[英]Concatenate and use in where clause oracle plsql
我必须连接两个字段并在 where 子句中使用连接字段,但它给了我无效的标识符。 如何解决此查询。
select i.FIRST_NAME || ' - ' || i.LAST_NAME as NAME, i.* from CONTACT i
where NAME = 'JOHN - HANKS'
这给了我
ORA-00904: "NAME": invalid identifier
00904. 00000 - "%s: invalid identifier"
您不能在同一级别使用列别名。 只需使用子查询(或重复表达式):
select c.*
from (select i.FIRST_NAME || ' - ' || i.LAST_NAME as NAME, i.*
from CONTACT i
) c
where c.NAME = 'JOHN - HANKS';
WITH 子句也是一个很好的选择,更好的可读性。 另外,如果子查询要被多次使用,那就更好了。
WITH data as(
select i.FIRST_NAME || ' - ' || i.LAST_NAME as NAME, i.* from CONTACT i)
select * from data where name = 'JOHN - HANKS';
选择 i.FIRST_NAME || ' - ' || i.LAST_NAME as NAME, i.* from CONTACT i where i.first_name ||'~'||i.last_name = 'JHON~HANKS';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.