Search code examples
oracle-databasesubquery

Select Statement Using Dual Table As A Sub Query In Oracle Generates "From keyword not found" Error


I get below error message while executing following queries using a select statement from dual table as a sub query:

Error: ORA-00923: FROM keyword not found where expected

Query 1:

select a.dt_1, a.dt_2, a.dt_1=a.dt_2 as "match_type" from
(select to_date(replace('2020-05-14 00:00:00',' 00:00:00',''), 'yyyy/mm/dd') as "dt_1", to_date('14/05/2020','dd/mm/yyyy') as "dt_2" from dual) a

Query 2:

select a.dt_1, a.dt_2, a.dt_1=a.dt_2 as match_type from
(select to_date(replace('2020-05-14 00:00:00',' 00:00:00',''), 'yyyy/mm/dd') as dt_1, to_date('14/05/2020','dd/mm/yyyy') as dt_2 from dual) a

When I individually run sub query it executes as expected, however when I run the whole statement it generates error.

Any help is appreciated.


Solution

  • Your match_type column is generating the error. Oracle doesn't support relational operator matching. You may try below query -

    SELECT a.dt_1,
           a.dt_2,
           CASE WHEN a.dt_1=a.dt_2 THEN 'TRUE' ELSE 'FLASE' END AS "match_type"
      FROM (SELECT TO_DATE(REPLACE('2020-05-14 00:00:00',' 00:00:00',''), 'yyyy/mm/dd') as "dt_1",
                   TO_DATE('14/05/2020','dd/mm/yyyy') as "dt_2"
              FROM DUAL) a;