create or replace procedure step_1(part number) is
    v_sql varchar2(4000);
    err varchar2(512);
    num number;
begin
    select count(1) into num from amdocs.raise_CRM2 a where a.partition_id = part;  
    for i in 1 .. num loop
        select a.v_exe into v_sql from amdocs.raise_CRM2 a where a.partition_id = part and a.seq = i; 
        execute immediate v_sql;
        err := sqlcode;
        err := err || '  ' || sqlerrm;
        update amdocs.raise_CRM2 a set a.state = err 
        where a.seq = i;
        dbms_transaction.commit;
    end loop; 
end step_1;麻烦大家帮我看看哪里错了。
编译通过,测试的时候,execute immediate v_sql中v_sql报为无效的字符。
raise_CRM2  这个表存储了相应的语句。并且确定语句是可执行的。

解决方案 »

  1.   

    amdocs.raise_CRM2存的 sql有错,你可以加个打印语句,打印出v_sql这个值看看是不是合法的sql语句
      

  2.   

    raise_CRM2 这个表存储了相应的语句。并且确定语句是可执行的。
    如果是上面所说 那么可能出问题的地方就是:
    select a.v_exe into v_sql from amdocs.raise_CRM2 a where a.partition_id = part and a.seq = i;这里了
    是不是把v_sql中有null?检查下
      

  3.   

    select a.v_exe into v_sql from amdocs.raise_CRM2 a where a.partition_id = part and a.seq = i; 这一句估计查出来的是空 。你可以调试下看看。
      

  4.   

    v_sql是个变量这是不能execute immediate v_sql被执行的。
      

  5.   

    我的
    select a.v_exe into v_sql from amdocs.raise_CRM2 a where a.partition_id = part and a.seq = i;
    取前4个的。字符串分别是:
    1
    create table xy_need_delete_offerinsta_1 as select * from ls8_sid.product_offer_instance_t a
    where a.partition_id_region=1012 and exists(select 1 from  upgrade_jx.xy_serv_pay_mode_1_detail b
    where a.product_offer_instance_id= b.product_offer_instance_id );
    2
    create index xy_need_delete_offerinsta_1 on xy_need_delete_offerinsta_1(product_offer_instance_id);
    3
    delete from ls8_sid.product_offer_instance_t a where a.partition_id_region=1012
    and exists(select 1 from  upgrade_jx.xy_serv_pay_mode_1_detail b
    where a.product_offer_instance_id= b.product_offer_instance_id ) ;
    4
    create table xy_need_delete_offerdetail_1 as select * from  ls8_sid.offer_detail_instance_t a
    where a.partition_id_region=1012 and exists(select 1 from upgrade_jx.xy_serv_pay_mode_1 b where a.serv_id = b.serv_id );
      

  6.   


    --动态语句里面不需要分号(;)
    --将你的这四个语句的最后的分号去掉
    1
    create table xy_need_delete_offerinsta_1 
    as 
    select * from ls8_sid.product_offer_instance_t a
    where a.partition_id_region=1012 
      and exists(
          select 1 
          from upgrade_jx.xy_serv_pay_mode_1_detail b
          where a.product_offer_instance_id= b.product_offer_instance_id )
    2
    create index xy_need_delete_offerinsta_1 
    on xy_need_delete_offerinsta_1(product_offer_instance_id)
    3
    delete from ls8_sid.product_offer_instance_t a 
    where a.partition_id_region=1012
      and exists(
          select 1 from upgrade_jx.xy_serv_pay_mode_1_detail b
          where a.product_offer_instance_id= b.product_offer_instance_id )
    4
    create table xy_need_delete_offerdetail_1 
    as 
    select * from ls8_sid.offer_detail_instance_t a
    where a.partition_id_region=1012 
      and exists(
          select 1 from upgrade_jx.xy_serv_pay_mode_1 b 
          where a.serv_id = b.serv_id )