Problem with inserting dates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kalyson
    New Member
    • Mar 2008
    • 11

    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
  • amitpatel66
    Recognized Expert Top Contributor
    • Mar 2007
    • 2358

    #2
    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:

    [code=oracle]

    ALTER SESSION SET nls_date_format = 'DD-MON-RR'

    [/code]

    Comment

    • kalyson
      New Member
      • Mar 2008
      • 11

      #3
      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...

      Comment

      • kalyson
        New Member
        • Mar 2008
        • 11

        #4
        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.

        Comment

        • kalyson
          New Member
          • Mar 2008
          • 11

          #5
          I found in Toad where to make the NLS parameter setting. It still does the same thing...Geeezzz .

          Comment

          • amitpatel66
            Recognized Expert Top Contributor
            • Mar 2007
            • 2358

            #6
            Did you try this:

            [code=oracle]

            ALTER SESSION SET nls_date_format = 'DD-MON-RRRR'

            [/code]

            With 4 R's ?

            Comment

            • amitpatel66
              Recognized Expert Top Contributor
              • Mar 2007
              • 2358

              #7
              Can you post your code that you are using for INSERTING data from table A to table B?

              Comment

              • Saii
                Recognized Expert New Member
                • Apr 2007
                • 145

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

                Comment

                • Mala232
                  New Member
                  • Jul 2007
                  • 16

                  #9
                  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') );

                  Comment

                  • kalyson
                    New Member
                    • Mar 2008
                    • 11

                    #10
                    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.

                    Comment

                    • kalyson
                      New Member
                      • Mar 2008
                      • 11

                      #11
                      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.

                      Comment

                      • kalyson
                        New Member
                        • Mar 2008
                        • 11

                        #12
                        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

                        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!

                        Comment

                        • Saii
                          Recognized Expert New Member
                          • Apr 2007
                          • 145

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

                          Comment

                          Working...