我有一个逗号分隔的字符串"'a','b','c','d'“。
select 'a', 'b', 'c', 'd' from dual;如何将这些选择到一个临时表中,全部放在一列中,而不是按值选择一列?因此,我的select将返回如下输出:
value
a
b
c
d注意:由于输入的是逗号分隔值,因此不允许执行普通的多个选择和联合。
发布于 2020-06-23 14:23:58
我猜您可以这样做,假设您可以限定您的列:
SQL> select val from
( select 'a' as c1, 'b' as c2, 'c' as c3, 'd' as c4 from dual ) unpivot include
nulls ( val for col in ( c1,c2,c3,c4 ) );
V
-
a
b
c
d在这个选项中,你在'a‘,'b’,'c‘'d’中有什么值并不重要,因为基本上取消透视就是将列转置为行。
希望能有所帮助
发布于 2020-06-23 12:59:16
您可以使用分层查询,如下所示:
SQL> with YOUR_DATA as (select q'#'a', 'b', 'c', 'd'#' as str from dual)
2 -- Your query starts from here
3 SELECT TRIM('''' FROM TRIM(REGEXP_SUBSTR(STR,'[^,]+',1,LEVEL))) AS RESULT
4 FROM YOUR_DATA CONNECT BY
5 LEVEL <= 1 + REGEXP_COUNT(STR,',');
RESULT
------------------
a
b
c
d
SQL>发布于 2020-06-23 15:43:50
如果您的版本为12c或更高版本,并且您的数据中没有奇怪的字符,则:
with input(x) as (select q'#'a', 'b', 'c', 'd'#' from dual)
select x_out from input,
json_table(
'['||replace(x, '''', '"')||']', '$[*]'
columns x_out path '$'
);
X_OUT
a
b
c
dhttps://stackoverflow.com/questions/62527437
复制相似问题