I’m using Oracle 11g Schema
I want to select the month and day from a date concatenate it and put it into a column.
The syntax I have here makes sense but its throwing an error of..
INSERT INTO OB_SELECT_LST12_SPG WED
VALUES (((TO_CHAR(TO_DATE('RET_DATE', MM))||( TO_CHAR(TO_DATE('RET_DATE', DD)));
“SQL Error: ORA-00907: missing right parenthesis”
Any help is greatly appreciated.
Thanks.
Some points first…
ret_dateis a column don’t encapsulate it in quotation marks (') as you won’t be able to convert the string'ret_date'into a date.However, assuming
ret_dateis a string that looks like13-06-2012If
ret_dateis a date data-type then you can remove the inner conversion.to_charandto_dateboth make use of datetime format models, which have a number of options.Please don’t do this though. Always store dates as dates
From your comments
ret_dateis a date and the columnwedis a character. You’re getting the error bind variable not declared because you haven’t specified the variable. I’m going to assume thatret_dateis in another table as it’s a date, in which case lose the values key-word and insert directly from that table:This shouldn’t be required though, you can always convert a date into whatever you want on exit from the database. If you don’t store it as a date in the database then it’s easy for errors and incorrect values to creep in. I personally would change the column
wedto a date, in which case your query becomes the very simple:You can then use the correct datetime format model for your needs when selecting from the database.