CREATE OR REPLACE PROCEDURE 存储过程名
AS
type ref_cursor is ref cursor;--定义游标
mycursor ref_cursor;
--定义需要的变量
变量1 number;
begin
变量ny:=to_char(sysdate,'yyyyMM');
strSql:='select 字段1, 字段2, 字段3,
decode(f.字段,'||''''||变量||''''||','||''''||变量||''''||','||''''||变量||''''||') 字段
from 表1 a
join 表2 b on a.字段=b.字段
join b'||变量ny||'c c on a.字段= c.字段
join 表3 d on a.字段= d.字段
left 表4 e on substr(d.字段,'||''''||变量||''''||','||''''||变量||''''||')=e.字段
left join 表5 f on e.字段=f.字段 and f.字段='||''''||变量||''''||'
left join 表6 g on e.字段=g.字段
where a.字段='||''''||变量||'''' || 'or a.字段='||''''||变量||'''';
open mycursor for strSql; --打开游标
if mycursor%isopen then --判断打开成功
loop --循环获取记录集
fetch mycursor into 变量,变量,变量,变量; --获取游标中的记录
if mycursor%found then --游标的found属性判断是否有记录
if 变量 is not null then
select count(*) into 变量 from 表 where 字段 = 变量;
if 变量 = 0 then
insert into 表(字段, 字段, 字段, 字段)
values(变量, 变量, 变量, 变量);
else
update 表 set 字段=表, 字段=表 where 字段 = 变量;
end if;
commit;
end if;
else
exit;
end if;
end loop;
end if;
close mycursor;
end;
AS
type ref_cursor is ref cursor;--定义游标
mycursor ref_cursor;
--定义需要的变量
变量1 number;
begin
变量ny:=to_char(sysdate,'yyyyMM');
strSql:='select 字段1, 字段2, 字段3,
decode(f.字段,'||''''||变量||''''||','||''''||变量||''''||','||''''||变量||''''||') 字段
from 表1 a
join 表2 b on a.字段=b.字段
join b'||变量ny||'c c on a.字段= c.字段
join 表3 d on a.字段= d.字段
left 表4 e on substr(d.字段,'||''''||变量||''''||','||''''||变量||''''||')=e.字段
left join 表5 f on e.字段=f.字段 and f.字段='||''''||变量||''''||'
left join 表6 g on e.字段=g.字段
where a.字段='||''''||变量||'''' || 'or a.字段='||''''||变量||'''';
open mycursor for strSql; --打开游标
if mycursor%isopen then --判断打开成功
loop --循环获取记录集
fetch mycursor into 变量,变量,变量,变量; --获取游标中的记录
if mycursor%found then --游标的found属性判断是否有记录
if 变量 is not null then
select count(*) into 变量 from 表 where 字段 = 变量;
if 变量 = 0 then
insert into 表(字段, 字段, 字段, 字段)
values(变量, 变量, 变量, 变量);
else
update 表 set 字段=表, 字段=表 where 字段 = 变量;
end if;
commit;
end if;
else
exit;
end if;
end loop;
end if;
close mycursor;
end;