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

SQL查询报错ORA-00923: FROM关键字未在预期位置找到求助

解决ORA-00923: FROM关键字未在预期位置找到的问题

一眼就能看出问题所在——你的SQL语句里**Hindi列别名后面多了一个逗号**!这个多余的逗号会让Oracle的解析器误以为后面还有要查询的列,但紧接着出现的是FROM关键字,完全打破了SQL的语法规则,所以才抛出了ORA-00923错误。

修正后的SQL语句

select 
    pl.label_id, 
    ( select pv.label_value from PV_I18N_ACTIVE_LOCALE_LABEL pv where pv.locale_id='English' and pv.label_type_id = 'LABEL' and pv.label_id = pl.label_id ) as 'English', 
    ( select pv.label_value from PV_I18N_ACTIVE_LOCALE_LABEL pv where pv.locale_id='Hindi' and pv.label_type_id = 'LABEL' and pv.label_id = pl.label_id ) as 'Hindi' -- 去掉了这里多余的逗号
from PV_I18N_ACTIVE_LOCALE_LABEL pl 
where pl.label_type_id = 'LABEL' 
order by pl.label_id

额外优化建议

虽然修正逗号后查询能正常运行,但你用的两个相关子查询在数据量较大时,性能可能会打折扣。推荐用自连接的方式重写,逻辑和原查询完全一致,但执行效率会更高:

select 
    pl.label_id,
    pv_eng.label_value as 'English',
    pv_hin.label_value as 'Hindi'
from PV_I18N_ACTIVE_LOCALE_LABEL pl
left join PV_I18N_ACTIVE_LOCALE_LABEL pv_eng
    on pl.label_id = pv_eng.label_id
    and pv_eng.locale_id = 'English'
    and pv_eng.label_type_id = 'LABEL'
left join PV_I18N_ACTIVE_LOCALE_LABEL pv_hin
    on pl.label_id = pv_hin.label_id
    and pv_hin.locale_id = 'Hindi'
    and pv_hin.label_type_id = 'LABEL'
where pl.label_type_id = 'LABEL'
order by pl.label_id

左连接还能保证:即使某个标签没有对应语言的翻译,这条标签记录也会被保留(对应语言列显示为NULL),和你原查询的逻辑完全匹配。

内容的提问来源于stack exchange,提问作者Chinmoy Nandi

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 07:00:25