Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oracle-如何从案例中返回多个记录_Oracle_Oracle Sqldeveloper - Fatal编程技术网

Oracle-如何从案例中返回多个记录

Oracle-如何从案例中返回多个记录,oracle,oracle-sqldeveloper,Oracle,Oracle Sqldeveloper,如何从“案例默认”返回多条记录 例如: 我试着通过一个,它返回1。但当我通过'four'时,它显示了错误,比如ORA-01427单行子查询返回多行。我如何解决这个问题???您得到了ORA-01427错误,因为在else部分的select查询中返回了多行 以下查询将帮助您: WITH t AS (SELECT 1 string FROM dual UNION SELECT 2 string FROM dual UNION SELECT 1234 s

如何从“案例默认”返回多条记录

例如:


我试着通过一个,它返回1。但当我通过'four'时,它显示了错误,比如ORA-01427单行子查询返回多行。我如何解决这个问题???

您得到了ORA-01427错误,因为在else部分的select查询中返回了多行

以下查询将帮助您:

WITH t AS
     (SELECT 1 string FROM dual
     UNION
     SELECT 2 string FROM dual
     UNION
     SELECT 1234 string FROM dual
     )
SELECT * FROM t
where t.string in ( case 'one' when 'one' then 1 else (select 1234 from dual) end);

output
_____
1

WITH t AS
     (SELECT 1 string FROM dual
     UNION
     SELECT 2 string FROM dual
     UNION
     SELECT 1234 string FROM dual
     )
SELECT * FROM t
where t.string in ( case 'two' when 'one' then 1 else (select 1234 from dual) end);

output
------
1234

您可以这样尝试:

column1 in (CASE '@InputString'
                    WHEN 'One' THEN 1
                    WHEN 'Two' THEN 2
                    WHEN 'THREE' THEN 3                    
                   END)
OR (column1 in (SELECT NUM_BER FROM TABLE1 WHERE COLUMN2 LIKE '%@InputString%')
    and '@InputString' not in ('One', 'Two', 'THREE'));

您可以使用
解码

SQL> ed
Wrote file afiedt.buf

  1  with x as (
  2     select 'A' as string from dual union all
  3     select 'B' from dual union all
  4     select 'C' from dual union all
  5     select 'D' from dual
  6  )
  7  select     string , decode(string, 'A',1,'B',2,3) as string_out
  8* from       x
SQL> /

S STRING_OUT
- ----------
A          1
B          2
C          3
D          3

CASE语句中的每个WHEN子句只能返回一个值,不能返回一组值。下面@ABCade发布的解决方案是您的最佳选择。
SQL> ed
Wrote file afiedt.buf

  1  with x as (
  2     select 'A' as string from dual union all
  3     select 'B' from dual union all
  4     select 'C' from dual union all
  5     select 'D' from dual
  6  )
  7  select     string , decode(string, 'A',1,'B',2,3) as string_out
  8* from       x
SQL> /

S STRING_OUT
- ----------
A          1
B          2
C          3
D          3