ORACLE存储过程sample

create or replace procedure ET(p1 in number,p2 in number , m out number) is
begin
--sql_str := 'insert into TABLE1(LKEY,TKBN) values(111,"758")' ;
-- EXECUTE IMMEDIATE sql_str;
DECLARE
v_title varchar(100);
l_count number ;
--定义游标
l_table1 WL.TABLE1%rowtype;
CURSOR cur_table1(vID number) is
SELECT * FROM WL.TABLE1 where table1.lkey = vID;

BEGIN
--打开游标方法一
/*
OPEN cur_table1(1) ;
--fetch cur_table1 into l_table1 ;

while cur_table1% found loop
l_count := l_count +1 ;
--比较
INSERT INTO TABLE2(ID,TXT) VALUES (l_table1.LKEY, l_table1.TKNB);
commit;

fetch cur_table1 into l_table1 ;
end loop;
*/
-- vs_ym_sn_beg :=
TO_CHAR(ADD_MONTHS(TO_DATE(vs_ym_beg,'yyyymm'), -12),'yyyymm');

FOR rec IN cur_table1(1) LOOP
INSERT INTO TABLE2(ID,TXT,DT)
VALUES (rec.LKEY, rec.TKNB,to_char(SYSDATE,'yymmdd'));
commit;

l_count := l_count +1 ;
dbms_output.put_line('插入记录数:'||l_count);
END LOOP;
CLOSE cur_table1;
--dbms_sql.close_cursor(cur_table1); --关闭游标;

END;

EXCEPTION
WHEN OTHERS THEN
BEGIN
dbms_output.put_line(SQLERRM);
rollback;
END;

end ET;
create or replace procedure ET(p1 in number,p2 in number , m out number) is
begin
--sql_str := 'insert into TABLE1(LKEY,TKBN) values(111,"758")' ;
-- EXECUTE IMMEDIATE sql_str;
DECLARE
v_title varchar(100);
l_count number ;
--定义游标
l_table1 WL.TABLE1%rowtype;
CURSOR cur_table1(vID number) is
SELECT * FROM WL.TABLE1 where table1.lkey = vID;

BEGIN
--打开游标方法一
/*
OPEN cur_table1(1) ;
--fetch cur_table1 into l_table1 ;

while cur_table1% found loop
l_count := l_count +1 ;
--比较
INSERT INTO TABLE2(ID,TXT) VALUES (l_table1.LKEY, l_table1.TKNB);
commit;

fetch cur_table1 into l_table1 ;
end loop;
*/
-- vs_ym_sn_beg :=
TO_CHAR(ADD_MONTHS(TO_DATE(vs_ym_beg,'yyyymm'), -12),'yyyymm');

FOR rec IN cur_table1(1) LOOP
INSERT INTO TABLE2(ID,TXT,DT)
VALUES (rec.LKEY, rec.TKNB,to_char(SYSDATE,'yymmdd'));
commit;

l_count := l_count +1 ;
dbms_output.put_line('插入记录数:'||l_count);
END LOOP;
CLOSE cur_table1;
--dbms_sql.close_cursor(cur_table1); --关闭游标;

END;

EXCEPTION
WHEN OTHERS THEN
BEGIN
dbms_output.put_line(SQLERRM);
rollback;
END;

end ET;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值