Solved

INSERT with to_date in values clause

Posted on 2010-11-18
2
760 Views
Last Modified: 2013-12-18
I'm tyring to insert a date value into a date field using to_date in the values clause, but continually get the following error.  I've tried a large variety of date formats and masks, but my preferred is MM/DD/YYYY hh:mm PM TZR.


Error starting at line 1 in command:
INSERT INTO pa_cpnt_user (col_num, cpnt_typ_id, cpnt_id, rev_dte, user_value, lst_upd_usr, lst_upd_tstmp) VALUES (1124,TRNG,test-item, to_date('20070901 02:00','yyyymmdd hh:mm'),08,SS_UPDATE,SYSDATE)
Error at Command Line:1 Column:183
Error report:
SQL Error: ORA-00984: column not allowed here
00984. 00000 -  "column not allowed here"
*Cause:    
*Action:


Here is the sql:

INSERT INTO pa_cpnt_user (col_num, cpnt_typ_id, cpnt_id, rev_dte, user_value, lst_upd_usr, lst_upd_tstmp) VALUES (1124,TRNG,test-item, to_date('20070901 02:00','yyyymmdd hh:mm'),08,SS_UPDATE,SYSDATE);

My table is as follows:

desc pa_cpnt_user
Name                           Null                             Type                                                                                                                                                                                                                                                                                      
------------------------------ -------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
COL_NUM                        NOT NULL                         NUMBER(38)                                                                                                                                                                                                                                                                                
CPNT_TYP_ID                    NOT NULL                         VARCHAR2(90)                                                                                                                                                                                                                                                                              
CPNT_ID                        NOT NULL                         VARCHAR2(90)                                                                                                                                                                                                                                                                              
REV_DTE                        NOT NULL                         DATE                                                                                                                                                                                                                                                                                      
USER_VALUE                                                      VARCHAR2(120)                                                                                                                                                                                                                                                                              
LST_UPD_USR                                                     VARCHAR2(90)                                                                                                                                                                                                                                                                              
LST_UPD_TSTMP                                                   DATE                                                                                                                                                                                                                                                                                      
0
Comment
Question by:mattturley
  • 2
2 Comments
 
LVL 3

Accepted Solution

by:
mpaladugu earned 500 total points
ID: 34169690
all the charecter values shoudl be enclosed in sngle quotes,

IINSERT INTO pa_cpnt_user (col_num,
                          cpnt_typ_id,
                          cpnt_id,
                          rev_dte,
                          user_value,
                          lst_upd_usr,
                          lst_upd_tstmp)
    VALUES (1124,
            'TRNG',
            'test-item',
            TO_DATE ('20070901 02:00', 'yyyymmdd hh:mm'),
            08,
            'SS_UPDATE',
            sysdate)
0
 
LVL 3

Expert Comment

by:mpaladugu
ID: 34169723
In the above comment, use MI instead of MM in place for minutes.

INSERT INTO pa_cpnt_user (col_num,
                          cpnt_typ_id,
                          cpnt_id,
                          rev_dte,
                          user_value,
                          lst_upd_usr,
                          lst_upd_tstmp)
    VALUES (1124,
            'TRNG',
            'test-item',
            TO_DATE ('20070901 02:00', 'yyyymmdd hh:mm'),
            08,
            'SS_UPDATE',
            sysdate)


and to try various date formats, just to test which format returns what. and if particular format is correct use for example.
Select TO_DATE ('20070901 02:00', 'yyyymmdd hh:mi PM') from dual
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now