如何在SQL查询中使用CASE分配两列

问题描述 投票:0回答:2

如何使用SQL query语句为CASE中的多个列分配值。当我尝试如下所示时,出现错误。

select case when 1=1 then 'Y' column1, 'Yes' column2 end from dual;

ORA-00905: missing keyword 00905. 00000 - "missing keyword" *Cause: *Action: Error at Line: 24 Column: 31

请您帮忙。

sql oracle
2个回答
0
投票

重复case

SQL> select case when 1 = 1 then 'Y'
  2              else 'N'
  3         end column1,
  4         --
  5         case when 1 = 1 then 'Y'
  6              else 'N'
  7         end column2
  8  from dual;

C C
- -
Y Y

SQL>

0
投票

也许你想要:

select 'Y' as column1, 'Yes' as column1
from dual
where 1=1
union all
select NULL, NULL
from dual
where not (1=1);
© www.soinside.com 2019 - 2024. All rights reserved.