oracle 带有管道分隔符的选择查询中列名和列的硬编码值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18180138/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hardcode value of column name and column in select query with pipe delimiter
提问by Devashri B.
I want to hard-code a column name and its value as New York
in a select query with pipe delimiter. E.g. Emp
table has columns EmpId
, EmpName
, Salary
. I want output such as
我想对列名及其值进行硬编码,就像New York
在带有管道分隔符的选择查询中一样。例如Emp
表有列EmpId
, EmpName
, Salary
。我想要输出,例如
Select EmpId ||'|'||
EmpName ||'|'||
'NewYork' as City ||'|'||
Salary
from Emp
Here I want City
column in output query and its value should be 'NewYork'
for each record.
这里我想要City
输出查询中的列,它的值应该是'NewYork'
每条记录。
Here I am getting error as "FROM keyword not found where expected"
. When I use comma instead of Pipe Delimiter I am getting result but not with Pipe. Please advise. Thanks in advance.
在这里,我收到错误为"FROM keyword not found where expected"
. 当我使用逗号而不是管道分隔符时,我得到了结果,但没有使用管道。请指教。提前致谢。
回答by user272735
with emps as (
select 1 as id, 'Smith' as name, 2000 as salary from dual
union
select 2, 'Jones', 2200 from dual
)
select
id || '|' || name as record1,
id || '|' || name || '|NewYork|' || salary as record2,
'NewYork' as city
from emps;