Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.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
Sql 不惜一切代价,我知道;通常我们对此无能为力。所以如果我有另一个专栏,我会把它放在connectby命令中,就像这个connectby level是的,就是它。 ID NAME ColumnA ColumnB 1 ITEM1 ,2_Sql_Oracle - Fatal编程技术网

Sql 不惜一切代价,我知道;通常我们对此无能为力。所以如果我有另一个专栏,我会把它放在connectby命令中,就像这个connectby level是的,就是它。 ID NAME ColumnA ColumnB 1 ITEM1 ,2

Sql 不惜一切代价,我知道;通常我们对此无能为力。所以如果我有另一个专栏,我会把它放在connectby命令中,就像这个connectby level是的,就是它。 ID NAME ColumnA ColumnB 1 ITEM1 ,2,sql,oracle,Sql,Oracle,不惜一切代价,我知道;通常我们对此无能为力。所以如果我有另一个专栏,我会把它放在connectby命令中,就像这个connectby level是的,就是它。 ID NAME ColumnA ColumnB 1 ITEM1 ,2562,2563,2564, ,121,122,123 2 ITEM2 NULL ,6455,545, 3 ITEM3 ,1221,1546, NULL 4 ITEM4 NULL


不惜一切代价,我知道;通常我们对此无能为力。所以如果我有另一个专栏,我会把它放在connectby命令中,就像这个connectby level是的,就是它。
ID NAME   ColumnA           ColumnB
1  ITEM1  ,2562,2563,2564,  ,121,122,123
2  ITEM2  NULL              ,6455,545,
3  ITEM3  ,1221,1546,       NULL
4  ITEM4  NULL              NULL
ITEM   ColumnA   ColumB
ITEM1  2562      121
ITEM1  2563      122
ITEM1  2564      123
ITEM2  NULL      6455
ITEM2  NULL      545
....
SELECT ug.*
FROM USER_GROUP ug
WHERE EXISTS (SELECT 1
              FROM TableA t1
              WHERE t1.COLUMNA LIKE '%,' || ug.ID || ',%'
             )
AND EXISTS (SELECT 1
              FROM TableA t1
              WHERE t1.COLUMNB LIKE '%,' || ug.ID || ',%'
             );
SQL> with test (id, name, cola, colb) as
  2    (select 1, 'item1', ',2562,2563,2564,', ',121,122,123,' from dual union all
  3     select 2, 'item2', null              , ',6455,545,'    from dual union all
  4     select 3, 'item3', ',1221,1546,'     , null            from dual union all
  5     select 4, 'item4', null              , null            from dual
  6    ),
  7  remcom
  8    -- remove leading and trailing commas
  9  as (select id,
 10        name,
 11        rtrim(ltrim(cola, ','), ',') cola,
 12        rtrim(ltrim(colb, ','), ',') colb
 13      from test
 14     )
 15  select id,
 16    name,
 17    regexp_substr(cola, '[^,]+', 1, column_value) cola,
 18    regexp_substr(colb, '[^,]+', 1, column_value) colb
 19  from remcom r cross join
 20    table(cast(multiset(select level from dual
 21                        connect by level <= regexp_count(nvl(r.cola, r.colb), ',') + 1
 22                       ) as sys.odcinumberlist))
 23  order by id, name, cola, colb;

        ID NAME  COLA       COLB
---------- ----- ---------- ----------
         1 item1 2562       121
         1 item1 2563       122
         1 item1 2564       123
         2 item2            545
         2 item2            6455
         3 item3 1221
         3 item3 1546
         4 item4

8 rows selected.

SQL>
ID | NAME | VALUEA | VALUEB -: | :---- | :----- | :----- 1 | ITEM1 | 2562 | 121 1 | ITEM1 | 2563 | 122 1 | ITEM1 | 2564 | 123 2 | ITEM2 | null | 6455 2 | ITEM2 | null | 545 3 | ITEM3 | 1221 | null 3 | ITEM3 | 1546 | null 4 | ITEM4 | null | null