请问关于游标在动态语句中的使用有关问题

请教关于游标在动态语句中的使用问题SQL codedeclarecursor cc is select distinct substr(vc_mobileno,1,

请教关于游标在动态语句中的使用问题

SQL code
declarecursor 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) thenExecute 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 where substr(vc_mobileno,4,3) = ccrec.trd;commit;end loop;End;


-- 如示例所示,如果我使用上面的代码执行,在表tp_20120807_a01 存在的情况自然没问题,但是如果不存在,在for 循环中的insert 语句在执行时是通不过的,因为表不存在,这时我想使用动态语句执行:
SQL code
Execute immeidiate 'insert into tp_20120807_a01 select vc_mobileno from dw_foxuser_det where substr(vc_mobileno,4,3) = ccrec.trd';


这时也会报错,提示是ccrec.trd 未定义,如何回避这个问题的产生?

[解决办法]
SQL code
--你的ccrec.trd是外面的值Execute immeidiate 'insert into tp_20120807_a01 select vc_mobileno from dw_foxuser_det where substr(vc_mobileno,4,3) = '||ccrec.trd;