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 sql中的多个列连接到单个列中_Sql_Oracle - Fatal编程技术网

如何仅为匹配条件将oracle sql中的多个列连接到单个列中

如何仅为匹配条件将oracle sql中的多个列连接到单个列中,sql,oracle,Sql,Oracle,我有以下4列 empid | name | dept | ph_no --------------------------------- 123 | null | null | null 124 | mike | science | null 125 | null | physics | 789 126 | null | null | 463 127 |

我有以下4列

      empid | name  | dept     | ph_no
      ---------------------------------
      123   | null  |  null    | null
      124   | mike  |  science | null
      125   | null  |  physics | 789
      126   | null  |  null    | 463
      127   | john  |  null    | null
我需要将所有4列合并为单个列,仅用于空值。 我需要下面这样的东西--


这可以通过
case
表达式实现

select empid,empid||' is missing '|| 
trim(',' from 
     (case when name is null then 'name,' else '' end||
      case when dept is null then 'dept,' else '' end||
      case when ph_no is null then 'ph_no' else '' end
     )
     ) 
from tbl

我同意Vamsi,只想添加一个where子句,这样“完整”的就不会被返回

select empid,empid||' is missing '|| 
       case when name is null then 'name,' else '' end||
       case when dept is null then 'dept,' else '' end||
       case when ph_no is null then 'ph_no' else '' end
 from tbl
where (name is null or dept is null or ph_no is null);

您还可以使用NVL2函数

SELECT empid||' is missing '||NVL2(name, NULL, 'name, ') ||NVL2(dept, NULL, 'dept, ')||NVL2(ph_no, NULL, 'ph_no') empid
  FROM table_

非常感谢。如何将结果分组预期结果-------------------123124127缺少PHU编号123125156缺少姓名123126127缺少部门
SELECT empid||' is missing '||NVL2(name, NULL, 'name, ') ||NVL2(dept, NULL, 'dept, ')||NVL2(ph_no, NULL, 'ph_no') empid
  FROM table_