0

Need to convert date format from (source oracle) yyyy/mm/dd to (target - SQL Server) mm/dd/yyyy.

Current Query:

SELECT* FROM WVT.WVCAS 
WHERE to_date(dttmcutpull, 'yyyy/mm/dd hh24:mi:ss', 'mm/dd/yyyy hh24:mi:ss')

Getting error:

ORA-00920: invalid relational operator

Please help.

1
  • If it's already a date field you don't have to use to_date, you would just use to_char(dttmcutpull,'mm/dd/yyyy'). Also, you have to set it to equal something, or you will always get that error. If that is a date in the WVT.WVCAS table, and you just want to see the format change, it needs to go after the select. Commented Jun 18, 2014 at 1:04

2 Answers 2

1

"Invalid relational operator" usually means that you have a where clause without a comparison. In your case, the where clause has the conversion to_date(), but no comparison. Perhaps you mean something like:

SELECT *
FROM WVT.WVCAS 
WHERE dttmcutpull > sysdate - 1;

In other words, merely converting the data is not sufficient, you have to compare it to something.

If you just want to do the conversion, then put that in the select:

SELECT w.*,
       to_char(dttmcutpull, 'mm/dd/yyyy hh24:mi:ss') as NewDate
FROM WVT.WVCAS w;

EDIT:

You have to convert each column independently, not all at once. to_char() takes two arguments, a date and a format:

SELECT w.*,
       to_char(dttmcutpull, 'mm/dd/yyyy hh24:mi:ss') as date1,
       to_char(DTTMPULLll, 'mm/dd/yyyy hh24:mi:ss') as date2,
       to_char(DTTMRUNll, 'mm/dd/yyyy hh24:mi:ss') as date3,
       to_char(SYSLOCKDATEll, 'mm/dd/yyyy hh24:mi:ss') as date4,
       to_char(SYSMODATEll, 'mm/dd/yyyy hh24:mi:ss') as date5,
       to_char(SYSCREATEDATE 'mm/dd/yyyy hh24:mi:ss') as NewDate
FROM WVT.WVCAS w;
Sign up to request clarification or add additional context in comments.

4 Comments

Receiving error ORA-00933: SQL command not properly ended when I run: SELECT w.*, to_date(dttmcutpull, 'yyyy/mm/dd hh24:mi:ss', 'mm/dd/yyyy hh24:mi:ss') as NewDate FROM WVT.WVCAS w;
@user3750517 - if it's for display then you should be using to_char() as Bob said; and you shouldn't have two format masks for either function.
@Gordon Linoff now I'm getting a missing right parenthesis error.
I used this query: SELECT w.*, to_char(dttmcutpull, DTTMPULL, DTTMRUN, SYSLOCKDATE, SYSMODATE, SYSCREATEDATE 'mm/dd/yyyy hh24:mi:ss') as NewDate FROM WVT.WVCAS w;
0
SELECT w.*,
       TO_CHAR(to_date(dttmcutpull, 'yyyy/mm/dd hh24:mi:ss'), 'mm/dd/yyyy hh24:mi:ss') as NewDate
FROM WVT.WVCAS w;

What I am doing is,

  • dttmcutpull is a STRING (VARCHAR) with format yyyy/mm/dd hh24:mi:ss
  • Initially converting the string to a DATE using TO_DATE
  • Re-converting the DATE to a string of mm/dd/yyyy hh24:mi:ss using TO_CHAR function

Used Syntax is similar to

SELECT
TO_CHAR 
( 
    TO_DATE (STRING_FIELD_VALUE, EXISTING_FORMAT_OF_STRING_FIELD_VALUE),
    EXPECTED_FORMAT_OF_NEW_VALUE
) AS NEW_STRING_FIELD_VALUE;

EDIT: Your Query should be:

  1. If dttmcutpull, DTTMPULLll,DTTMRUNll etc are DATE datatypes then

    SELECT w.*, to_char(dttmcutpull, 'mm/dd/yyyy hh24:mi:ss') as NEW_DATE1, to_char(DTTMPULLll, 'mm/dd/yyyy hh24:mi:ss') as NEW_DATE2, to_char(DTTMRUNll, 'mm/dd/yyyy hh24:mi:ss') as NEW_DATE3, to_char(SYSLOCKDATEll, 'mm/dd/yyyy hh24:mi:ss') as NEW_DATE4, to_char(SYSMODATEll, 'mm/dd/yyyy hh24:mi:ss') as NEW_DATE5, to_char(SYSCREATEDATE 'mm/dd/yyyy hh24:mi:ss') as NEW_DATE6 FROM WVT.WVCAS w;

  2. If dttmcutpull, DTTMPULLll,DTTMRUNll etc are VARCHAR(STRING/CHARACTER) datatypes then

    SELECT w.*, TO_CHAR(to_date(dttmcutpull, 'yyyy/mm/dd hh24:mi:ss'), 'mm/dd/yyyy hh24:mi:ss') as NEW_DATE1, TO_CHAR(to_date(DTTMPULLll, 'yyyy/mm/dd hh24:mi:ss'), 'mm/dd/yyyy hh24:mi:ss') as NEW_DATE2, TO_CHAR(to_date(DTTMRUNll, 'yyyy/mm/dd hh24:mi:ss'), 'mm/dd/yyyy hh24:mi:ss') as NEW_DATE3, TO_CHAR(to_date(SYSLOCKDATEll, 'yyyy/mm/dd hh24:mi:ss'), 'mm/dd/yyyy hh24:mi:ss') as NEW_DATE4, TO_CHAR(to_date(SYSMODATEll, 'yyyy/mm/dd hh24:mi:ss'), 'mm/dd/yyyy hh24:mi:ss') as NEW_DATE5, TO_CHAR(to_date(SYSCREATEDATE , 'yyyy/mm/dd hh24:mi:ss'), 'mm/dd/yyyy hh24:mi:ss') as NEW_DATE6 FROM WVT.WVCAS w;

1 Comment

Hi Nishanthi....I'm getting this error. Message Code: RR_4035 Message: SQL Error [ ORA-00907: missing right parenthesis

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.