帮你写了个例子,好好研究一下吧:declare type emp_cur_type is ref cursor; C1 emp_cur_type; table_name varchar2(100); fnd_id varchar2(10); begin table_name := 'DUAL'; OPEN c1 FOR 'SELECT ''TEST'' from ' || TABLE_NAME; loop fetch c1 into fnd_id; exit when C1%notfound; dbms_output.put_line(fnd_id); end loop; end;
我是想将表名称作为参数传进来,因为好几个表需要用到这个 存储过程, 但是 我不知道为什么 会报错,很纠结
我是想将表名称作为参数传进来,因为好几个表需要用到这个 存储过程, 但是 我不知道为什么 会报错,很纠结
作为参数不能这样写,必须用动态SQL
我是想将表名称作为参数传进来,因为好几个表需要用到这个 存储过程, 但是 我不知道为什么 会报错,很纠结
作为参数不能这样写,必须用动态SQL
具体怎么写?
帮你写了个例子,好好研究一下吧:declare
type emp_cur_type is ref cursor;
C1 emp_cur_type;
table_name varchar2(100);
fnd_id varchar2(10);
begin
table_name := 'DUAL';
OPEN c1 FOR 'SELECT ''TEST'' from ' || TABLE_NAME;
loop
fetch c1
into fnd_id;
exit when C1%notfound;
dbms_output.put_line(fnd_id);
end loop;
end;