存储过程:
创建语法:
create or replace procedure 存储过程名[(param1 in type,param2
out type)]
is
变量1 类型(值范围); --content
varchar2(40000);
变量2 类型(值范围);
begin
--pl/sql语句
end 存储过程名;
举例:其中有一个无参游标和一个有参游标:
create or replace procedure XXX
is
--标记
flag int:=0;
--游标
cursor curYYY is
select *
from X x,Y y
where x.id=y.id;
--参数游标
cursor
curZZZ(id varchar2)is
select * from P p where p.id=id;
rec_curZZZ
curZZZ%rowtype;
rec_curYYY
curYYY%rowtype;
begin
--判断游标是否被打开,如果已经打开,首先关闭
if curYYY%isopen then
--关闭游标
close
curYYY;
end if;
--打开游标
open curYYY;
--进行循环
loop
--打开游标里的一条记录,赋到游标变量里
fetch
curYYY
into rec_curYYY;
--判断游标里是否还有记录,如果没有记录,关闭游标,退出循环
if
curYYY%notfound then
close curYYY;
exit;
else
if curZZZ%isopen then
--关闭游标
close curZZZ;
end if;
--打开游标
open curZZZ(rec_curYYY.id);
loop
fetch curZZZ
into rec_curZZZ;
if curZZZ%notfound then
close curZZZ;
exit;
else
--pl/sql语句
end if;
end loop;
end
if;
--提交事务
commit;