存储过程里面能包含多个语句吧?
我代码如下create table tmp_ny_cfjc_1 as
select distinct serv_id
  from acct.acct_item_owe@dblink_comm_qry_135
 where state = '5JB'
   and billing_cycle_id = '111' || to_char(sysdate, 'mm') - 1;--OK,17mindelete from dun_gencflist_1112 where serv_id
in (
select serv_id from acct.a_owe_special_serv@dblink_comm_qry_135
where exp_date>=sysdate
and owe_business_type_id='1');--OK
commit;delete from dun_gencflist_1112 where serv_id
in (
select serv_id from acct.a_owe_special_serv@dblink_comm_qry_135
where exp_date>=sysdate
and owe_business_type_id='1');
commit;--OKend evd_go;每一句都是可以执行成功的,
创建存储过程也成功,但execute的时候提示错误
ORA-06550: line 2, column 7:
PLS-00905: object INTERFACE.EVD_GO is invalid
ORA-06550: line 2, column 7:
PL/SQL: Statement ignored
初学的菜鸟,请大家帮忙指正。

解决方案 »

  1.   

    你创建表的操作是在SP里的嘛,一般在SP中使用动态DDL语句。
      

  2.   

    存储过程里不能有DDL操作,必须使用动态SQL,
    sqlstr:='create table tmp_ny_cfjc_1 as
    select distinct serv_id
      from acct.acct_item_owe@dblink_comm_qry_135
     where state = '5JB'
       and billing_cycle_id = '111' || to_char(sysdate, 'mm') - 1';
    execute immediate sqlstr;
    具体的动态SQL 自己拼
      

  3.   

    抱歉 复制少了 代码create or replace procedure evd_go is
    begindrop table tmp_ny_cfjc_1;create table tmp_ny_cfjc_1 as
    select distinct serv_id
      from acct.acct_item_owe@dblink_comm_qry_135
     where state = '5JB'
       and billing_cycle_id = '111' || to_char(sysdate, 'mm') - 1;--OKdelete from dun_gencflist_1112 where serv_id
    in (
    select serv_id from acct.a_owe_special_serv@dblink_comm_qry_135
    where exp_date>=sysdate
    and owe_business_type_id='1');--OK
    commit;delete from dun_gencflist_1112 where serv_id
    in (
    select serv_id from acct.a_owe_special_serv@dblink_comm_qry_135
    where exp_date>=sysdate
    and owe_business_type_id='1');
    commit;--OKend evd_go;
      

  4.   

    也就是说,不能直接在存储过程里create?
      

  5.   

    那个sqlstr要事先定义吗?
    都写在存储过程的里面吗?
    凡是drop、create这些,都要变成一个字符串然后再用execute命令来操作是吗?
      

  6.   

    凡是ddl ,create ,drop ,truncate 等都必须使用动态sql。
    execute immediate 'DDL语句'
      

  7.   

    还有一个小问题:如果我像3楼写的那样把DDL语句先赋在一个字符串里那么这个sqlstr要在哪里定义?
    能给一个完整的写法么?
    麻烦各位了
      

  8.   

    还有一个小问题:如果我像3楼写的那样把DDL语句先赋在一个字符串里那么这个sqlstr要在哪里定义?
    能给一个完整的写法么?
    麻烦各位了
      

  9.   


    create or replace procedure evd_go as
    begindeclare str1 string,str2 string;str1:='drop table tmp_ny_cfjc_1';
    execute immediate str1;str2:='create table tmp_ny_cfjc_1 as
    select distinct serv_id
      from acct.acct_item_owe@dblink_comm_qry_135
     where state = '5JB'
      and billing_cycle_id = '111' || to_char(sysdate, 'mm') - 1';
    execute immediate str2;delete from dun_gencflist_1112 where serv_id
    in (select serv_id from tmp_ny_cfjc_1);
    commit;delete from dun_gencflist_1112 where serv_id
    in (
    select serv_id from acct.a_owe_special_serv@dblink_comm_qry_135
    where exp_date>=sysdate
    and owe_business_type_id='1');
    commit;end;这样对么?(现在没办法测试,只好先发上来问问,请别拍我砖)