日期:2014-05-17  浏览次数:20917 次

请教如何将游标以参数的方式使用,比如当成表名的一部分?
SQL code

declare
cursor cc is select distinct substr(vc_mobileno,1,3) trd from dw_foxuser_det order by 1;
rec_ind number;
ccrec cc%rowtype;
begin
 select count(*) into rec_ind from user_table where table_name = upper('tp_20120807_a01');
 if (rec_ind <> 0) then
Execute immediate 'drop table tp_20120807_a01 purge';
Execute immediate 'create table tp_20120807_a01 (test varchar2(11))';
end if;

for ccrec in cc loop
  insert into tp_20120807_a01 select vc_mobileno from dw_foxuser_det_138 where substr(vc_mobileno,4,3) = ccrec.trd;
  commit;
end loop;

End;



如题, 比如ccrec.trd 其中一个值为 138, 其后的insert 中表dw_foxuser_det_138 需要动态改变:
当ccrec.trd=138 的时候,就使用dw_foxuser_det_138,而如果ccrec.trd=134 时,就使用dw_foxuser_det_134

就像引用参数变量一样?

------解决方案--------------------
回你了,引用变量的方式自已试下,没试过,应可以