oracle ORA-00923:在预期问题处未找到FROM关键字

00jrzges  于 2023-05-16  发布在  Oracle
关注(0)|答案(2)|浏览(298)
SELECT
    maint_id,
    to_char(maint_datetime, 'dd-Mon-yyyy') AS date,
    prop_address,
    owner_givname
    || ' '
    || owner_famname AS owner_name,
    maint_desc,
    maint_cost
FROM 
    rent.maintenance
    NATURAL JOIN rent.property
    NATURAL JOIN rent.owner
WHERE
        maint_cost > 1000
    AND maint_cost < 3000
ORDER BY
    maint_cost DESC,
    maint_datetime;

我不明白为什么我仍然保持gatting的ORA-00923错误,有人可以帮助解决它?

ddhy6vgd

ddhy6vgd1#

它是关于列别名的;你使用了date,这是一个保留给date数据类型的关键字。

SQL> select to_char(sysdate, 'dd-mm-yyyy') date
  2  from dual;
select to_char(sysdate, 'dd-mm-yyyy') date
                                      *
ERROR at line 1:
ORA-00923: FROM keyword not found where expected

将其修改为其他内容,或者(如果必须)将其括在双引号中:

SQL> select to_char(sysdate, 'dd-mm-yyyy') datum,
  2         to_char(sysdate, 'dd-mm-yyyy') "date"
  3  from dual;

DATUM      date
---------- ----------
09-05-2023 09-05-2023

SQL>
falq053o

falq053o2#

DATE是一个reserved word,不能将其用作(未加引号的)标识符。
使用不同的标识符maint_date或使用带引号的标识符"date"

SELECT
    maint_id,
    to_char(maint_datetime, 'dd-Mon-yyyy') AS maint_date,
    prop_address,
    owner_givname
    || ' '
    || owner_famname AS owner_name,
    maint_desc,
    maint_cost
FROM 
    rent.maintenance
    NATURAL JOIN rent.property
    NATURAL JOIN rent.owner
WHERE
        maint_cost > 1000
    AND maint_cost < 3000
ORDER BY
    maint_cost DESC,
    maint_datetime;

相关问题