You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ORA-00923错误求助:SQL语句FROM关键字未按预期出现问题排查

解决ORA-00923错误的方案

你的SQL触发错误的核心原因是**date是Oracle的保留关键字**,直接将其用作列别名会导致数据库解析SQL时出现语法混乱,进而抛出"FROM keyword not found where expected"错误。

修正后的SQL

你可以通过两种方式解决这个问题:

方案1:转义关键字别名

用双引号包裹保留关键字,Oracle允许以此方式将其作为标识符使用:

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;

方案2:更换别名(推荐)

避免使用保留关键字作为标识符,从根源上减少后续潜在问题:

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;

补充说明

Oracle的保留关键字(如DATE、SELECT、FROM等)不能直接作为列名、别名、表名等标识符使用。若必须使用,需用双引号""包裹,但包裹后标识符会区分大小写(双引号内为小写时,查询也需小写加双引号)。因此更推荐使用非关键字的标识符,避免不必要的语法限制。

内容的提问来源于stack exchange,提问作者Zi Ying Heng

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 10:04:57