Connecting Tech Pros Worldwide Help | Site Map

Problem with inserting dates

 
LinkBack Thread Tools Search this Thread
  #1  
Old March 24th, 2008, 11:25 PM
Newbie
 
Join Date: Mar 2008
Posts: 11
Default Problem with inserting dates

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
Reply
  #2  
Old March 25th, 2008, 04:43 AM
amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: India
Age: 25
Posts: 2,132
Default

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.  
Reply
  #3  
Old March 25th, 2008, 03:41 PM
Newbie
 
Join Date: Mar 2008
Posts: 11
Default

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...
Reply
  #4  
Old March 25th, 2008, 03:57 PM
Newbie
 
Join Date: Mar 2008
Posts: 11
Default

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.
Reply
  #5  
Old March 25th, 2008, 04:24 PM
Newbie
 
Join Date: Mar 2008
Posts: 11
Default

I found in Toad where to make the NLS parameter setting. It still does the same thing...Geeezzz.
Reply
  #6  
Old March 26th, 2008, 06:21 AM
amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: India
Age: 25
Posts: 2,132
Default

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 ?
Reply
  #7  
Old March 26th, 2008, 06:49 AM
amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: India
Age: 25
Posts: 2,132
Default

Can you post your code that you are using for INSERTING data from table A to table B?
Reply
  #8  
Old March 26th, 2008, 03:25 PM
Saii's Avatar
Expert
 
Join Date: Apr 2007
Posts: 141
Default

Just try using
to_date(to_char(<your date variable>,'DD-MON-YYYY'),'DD-MON-YYYY') while inserting to other table
Reply
  #9  
Old March 27th, 2008, 01:44 AM
Newbie
 
Join Date: Jul 2007
Posts: 16
Default

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') );
Reply
  #10  
Old March 28th, 2008, 07:50 PM
Newbie
 
Join Date: Mar 2008
Posts: 11
Default

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.
Reply
  #11  
Old March 28th, 2008, 08:12 PM
Newbie
 
Join Date: Mar 2008
Posts: 11
Default

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.
Reply
  #12  
Old March 28th, 2008, 09:23 PM
Newbie
 
Join Date: Mar 2008
Posts: 11
Default

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!
Reply
  #13  
Old March 31st, 2008, 06:34 PM
Saii's Avatar
Expert
 
Join Date: Apr 2007
Posts: 141
Default

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
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.