我正在使用这个 SQL:
SELECT sys_tbldef_desc as tbldef_desc
FROM sys_tbldef
WHERE UPPER(tbldef_desc) = UPPER('a tbldef desc')
我得到这个错误:
Error at line 1 - Dynamic SQL Error
SQL error code = -206
Column unknown
TBLDEF_DESC
有谁知道解决方案?
你不能使用ALIAS
onWHERE
子句。SQL操作顺序如下
该WHERE
子句在该子句之前首先执行SELECT
。您应该改用列名。例如:
SELECT sys_tbldef_desc as tbldef_desc
FROM sys_tbldef
WHERE UPPER(sys_tbldef_desc) = UPPER('a tbldef desc')
如果您真的想使用ALIAS
,则需要子查询,例如:
SELECT tbldef_desc
FROM
(
SELECT sys_tbldef_desc as tbldef_desc
FROM sys_tbldef
) a
WHERE UPPER(tbldef_desc) = UPPER('a tbldef desc')
但我更喜欢第一个。
您不能在 WHERE 子句中使用别名,您的查询应该是,
SELECT sys_tbldef_desc as tbldef_desc
FROM sys_tbldef
WHERE UPPER(sys_tbldef_desc) = UPPER('a tbldef desc')
我找到了解决方案:
SELECT *
FROM sys_tbldef
where UPPER(case when sys_tbldef_trnslt_desc is null
then sys_tbldef_desc else sys_tbldef_trnslt_desc end) = UPPER('a table desc')