[英]java.sql.SQLException: ORA-01843: not a valid month when calling a procedure
I have application which has a procedure as follows: 我有以下程序的应用程序:
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;
And Here's the Java code which calls this procedure (I'm using hibernate
over here): 这是调用此过程的Java代码(我在这里使用hibernate
):
List<MyBean> salesApproval=session.getNamedQuery("get_data").setInteger("id",my_id).setString("code",my_code).setString("type",my_type).list();
MyBean
is the class holds the data returned by procedure. MyBean
是保存过程返回的数据的类。
Problem: 问题:
When I host my application on windows
system it works fine with desired result. 当我在windows
系统上托管我的应用程序时,它可以正常工作并具有所需的结果。
However when I host my application on Linux Ubuntu 12.04
, it gives following error: 但是,当我在Linux Ubuntu 12.04
上托管我的应用程序时,出现以下错误:
java.sql.SQLException: ORA-01843: not a valid month
ORA-06512: at "db.proc_pack", line 628
Line number 628 is mentioned in procedure. 在过程中提到了行号628。
year_in := to_number(to_char(sysdate,'RRRR')); // line 628
SYSDATE
is already returning date, so TO_DATE()
conversion on it goes wrong.. SYSDATE
已经返回日期,因此它的TO_DATE()
转换出错。
To understand why the error is.. TO_DATE(SYSDATE,'...')
will become TO_DATE('Date in Default Format','YOUR FORMAT');
了解错误的原因TO_DATE(SYSDATE,'...')
将变为TO_DATE('Date in Default Format','YOUR FORMAT');
So, more chances of it to go wrong.. 因此,出错的机会更多。
Your default format will be NLS_DATE_FORMAT
of your session! 您的默认格式为会话的NLS_DATE_FORMAT
! This depend on the platform and session parameters in different hosts! 这取决于不同主机中的平台和会话参数!
Example: 例:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.