DB2儲存過程 Oracle對比

2021-07-31 05:19:04 字數 3560 閱讀 2288

drop  procedure cdi.prc_cim_identity_find@

create procedure cdi.prc_cim_identity_find(

in i_id_num varchar(21),--oracle i_id_num in varchar(21) db2也有in out

in i_cert_type varchar(5),

in i_num_type integer,

out o_respnose_type varchar(1),

out o_respnose_code varchar(6)

)dynamic result sets 2

language sql

not deterministic

called on null input

modifies sql data

inherit special registers

begin

declare v_id_num    varchar (21);--oracle:在is/as中對變數宣告且沒有declare

--查詢號碼(傳入資料預處理)

declare v_cert_type    varchar (8);                     --查詢證件型別(傳入資料預處理)

declare v_num_type    integer;                      --查詢型別(傳入資料預處理)1:查詢號碼是卡號;2:查詢號碼是證件號碼;--3:查詢號碼是客戶號;

declare v_cust_union_id varchar(21);

--宣告出錯處理

declare exit handler forsqlexceptionbegin

set o_respnose_type = 'e';--

set o_respnose_code = '000005';--

end;--

--宣告結束

--對傳入引數空(值null)進行初始化

set v_id_num = rtrim(ltrim(i_id_num));--可代替函式trim() replace()

set v_cert_type = rtrim(ltrim(i_cert_type));--ora 賦值 :=

set v_num_type = i_num_type;

--當v_num_type查詢型別為1時,查詢結果為此卡所屬客戶的所有標識

--當v_num_type查詢型別為2時,查詢結果為此證件號碼所屬客戶的所有標識;

--當證件型別為空時,查詢所有證件 --當v_num_type查詢型別為3時,查詢結果為此客戶號所屬客戶的所有標識

if v_cust_union_id is null then

set v_cust_union_id='';

end if;

if v_cert_type is null then

set v_cert_type='';

end if;

--查詢號碼與查詢型別不能為空

if v_id_num is null or v_id_num = '' or v_num_type < 1 then

set o_respnose_type = 'e';

set o_respnose_code = '000003';

return;--終止儲存過程繼續執行

else

--查詢號碼型別為1卡號並且查詢號碼不為空||測試資料--5218990187677975

if v_num_type = 1 and v_id_num is not null then

begin

select distinct cust_union_id into v_cust_union_id from

cdi.cim_card_info where card_num=v_id_num withur;--髒讀

end;

--查詢號碼型別為2並且證件型別不為空

elseif v_num_type = 2 and v_cert_type <>'' then

begin

select distinct cust_union_id into v_cust_union_id from

cdi.cim_cust_iden_info

where cert_num=v_id_num and cert_type_cd=v_cert_type fetch first 1 rows only with ur;

end;

elseif v_num_type = 2 and v_cert_type = '' then

begin

select cust_union_id into v_cust_union_id from

cdi.cim_cust_iden_info

where cert_num=v_id_num fetch first 1 row only  with ur;--

end;--

elseif  v_num_type <> 1 and v_num_type <> 2 then

begin

select distinct cust_union_id into v_cust_union_id from

cdi.cim_cust_base_info

where cust_ref_num=v_id_num with ur;--

end;--

end if;--

if v_cust_union_id = '' then

set o_respnose_type = 'n';--

set o_respnose_code = '000004';--

return;--

end if;--

if v_num_type = 1 then --查詢卡號 /*卡標識*/

begin

declare result_card cursor with return for

select * from tablename with ur;--

open result_card;--

end;--

else --查詢統一編號

begin

declare result_card cursor with return for

select * from tablename with ur;--

open result_iden;--

end;--

set o_respnose_type = 'n';--

set o_respnose_code = '000000';--

end if;--

end@

grant execute on procedure cdi.prc_cim_identity_find  to public;

DB2儲存過程 Oracle對比

drop procedure cdi.prc cim identity find create procedure cdi.prc cim identity find in i id num varchar 21 oracle i id num in varchar 21 db2也有in out i...

db2儲存過程批量插入資料 db2儲存過程批量更新

db2儲存過程批量更新 雲伺服器 elastic compute service,簡稱ecs 是阿里雲提供的效能卓越 穩定可靠 彈性擴充套件的iaas infrastructure as a service 級別雲計算服務。雲伺服器ecs免去了您採購it硬體的前期準備,讓您像使用水 電 天然氣等公共...

db2儲存過程批量插入資料 db2儲存過程批量提交

db2儲存過程批量提交 雲伺服器 elastic compute service,簡稱ecs 是阿里雲提供的效能卓越 穩定可靠 彈性擴充套件的iaas infrastructure as a service 級別雲計算服務。雲伺服器ecs免去了您採購it硬體的前期準備,讓您像使用水 電 天然氣等公共...