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就像引用参数变量一样?
cursor cc is select distinct substr(vc_mobileno,1,3) trd from dw_foxuser_det where substr(vc_mobileno,1,3) in ('134','135') order by 1;
rec_ind number;
ccrec cc%rowtype;
begin
select count(*) into rec_ind from user_tables 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
execute immediate 'insert into tp_20120807_a01 select vc_mobileno from dw_foxuser_det_'||ccrec.trd||' where substr(vc_mobileno,4,3) = '||ccrec.trd;
commit;
end loop;End;