Connecting Tech Pros Worldwide Help | Site Map

Problem with inserting dates

Newbie
 
Join Date: Mar 2008
Posts: 11
#1: Mar 25 '08
I am using a variable of type: DATE

Our instance of Oracle has: NLS_DATE_FORMAT DD-MON-YY

I select a DATE from table A into this date variable. I then insert that variable into another table, B. Dates that were before 2000 change -- like 1995 becomes 2095. I do nothing to the date between select and insert.

My PL/SQL is being executed in Toad version 9.1. Oracle is release 1002000300

Does anyone know what is wrong?

Thanks
amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,192
#2: Mar 25 '08

re: Problem with inserting dates


Quote:

Originally Posted by kalyson

I am using a variable of type: DATE

Our instance of Oracle has: NLS_DATE_FORMAT DD-MON-YY

I select a DATE from table A into this date variable. I then insert that variable into another table, B. Dates that were before 2000 change -- like 1995 becomes 2095. I do nothing to the date between select and insert.

My PL/SQL is being executed in Toad version 9.1. Oracle is release 1002000300

Does anyone know what is wrong?

Thanks

That shouldnt be the case.
Can you try the below query and then execute your procedure:

Expand|Select|Wrap|Line Numbers
  1.  
  2. ALTER SESSION SET nls_date_format = 'DD-MON-RR'
  3.  
  4.  
Newbie
 
Join Date: Mar 2008
Posts: 11
#3: Mar 25 '08

re: Problem with inserting dates


I'll admit to being a newbie with PL/SQL, but I did already try that. I got a syntax error. Maybe I should put it outside the PL/SQL procedure...
Newbie
 
Join Date: Mar 2008
Posts: 11
#4: Mar 25 '08

re: Problem with inserting dates


Well, I ran the alter session outside the procedure, then ran the procedure and same thing happens. I print out the date variable just prior to insertion, and the dates are like, 1997, 1995. Then in the table I see they have been inserted as 2097, 2095. Very strange.
Newbie
 
Join Date: Mar 2008
Posts: 11
#5: Mar 25 '08

re: Problem with inserting dates


I found in Toad where to make the NLS parameter setting. It still does the same thing...Geeezzz.
amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,192
#6: Mar 26 '08

re: Problem with inserting dates


Did you try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. ALTER SESSION SET nls_date_format = 'DD-MON-RRRR'
  3.  
  4.  
With 4 R's ?
amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,192
#7: Mar 26 '08

re: Problem with inserting dates


Can you post your code that you are using for INSERTING data from table A to table B?
Saii's Avatar
Expert
 
Join Date: Apr 2007
Posts: 141
#8: Mar 26 '08

re: Problem with inserting dates


Just try using
to_date(to_char(<your date variable>,'DD-MON-YYYY'),'DD-MON-YYYY') while inserting to other table
Newbie
 
Join Date: Jul 2007
Posts: 16
#9: Mar 27 '08

re: Problem with inserting dates


Quote:

Originally Posted by kalyson

I am using a variable of type: DATE

Our instance of Oracle has: NLS_DATE_FORMAT DD-MON-YY

I select a DATE from table A into this date variable. I then insert that variable into another table, B. Dates that were before 2000 change -- like 1995 becomes 2095. I do nothing to the date between select and insert.

My PL/SQL is being executed in Toad version 9.1. Oracle is release 1002000300

Does anyone know what is wrong?

Thanks


hi ,

try this

SQL> alter session set NLS_DATE_FORMAT = 'DD-MM-RRRR';

and try to insert the date values by converting it to

insert into table_name values ( to_date( <date column>,' RRRR-MM-DD HH:MI:SS') );
Newbie
 
Join Date: Mar 2008
Posts: 11
#10: Mar 28 '08

re: Problem with inserting dates


Quote:

Originally Posted by Saii

Just try using
to_date(to_char(<your date variable>,'DD-MON-YYYY'),'DD-MON-YYYY') while inserting to other table

Thanks, but that did not work. I had already tried it a while back, but it was a good suggestion.
Newbie
 
Join Date: Mar 2008
Posts: 11
#11: Mar 28 '08

re: Problem with inserting dates


Quote:

Originally Posted by Mala232

hi ,

try this

SQL> alter session set NLS_DATE_FORMAT = 'DD-MM-RRRR';

and try to insert the date values by converting it to

insert into table_name values ( to_date( <date column>,' RRRR-MM-DD HH:MI:SS') );

Oracle gives an error for this, unfortunately.
Newbie
 
Join Date: Mar 2008
Posts: 11
#12: Mar 28 '08

re: Problem with inserting dates


Originally Posted by Saii
Just try using
to_date(to_char(<your date variable>,'DD-MON-YYYY'),'DD-MON-YYYY') while inserting to other table

Quote:

Originally Posted by kalyson

Thanks, but that did not work. I had already tried it a while back, but it was a good suggestion.


I figured out the solution, this one was close, but it was actually this:

to_char(<your date variable>,'DD-MON-YYYY') but with quotes around it. Have to include the '' around it, too. Just the to_char by itself with formatting did the trick!

Thanks!
Saii's Avatar
Expert
 
Join Date: Apr 2007
Posts: 141
#13: Mar 31 '08

re: Problem with inserting dates


I thought you need a date datatype column.Ignoring to_date conversion,results in varchar2 column, if this suits your requirement, then you are good to go :)
Reply