Sql Case语句错误无法选择多个列

时间:2015-07-20 10:33:41

标签: sql oracle case oracle-apex

我需要从Case语句中的SQL Select语句中获取Supplier ID。一旦我将A.SUPPLIER_ID放入Select语句,我就会收到错误。这该怎么做?

Select 
       CASE 
         WHEN  TYPE = 1 THEN 
           (
              SELECT A.name 
              from BIZZXE_V2_SCH.SUPPLIERS A
              where A.SUPPLIER_ID = 30
           ) 
        ELSE
          (
            SELECT A.name 
            from BIZZXE_V2_SCH.STOCK_SUPPLIER A
            where A.SUPPLIER_ID = 31
          )
        END name
from DUAL;

3 个答案:

答案 0 :(得分:1)

您无法将完整查询放入case语句中。但这应该有用

SELECT name
from BIZZXE_V2_SCH.SUPPLIERS
where SUPPLIER_ID = 30 and TYPE = 1
union all
SELECT name
from BIZZXE_V2_SCH.STOCK_SUPPLIER
where SUPPLIER_ID = 31 and TYPE <> 1

答案 1 :(得分:0)

你应该能够在WHERE语句中处理这个问题,就像这样。

SELECT A.name 
FROM BIZZXE_V2_SCH.STOCK_SUPPLIER A
WHERE (A.SUPPLIER_ID = 30 AND TYPE = 1) OR
A.SUPPLIER_ID = 31

答案 2 :(得分:0)

使用ghi声明

IF/ELSE