Oracle to_date error caused by different language Environments

Source: Internet
Author: User

Oracle to_date error caused by different language Environments

I wrote a stored procedure and used a function in it. The function contains a to_date (dateFrom, 'yyyy/mm/dd'). After running the function, I found that the data was inserted incorrectly, the inserted data is "0001/9/14 ". I don't know why the data is like this. After debugging, I found that the date "" entered in the test window changed to "01-SEP-14" in the program, it turned out to be September 14.

If you know the reason, let's talk about the solution: to_date (to_char (dateFrom, 'yyyy/mm/dd'), 'yyyy/mm/dd '). Run again and the record is successful.


Oracle insertion date Error

The environment variable nls_date_language is not set.

The following is the query result when no settings are set:
SQL> select to_char (sysdate, 'dd-mon-yy') from dual;

TO_CHAR (SYSDAT
--------------
5-10-11 months

Query the set statement
SQL> show parameter nls_date_language;

NAME TYPE VALUE
------------------------------------------------------
Nls_date_language string

Modify the set statement
SQL> alter session set nls_date_language = 'American ';

The session has been changed.

Query after modification
SQL> select to_char (sysdate, 'dd-mon-yy') from dual;

TO_CHAR (SYSD
------------
05---11

SQL> SELECT TO_DATE ('05-oct-11 ', 'dd-mon-yy') from dual;

TO_DATE ('05-
------------
05---11

ORACLE to_date

It must be because the format of a record does not conform to YYYYMMDD.
You should write a function to find out and correct such exceptions.
Create function is_valid_date (p_yyyyymmdd in varchar2) return number is
Rochelle date;
Begin
Rochelle date = to_date (p_yyyyymmdd, 'yyyymmdd ');
Return 1;
Exception when others then
Return 0;
End;

Then write the select statement.
Select * from pc_xx where is_valid_date (substr (rydjsj, 1, 8) = 0;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.