oracle存储过程中v_FirstMonth Bpms_Businessvalue.Currentdate%Type :=trunc(to_date(v_ReportDate,'yyyy/MM/dd'),'yyyy');变量赋值后为什么是null 
此处的v_ReportDate是存储过程传入的参数

解决方案 »

  1.   

    v_ReportDate是精确到天吗?
    楼主是想要精确到年吗?可以直接的截取,用substr就行了
      

  2.   

    Select Trunc(to_date('2012/12/20','yyyy/mm/dd'),'year') from dual;
    具体参考oracle官网对trunc讲解http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions220.htm#SQLRF06151
      

  3.   

    LZ,我经过测试,结果不是null啊
    我的代码如下:
    set SERVEROUTPUT on;
    create or replace procedure pro_test(v_ReportDate in varchar2)
    as
    v_FirstMonth TEST_TABLE.TEST_DATE%TYPE:=trunc(to_date(v_ReportDate,'yyyy/MM/dd'),'yyyy');
    begin
    DBMS_OUTPUT.PUT_LINE('v_FirstMonth='||v_FirstMonth);
    end;
    execute pro_test('2013-10-5');
    结果是:v_FirstMonth=01-1月 -13
      

  4.   

    获取年份正确的方法declare v_FirstMonth varchar2(4);
    begin
       v_FirstMonth := to_char(to_date('2013-01-18','yyyy/MM/dd'),'yyyy');
       dbms_output.put_line(v_FirstMonth);
    end;