Connecting Tech Pros Worldwide Help | Site Map

Problem with inserting dates

  #1  
Old March 25th, 2008, 12:25 AM
Newbie
 
Join Date: Mar 2008
Posts: 11
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
  #2  
Old March 25th, 2008, 05:43 AM
amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,188

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

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

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

re: Problem with inserting dates


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

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 ?
  #7  
Old March 26th, 2008, 07:49 AM
amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,188

re: Problem with inserting dates


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

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
  #9  
Old March 27th, 2008, 02:44 AM
Newbie
 
Join Date: Jul 2007
Posts: 16

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

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

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

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with inserting date value into MSSQL Igal answers 2 November 20th, 2006 10:05 AM
Inserting dates into SQL Server DB Andrew Banks answers 9 November 18th, 2005 02:28 AM
strange problem with dates Zibi answers 4 July 23rd, 2005 10:32 AM
Problem with inserting dates using mx.ODBC.Windows driver Fons Dijkstra answers 1 July 18th, 2005 02:11 AM