這個存儲過程在package中,以下是包中的詳細代碼,下面的代碼包含僞代碼,請結合實際進行參考
object的創建代碼:
craate or repalce type tanglei_lianxi_obj is object(
-- 列名
id number,
name varchar,
.
.
.
)
tab的創建代碼:
create or replace type tanglei_lianxi_tab is table of tanglei_lianxi_obj --創建TAB類型
包頭:
create or replace package tanglei_lianxi is
-- Author : lei.tang
-- Created : 2017/8/9 10:36:29
-- Purpose : 存儲過程的導入List<Object>集合
-- 導入List集合的存儲
procedure importObjectList(pi_lianxi_tab IN tanglei_lianxi_tab, --TAB
po_flag out number, --輸出標誌
po_msg out varchar2 --輸出信息
);
end tanglei_lianxi;
包體:
create or replace package body tanglei_lianxi is
-- 導入List集合的存儲
procedure importObjectList(pi_lianxi_tab IN tanglei_lianxi_tab, --TAB
po_flag out number, --輸出標誌
po_msg out varchar2 --輸出信息
) is
-- 定義接收對象的id
v_id number;
-- 定義接收對象
v_obj tanglei_lianxi_obj;
begin
-- 給標誌和信息賦初值
po_flag := 0;
po_msg := 'OK';
--循環入參TAB
for i in 1 .. tanglei_lianxi_tab.count loop
-- 接收循環的對象
v_obj := tanglei_lianxi_tab(i);
-- 判斷該對象的id是否存在; 存在-->更新,不存在-->插入
if v_obj.id is null then
-- 用序列獲取id
v_id := nextVal(); -- 這裏自己獲取下一個序列的值
-- 插入
insert into 表名(列1,列2) values (v_obj.id,列2);
else
-- 更新
update 表名 set 列1=? where id = v_obj.id;
end if;
end loop;
-- 循環結束,提交事務
commit;
--異常處理
Exception
when others then
po_flag : = 1;
po_msg := SQLERRM;
-- 回滾
rollback;
end importObjectList;
end tanglei_lianxi;