sqloracle-databaseto-char

Unable to Convert to Date


I am trying to return just the date from a datetime field When I run the Select Claus with just the first line, it work as expected. But when I add the second line, I receive From keyword not found error.

SELECT To_Char(t.inc_date_time,'yyyy-mm-dd hh24:mi:ss') AS Date_Time,
       To_Char(t.inc_date_time,'DD/MM/YYYY') AS Date
FROM tbl t
FETCH first 10 rows only

ORA-00923: FROM keyword not found where expected


Solution

  • In Oracle, DATE is a reserved word and you cannot use it as an unquoted identifier. Either change your query to use a different identifier:

    SELECT To_Char(t.inc_date_time,'yyyy-mm-dd hh24:mi:ss') AS Date_Time,
           To_Char(t.inc_date_time,'DD/MM/YYYY') AS dt
    FROM tbl t
    FETCH first 10 rows only
    

    Or quote the identifier:

    SELECT To_Char(t.inc_date_time,'yyyy-mm-dd hh24:mi:ss') AS Date_Time,
           To_Char(t.inc_date_time,'DD/MM/YYYY') AS "DATE"
    FROM tbl t
    FETCH first 10 rows only
    

    db<>fiddle here