简体   繁体   English

无效月份-SQL ORA-01843-UNIX

[英]Not A valid Month - SQL ORA-01843 - In unix

I'm using a 我正在使用

TO_CHAR(TO_DATE(tdj_tran_dt,'DD-MON-RRRR'),'DD-MON-RRRR')    

in my one of my views. 在我的观点之一中。

The underlying Data is in the form DD-MON-YY and I have to display it in the form DD-MON-YYYY in the screen. 基础数据的格式为DD-MON-YY ,我必须在屏幕上以DD-MON-YYYY的形式显示它。

Initially I was using to_char(tdj_Tran_dt,'DD-MON-YYYY') alone but it wasnt working out. 最初,我是to_char(tdj_Tran_dt,'DD-MON-YYYY')使用to_char(tdj_Tran_dt,'DD-MON-YYYY') ,但没有解决问题。 For example, 20-OCT-17 would become 20-OCT-0017. 例如,20-OCT-17将变为20-OCT-0017。 My system has migrated data so changing the form of the data while inserting into table will not help. 我的系统已迁移了数据,因此在插入表时更改数据的形式无济于事。 So for this I've used TO_CHAR(TO_DATE(tdj_tran_dt,'DD-MON-RRRR'),'DD-MON-RRRR') which seems to be working everywhere except in unix. 因此,为此,我使用了TO_CHAR(TO_DATE(tdj_tran_dt,'DD-MON-RRRR'),'DD-MON-RRRR') ,它似乎在除Unix之外的任何地方都有效。 I have a proc file (run through linux) which calls this view and writes the data in xls format. 我有一个proc文件(通过linux运行),该文件调用此视图并以xls格式写入数据。 but in the proc while opening the cursor it gives Oracle error ORA-01843. 但是在打开游标的过程中,它给出了Oracle错误ORA-01843。 Changing it back to to_char(tdj_Tran_dt,'DD-MON-YYYY') seems to work but brings back the original problem. 将其更改回to_char(tdj_Tran_dt,'DD-MON-YYYY')似乎可行,但又带回了原来的问题。

I just want to know is there some setting in the database that I can change to fix this issue. 我只想知道数据库中是否有一些设置可以更改以解决此问题。 I have the samething running in two different environments and the not a valid month error seems to be only occuring in one environment. 我在两个不同的环境中运行相同的东西,并且无效的月份错误似乎仅在一个环境中发生。 I have checked nls_parameters which seems to be the same in both environments. 我已经检查了nls_parameters,这似乎在两种环境中都是相同的。

NLS_LANGUAGE    AMERICAN
NLS_TERRITORY   AMERICA
NLS_CURRENCY    $
NLS_ISO_CURRENCY    AMERICA
NLS_NUMERIC_CHARACTERS  .,
NLS_CALENDAR    GREGORIAN
NLS_DATE_FORMAT DD-MON-RR
NLS_DATE_LANGUAGE   AMERICAN
NLS_CHARACTERSET    AL32UTF8
NLS_SORT    BINARY
NLS_TIME_FORMAT HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT    DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT  HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY   $
NLS_NCHAR_CHARACTERSET  AL16UTF16
NLS_COMP    BINARY
NLS_LENGTH_SEMANTICS    BYTE
NLS_NCHAR_CONV_EXCP FALSE

I've checked in a lot of places but no solution. 我已经检查了很多地方,但没有解决办法。 If anybody has any idea how this could be solved, please help. 如果有人知道如何解决此问题,请提供帮助。

I'm going to make a wild guess that tdj_tran_dt is actually a DATE column, since you mentioned that you were using to_char(tdj_tran_dt,'DD-MON-YYYY') , which would have failed if it was a string. 我要tdj_tran_dt猜测tdj_tran_dt实际上是DATE列,因为您提到您使用的是to_char(tdj_tran_dt,'DD-MON-YYYY') ,如果它是字符串,那将失败。 (It could also explain why to_date(tdj_tran_dt,'DD-MON-RRRR') failed in another environment, if the nls_date_format there was not compatible with 'DD-MON-RRRR' .) Therefore the issue is that some of the dates were incorrectly entered as year 0017 etc, ie 1st century AD. (这也可以解释为什么to_date(tdj_tran_dt,'DD-MON-RRRR')在另一个环境中失败,如果那里的nls_date_format'DD-MON-RRRR'不兼容。)因此,问题在于某些日期是错误地输入为0017年等,即公元1世纪。

If this is the case, then you probably want to clean up dates that are wildly out by discarding the century and substituting a nearer one, while retaining dates that are closer to today. 如果是这种情况,那么您可能希望通过丢弃本世纪并替代一个更接近的日期来清理那些过时的日期,同时保留更接近今天的日期。

with demo (tdj_tran_dt) as
     ( select date '0017-01-30' from dual union all
       select date '1917-01-30' from dual union all
       select date '1960-01-30' from dual union all
       select date '2017-01-30' from dual )
select tdj_tran_dt
     , to_date(to_char(tdj_tran_dt,'DD-MON-YY'),'DD-MON-RR') as fixed_tran_dt
from   demo
order by tdj_tran_dt;

TDJ_TRAN_DT  FIXED_TRAN_DT
------------ -------------
30-JAN-0017  30-JAN-2017
30-JAN-1917  30-JAN-2017
30-JAN-1960  30-JAN-1960
30-JAN-2017  30-JAN-2017

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM