v_sqlInsert := 'insert into'||v_ktTable||'select * from '||v_crmTable||'@CRM4'
                        ||'where action_id=4 and ps_net_code not in(''6E'',''6F'',''6G'',''6H'')';
         execute immediate v_sqlInsert;
在execute immediate 这行会报错。源码为:
declare
v_crmTable varchar2(30);
v_ktTable varchar2(30); 
v_sqlInsert varchar2(200);
v_sqlUpdate varchar2(200);
begin
     for i in 200.. 210 
     loop     
         v_crmTable := 'aicbs.ps_provision_'||i;
         v_ktTable := 'kt.ps_provision_'||i;
         v_sqlInsert := 'insert into'||v_ktTable||'select * from '||v_crmTable||'@CRM4'
                        ||'where action_id=4 and ps_net_code not in(''6E'',''6F'',''6G'',''6H'')';
         execute immediate v_sqlInsert;
         v_sqlUpdate := 'update'||v_crmTable||'@CRM4'
                        ||'set notes = ''LOAD'' where action_id=4 and ps_net_code not in(''6E'',''6F'',''6G'',''6H'')';
         execute immediate v_sqlUpdate;     
     end loop;
end;
请各位帮忙解决

解决方案 »

  1.   

    'insert into'||v_ktTable||'select * from  ...
    这一行 会生成类似于 insert into tabselect * from 这样的sql语句,表名和select 中没有分开。
      

  2.   

    其实 可以用 dbms_output.putline打印出来  就可以测试语句正确性了
      

  3.   


    declare
    v_crmTable varchar2(30);
    v_ktTable varchar2(30);  
    v_sqlInsert varchar2(200);
    v_sqlUpdate varchar2(200);
    begin
      for i in 200.. 210  
      loop   
          v_crmTable := 'aicbs.ps_provision_'||i;
          v_ktTable := 'kt.ps_provision_'||i;
          v_sqlInsert := 'insert into '||v_ktTable||
                         ' select * from '||v_crmTable||'@CRM4'||--v_crmTable||'@CRM4'
                         ' where action_id=4 and ps_net_code not in(''6E'',''6F'',''6G'',''6H'')';
          execute immediate v_sqlInsert;
          v_sqlUpdate := 'update '||v_crmTable||' @CRM4'||--
                         'set notes = ''LOAD'' where action_id=4 and ps_net_code not in(''6E'',''6F'',''6G'',''6H'')';
          execute immediate v_sqlUpdate;   
      end loop;
    end;
    --上面注释的地方,@CRM4这是什么,insert ...select ...语句应该是像下面这样的
    --还有注意空格
    insert into table_name
    select * from table_name_2
    where conditions
      

  4.   

    'insert into'||v_ktTable||'select * from '||v_crmTable||'@CRM4'这里提示缺少INTO 关键字,,其实是你INTO 后面没有空格造成的
      

  5.   

    还有,最好在loop中,及时commit;