接收日期作为参数输入时出错

时间:2013-02-13 20:20:59

标签: oracle date plsql runtime-error procedure

当我插入日期来测试我正在处理的参数时,我收到错误。错误是:

01858. 00000 -  "a non-numeric character was found where a numeric was expected"
*Cause:    The input data to be converted using a date format model was
           incorrect.  The input data did not contain a number where a number was
           required by the format model.
*Action:   Fix the input data or the date format model to make sure the
           elements match in number and type.  Then retry the operation.

这是我的测试脚本:

set serveroutput on
declare
  type tempcursor is ref cursor;
  v_cur_result tempcursor;
  errcode number;
  errmesg varchar2(1000);
  p_statusmnemonic_in         acts.ct_cu_act_medrecon_pg.varchararrayplstype;
  p_processtypemnemonic_in    transactionprocesslog.processtypemnemonic%type; 
  p_primarymemberplanid_in    membermedicalreconcilationhdr.primarymemberplanid%type;
  p_assigneduserid_in         membermedicalreconcilationhdr.assigneduserid%type;
  p_accountorgid_in           membermedicalreconcilationhdr.accountorgid%type;
  p_reconstatusmnemonic_in    membermedicalreconcilationhdr.reconciliationstatusmnemonic%type;
  p_estimatedenddt_in         membermedicalreconcilationhdr.estimatedenddt%type;
  p_actualenddt_in            membermedicalreconcilationhdr.actualenddt%type;
  p_inserteddate_in           membermedicalreconcilationhdr.inserteddt%type;
  p_insertedby_in             membermedicalreconcilationhdr.insertedby%type;
  p_updateddate_in           membermedicalreconcilationhdr.updateddt%type;
  p_updatedby_in           membermedicalreconcilationhdr.updatedby%type;

begin
  p_statusmnemonic_in(1) := ('OPEN');
  p_statusmnemonic_in(2) := ('SUSPENDED_PRIOR_TO_COMPARE');
  ct_cu_act_medrecon_pg.sps_get_patientmedrecs_hdr      
  (p_statusmnemonic_in,'NO','26-JAN-14',v_cur_result, errcode, errmesg);

   loop
fetch v_cur_result into     p_primarymemberplanid_in,p_assigneduserid_in,p_accountorgid_in,p_reconstatusmnemonic_in,
                        p_estimatedenddt_in,p_actualenddt_in,p_inserteddate_in,p_insertedby_in,
                        p_updateddate_in,p_updatedby_in,p_processtypemnemonic_in;

  dbms_output.put_line(' planid '||p_primarymemberplanid_in||' userid '||p_assigneduserid_in);

  exit when v_cur_result%notfound;
  end loop;

  dbms_output.put_line(' error code '||errcode||' message '||errmesg);
end;

当日期设置为'24 -JAN-13'时,我没有收到错误,但是第二次我改变了任何我得到的错误。以下是我正在查看的表中的两个估计日期字段:

24-JAN-13 04.29.19.989847000 PM
28-JAN-13 08.52.27.187015000 PM

这是我的过程:

  procedure sps_get_patientmedrecs_hdr (
    p_statusmnemonic_in       in varchararrayplstype,
    p_processtypemnemonic_in  in transactionprocesslog.processtypemnemonic%type,
    p_estimatedenddt_in       in membermedicalreconcilationhdr.estimatedenddt%type,
    p_return_cur_out          out sys_refcursor,
    p_err_code_out            out number,
    p_err_mesg_out            out varchar2)
  is
     lv_varchararray         varchararray := varchararray();
  begin
    if p_statusmnemonic_in.count > 0
    then
      for rec1 in 1..p_statusmnemonic_in.count
      loop
        lv_varchararray.extend(1);
        lv_varchararray(rec1) := p_statusmnemonic_in(rec1);
      end loop;

        open p_return_cur_out for
        select h.membermedreconciliationhdrskey,
               h.primarymemberplanid,
               h.assigneduserid,
               h.accountorgid,
               h.reconciliationstatusmnemonic,
               h.estimatedenddt,
               h.actualenddt,
               h.inserteddt,
               h.insertedby,
               h.updateddt,
           h.updatedby
        from membermedicalreconcilationhdr h
        where h.reconciliationstatusmnemonic in (select *
                                             from table (cast(lv_varchararray as varchararray)))
        and h.estimatedenddt <= nvl(p_estimatedenddt_in, h.estimatedenddt)
        and not exists (select *
                        from transactionprocesslog tpl
                        where tpl.transactiontypemnemonic = 'MEDREC'
                        and tpl.transactionid = h.primarymemberplanid
                        and nvl(p_processtypemnemonic_in, tpl.processtypemnemonic) = tpl.processtypemnemonic);
    else
        open p_return_cur_out for
        select h.membermedreconciliationhdrskey,
               h.primarymemberplanid,
               h.assigneduserid,
               h.accountorgid,
               h.reconciliationstatusmnemonic,
               h.estimatedenddt,
               h.actualenddt,
               h.inserteddt,
               h.insertedby,
               h.updateddt,
               h.updatedby
        from membermedicalreconcilationhdr h; 
    end if;

  p_err_code_out := 0;  
  exception
    when others then
      p_err_code_out := -1;
      p_err_mesg_out := 'error in ct_cu_act_medrecon_pg.sps_get_patientmedrecs_hdr => ' || sqlerrm;
  end sps_get_patientmedrecs_hdr;

我尝试了to_date函数,但收到了同样的错误。任何帮助将不胜感激,提前谢谢。

1 个答案:

答案 0 :(得分:0)

看起来你正在处理一个类似日期的字符串,根据你的NLS设置,这可能会也可能不起作用。每当Oracle看到一个预期日期的字符串时,它会尝试根据该字符串是否恰好与您的特定会话的日期格式参数匹配来进行隐式日期转换。这是一个非常常见的错误来源。

要使用正确的日期,您可以使用to_date函数,如下所示:

to_date('26-JAN-14','DD-MON-RR')

或使用本机语法指定日期文字,这是我建议的:

date'2014-1-26'