在开发中,经常会碰到动态表名的游标的写法,正好在工作中碰到一个,如下所示:
declare
stralltable varchar2(100);
TYPE cur_typ IS REF CURSOR;
c cur_typ;
c_id number(18);
c_code varchar2(100);
begin
for c_table in (select t.TABLE_NAME
from user_tab_columns t
where t.table_name like upper('pne_%')
and t.COLUMN_NAME = 'CODE') loop
stralltable := 'select id,code from ' ||
c_table.TABLE_NAME;
open c for stralltable;
loop
fetch c
into c_id, c_code;
exit when c%notfound;
-- 此处可以写自已的处理代码
end loop;
close c;
end loop;
end;