使用管道分隔符的select查询中列名和列的硬编码值

时间:2013-08-12 05:34:02

标签: oracle select hardcoded

我想在使用管道分隔符的select查询中将列名及其值硬编码为New York。例如。 Emp表格包含EmpIdEmpNameSalary列。我想要输出,如

Select EmpId ||'|'||
       EmpName ||'|'||
       'NewYork' as City  ||'|'||
       Salary
 from Emp

此处我想在输出查询中使用City列,并且每个记录的值应为'NewYork'

我在这里收到错误"FROM keyword not found where expected"。当我使用逗号而不是管道分隔符时,我得到的结果却没有使用Pipe。请指教。提前谢谢。

1 个答案:

答案 0 :(得分:0)

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;