/*遍歷gws_payment_notice表,根據wfr_no查詢gws_write_off_record
根據gws_write_off_record的source_id查詢gws_payment_notice_detail,
如果不存在,則對gws_payment_notice_detail作新增操作,對gws_payment_notice作更新操作*/
create or replace procedure proc_init_paymentnotice as
cursor c_paymentnotice is
select * from gws_payment_notice t_pn where t_pn.is_deleted = 'n';
/*付款通知單記錄變數*/
r_paymentnotice gws_payment_notice%rowtype;
/*核銷記錄變數*/
c_wfr gws_write_off_record%rowtype;
/*根據sourceid查詢gws_payment_notice_detail記錄數*/
i_num number(10) := 0;
begin
open c_paymentnotice;
loop
fetch c_paymentnotice
into r_paymentnotice;
exit when c_paymentnotice%notfound;
begin
select *
into c_wfr
from gws_write_off_record t_wfr
where t_wfr.wfr_no = r_paymentnotice.wfr_no;
/*查詢是否已存在gws_payment_notice_detail*/
select count(1)
into i_num
from gws_payment_notice_detail t
where t.source_id = c_wfr.source_id;
/*不存在gws_payment_notice_detail,才作新增,更新操作*/
if i_num = 0 then
/*新增gws_payment_notice_detail表*/
insert into gws_payment_notice_detail
(id,
gmt_create,
gmt_modified,
payment_notice_id,
source_id,
amount,
un_exchange_amount,
creator,
modifier,
is_deleted)
values
(seq_gws_payment_notice_detail.nextval,
sysdate,
sysdate,
r_paymentnotice.id,
c_wfr.source_id,
r_paymentnotice.amount,
r_paymentnotice.un_exchange_gain_loss,
'wb_cj189958',
'wb_cj189958',
'n');
/*更新paymentnotice表*/
update gws_payment_notice
set exchange_date = c_wfr.exchange_date,
exchange_type = c_wfr.exchange_type,
exchange_rate = c_wfr.exchange_rate,
source_type = c_wfr.source_type,
gmt_modified = sysdate,
modifier = 'wb_cj189958'
where id = r_paymentnotice.id;
end if;
exception
when no_data_found then
dbms_output.put_line('未查到核銷記錄,wfr_no='||r_paymentnotice.wfr_no);
when too_many_rows then
dbms_output.put_line('查到多條核銷記錄,wfr_no='||r_paymentnotice.wfr_no);
when others then
dbms_output.put_line('系統異常');
end;
end loop;
close c_paymentnotice;
begin
commit; /*提交*/
dbms_output.put_line('儲存過程執行成功');
exception
when others then
rollback; /*回滾*/
dbms_output.put_line('儲存過程執行失敗');
end;
end proc_init_paymentnotice;
ORACLE中用for in 使用cursor
cursor cur is select from for cur result in cur loop begin v sum cur result.列名1 cur result.列名2 end end loop end 中的cursor cur is得到的是什麼?用for in 能夠得到什麼?答...
Oracle儲存過程呼叫儲存過程
oracle儲存過程呼叫有返回結果集的儲存過程一般用光標的方式,宣告乙個游標,把結果集放到游標裡面,然後迴圈游標 declare newcs sys refcursor cs1 number cs2 number cstype table rowtype table列的個數和newcs返回的個數一樣...
ORACLE儲存過程
自定義函式開始 create or replace function fn wftemplateidget templatecategoryid number,organid number,templatemode number return number istemplateid number i...