写了一个包,包里有一个存储过程
存储过程有一个传入参数和一个游标
功能:根据传入的日期,计算上一个月的日期,然后查询出这两个月之间的全部信息
但是存储过程报错了,各位帮我看看,谢谢create or replace package body PKG_T_BlogSearchDate
as
procedure PRO_T_BlogSearchDate(bgdate varchar2,mycur_out out mycur)
is
mm_temp date;--上一月
begin
select to_char(add_months(trunc(bgdate),-1),'yyyy-mm') into mm_temp from dual; --根据传入月份,获取上一月份
open mycur_out for
select * from t_blog where bg_date between mm_temp and bgdate order by bg_date desc;
end PRO_T_BlogSearchDate;
end PKG_T_BlogSearchDate;错误信息:ora-00932不一致的数据类型:要求date得到却是number

解决方案 »

  1.   

    1)
    --报错在这里:
    select to_char(add_months(trunc(bgdate),-1),'yyyy-mm') into mm_temp from dual; --根据传入月份,获取上一月份改成:
    select add_months(to_date(bgdate || '-01', 'yyyy-mm-dd'), -1) into mm_temp from dual;2)
    select * from t_blog where bg_date between mm_temp and bgdate order by bg_date desc;
    这里也有问题,bg_date字段是什么类型的?
      

  2.   

    create or replace package body PKG_T_BlogSearchDate
    as
    procedure PRO_T_BlogSearchDate(bgdate varchar2,mycur_out out mycur)
    is
    mm_temp date;--上一月
    begin
    select to_char(add_months(trunc(bgdate),-1),'yyyy-mm') into mm_temp from dual; --根据传入月份,获取上一月份
    open mycur_out for
    select * from t_blog where bg_date between mm_temp and bgdate order by bg_date desc;
    end PRO_T_BlogSearchDate;
    end PKG_T_BlogSearchDate;
    bgdate 应为date型。SQL> SELECT add_months(trunc('2010-2-28'),-1) FROM dual;
    SELECT add_months(trunc('2010-2-28'),-1) FROM dual
                      *
    第 1 行出现错误:
    ORA-00932: 数据类型不一致: 应为 DATE, 但却获得 NUMBER
    SQL> SELECT add_months(trunc(sysdate),-1) FROM dual;ADD_MONTHS(TRU
    --------------
    28-2月 -10SQL>