在程序中获得错误ORA-01722和ORA-06512

时间:2015-01-19 13:48:48

标签: oracle plsql procedure

尝试运行此过程时出错。我传递36到p_nb_months并且p_msg_per_loop采用默认值。

代码如下。

procedure prc_purge(p_nb_month IN number default 210, p_msg_per_loop IN number default 10000) as


TYPE selREC IS RECORD (

  EMAIL     desinscription.EMAIL%type,
  IDRA      desinscription.IDRA%type,
  D_DATE    desinscription.desinscription_date%type
  );

    type t_stringtab is table of selREC;
    tab_liste_tables t_stringtab;

  i number(10);      

    cursor c_table_order is
        select EMAIL,IDRA,desinscription_date from desinscription where desinscription_date < trunc(add_months(sysdate,-'||p_nb_month||'));

begin

    g_proc_name := 'PRC_PURGE';

    prc_log('Begining procedure');

    open c_table_order;
    fetch c_table_order bulk collect into tab_liste_tables;
    close c_table_order;

        for i in 1..tab_liste_tables.count Loop
        begin
            DBMS_APPLICATION_INFO.set_action(action_name => 'Purging DESINCRIPTION and INSCRIPTION tables');
            execute immediate 'DELETE FROM DESINSCRIPTION WHERE EMAIL=:1 AND IRDA=:2' using tab_liste_tables(i).EMAIL,tab_liste_tables(i).IDRA;
            execute immediate 'DELETE FROM INSCRIPTION WHERE EMAIL=:1 AND IDRA=:2 AND INSCRIPTION_DATE < TRUNC(:3)' using tab_liste_tables(i).EMAIL,tab_liste_tables(i).IDRA,tab_liste_tables(i).D_DATE;
        exception when others then 
            prc_log('Error in procedure : '||chr(10)||DBMS_UTILITY.FORMAT_ERROR_STACK() || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE(),'ERROR');
            raise_application_error(-20000,'Erreur durant la purge ECOM. Consulter WRK_LOG pour plus d''information');
        end;
        end loop;

        commit;


    tab_liste_tables.delete;
    prc_log('End of procedure');

end prc_purge;

1 个答案:

答案 0 :(得分:0)

函数add_month的第二个参数必须是数字数据类型,所以只需从

更改光标即可
    cursor c_table_order is
    select EMAIL,IDRA,desinscription_date from desinscription where desinscription_date < trunc(add_months(sysdate,-'||p_nb_month||'));

    cursor c_table_order is
    select EMAIL,IDRA,desinscription_date from desinscription where desinscription_date < trunc(add_months(sysdate,-p_nb_month));

您也可以在不声明记录类型的情况下定义表类型,只需尝试:

type t_stringtab is table of c_table_order%ROWTYPE;