我的应用程序有如下程序:
procedure get_full_data (list OUT sys_refcursor,id in number,
code in varchar2,type in varchar2) is
year_in number;
begin
year_in := to_number(to_char(to_date(sysdate,'DD-MON-RRRR'),'RRRR')); // line 628
open list for
select * from my_tab
where code_present = code AND to_number(substr(year,1,4)) in (year_in,year_in-1,year_in-2)
and minth in(select max(month) from my_tab where code_present = code
and to_number(substr(year,1,4)) in (year_in,year_in-1,year_in-2)
group by substr(year,1,9))
order by to_number(substr(year,1,4)) desc;
END get_full_data;
这是调用此过程的Java代码(我在这里使用hibernate
):
List<MyBean> salesApproval=session.getNamedQuery("get_data").setInteger("id",my_id).setString("code",my_code).setString("type",my_type).list();
MyBean
是该类保存过程返回的数据。
问题:
当我在windows
系统上托管我的应用程序时,它可以正常工作
但是,当我在Linux Ubuntu 12.04
上托管我的应用程序时,会出现以下错误:
java.sql.SQLException: ORA-01843: not a valid month
ORA-06512: at "db.proc_pack", line 628
程序中提到了行号628.
答案 0 :(得分:1)
year_in := to_number(to_char(sysdate,'RRRR')); // line 628
SYSDATE
已经返回日期,因此TO_DATE()
转换就出错了。
要理解错误的原因.. TO_DATE(SYSDATE,'...')
将成为TO_DATE('Date in Default Format','YOUR FORMAT');
因此,它出错的可能性更大..
您的默认格式为会话的NLS_DATE_FORMAT
!这取决于不同主机中的平台和会话参数!
示例:强>
SQL> SELECT value FROM nls_database_parameters WHERE parameter = 'NLS_DATE_FORMAT';
VALUE
--------------------------------------------------------------------------------
DD-MON-RR
SQL> select to_date(sysdate,'MON-DD-RR') from dual;
select to_date(sysdate,'MON-DD-RR') from dual
*
ERROR at line 1:
ORA-01843: not a valid month
SQL> ALTER SESSION SET nls_date_format = 'MON-DD-RR';
Session altered.
SQL> select to_date(sysdate,'MON-DD-RR') from dual;
TO_DATE(S
---------
AUG-29-14