High usage of Oracle to_date function

Due to various reasons, in our system, C set period (PERIOD_NAME) due to the formatting, the format stored in the database layer Mar-19, rather than the conventional 2019-03.

We can not change the database, involved too many points.

However, it is inconvenient for the Mar-19, for example it can not compare the size of the data storing period during the same format directly to 2019-03.

Because Oracle supports MON format, so try to use

the SELECT the TO_CHAR (to_date ( ' Mar-19 ' , ' MM-YY ' ), ' YYYY-MM ' ) the FROM DUAL; // ORA-01843: Invalid month

But unfortunately it reported ORA-01843: Invalid month, most of the solutions are NLS_LANGUAGE or by changing the language AMERICAN SESSION way to change the entire database of environmental parameters, feasible, but not practical.

In fact, not, as you can

select TO_CHAR(to_DATE('Mar-19','MM-YY','NLS_DATE_LANGUAGE = ''AMERICAN'''),'YYYY-MM') FROM DUAL;

 

reference:

When translated into strings to_date ORA-01843 not a valid month Analysis

Oracle Dates and Times 

Guess you like

Origin www.cnblogs.com/huanghongbo/p/11291870.html