oracle存储过程动态表名 oracle存储过程中查询动态表名?

oracle存储过程中查询动态表名?先建立结果表,也就是存放你最终结果的表create table test(a varchar2(100),b varchar2(100))然后建立存储过程creat

oracle存储过程中查询动态表名?

先建立结果表,也就是存放你最终结果的表

create table test

(a varchar2(100),

b varchar2(100))

然后建立存储过程

create procedure p_insert

as

cursor cur_tbname is

select "insert into test select col1,col2 from "||table_name

from user_tables where table_name like "AA____BB"--这个位置的表名必须大写的A和B,col1和col2换成你实际的字段名称

begin

open cur_tbname

loop

fetch cur_tbname into v_sql

exit when cur_tbname%notfound

execute immediate v_sql

commit

end loop

end

我最终没测试,你自己测试一下,看哪有问题吧