存储过程中的日期使用报“ORA-01861”

在存储过程begin中用查询用到to_date(),一直报“ORA-01861: 文字与格式字符串不匹配”。

我的存储

create or replace procedure p_bill_statics(start_date in varchar2,end_date in varchar2) is

  --1

  cursor cur is select distinct(bill_id) as bill_id from t_print_log where print_time>=to_date(start_date,'yyyy-mm-dd') and print_time<=to_date(end_date,'yyyy-mm-dd');

begin

    select count(1) into v_cnt from t_receipt_data rd inner join t_account_info ac on rd.account_code=ac.account_code
            inner join t_org_info oi on ac.org_code = oi.org_code
            where rd.type_code=v_type_cur.type_code and ac.org_code=v_cur_init.org_code
            and rd.import_time>=to_date(start_date,'yyyy-mm-dd')
            and rd.import_time<=to_date(end_date,'yyyy-mm-dd') ;--2

end;
 

入参start_date 的值是2017-05-01,在1处使用正常,但运行到2出的时候就报“ORA-01861: 文字与格式字符串不匹配”。经过研究发现在存储过程begin体中需要将start_date和end_date再赋给新定义的变量,因为有可能是oracle内部把它当做了某些处理,正确使用方法:

create or replace procedure p_bill_statics(start_date in varchar2,end_date in varchar2) is

  --1

  cursor cur is select distinct(bill_id) as bill_id from t_print_log where print_time>=to_date(start_date,'yyyy-mm-dd') and print_time<=to_date(end_date,'yyyy-mm-dd');

v_start varchar2(30);--3
   v_end varchar2(30);

begin

    select count(1) into v_cnt from t_receipt_data rd inner join t_account_info ac on rd.account_code=ac.account_code
            inner join t_org_info oi on ac.org_code = oi.org_code
            where rd.type_code=v_type_cur.type_code and ac.org_code=v_cur_init.org_code
            and rd.import_time>=to_date(v_start,'yyyy-mm-dd')
            and rd.import_time<=to_date(v_end,'yyyy-mm-dd');--2

end;
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值