使用预定义的系统函数将分隔的字符串(或列)转换为 Oracle 中的行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5825356/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 23:31:59  来源:igfitidea点击:

Converting a delimited string (or column) to rows in Oracle using a pre-defined system function

sqloracleplsql

提问by Pranav Shah

A few years ago in Oracle 10 or 9 I used a function which was something like "DBMS_COL_2_VAL" (This is definitely not the right function).

几年前在 Oracle 10 或 9 中,我使用了一个类似于“DBMS_COL_2_VAL”的函数(这绝对不是正确的函数)。

The purpose of this built in function is to convert the provided string to rows based on a specified delimiter. I know that there are multiple ways of converting a delimited string to rows, but what I looking for is this specific function.

这个内置函数的目的是根据指定的分隔符将提供的字符串转换为行。我知道有多种方法可以将分隔的字符串转换为行,但我要寻找的是这个特定的函数。

If you can help that would be great.

如果你能帮忙那就太好了。

Please do not provide any solutions with CONNECT, CASE, or REGEX.

请不要使用 CONNECT、CASE 或 REGEX 提供任何解决方案。

Thanks

谢谢

回答by Pranav Shah

The function I was trying to find was SYS.DBMS_DEBUG_VC2COLL.

我试图找到的功能是SYS.DBMS_DEBUG_VC2COLL.

Technically speaking it does not convert a delimited string to column, but it converts a list of comma separated values to rows. I realized that after I found an old post.

从技术上讲,它不会将分隔字符串转换为列,而是将逗号分隔值列表转换为行。我发现了一个旧帖子后才意识到。

Sample code and results:

示例代码和结果:

with test as  (
    select column_value AS c1  
      from table( SYS.DBMS_DEBUG_VC2COLL( 'a','b','c' ) )  
   )  
 select * from test;

Result:

结果:

c1   
__  
a    
b    
c    

回答by tbone

Maybe thinking of this?

也许想到这个?

DBMS_UTILITY.COMMA_TO_TABLE ( 
   list   IN  VARCHAR2,
   tablen OUT BINARY_INTEGER,
   tab    OUT uncl_array); 

DBMS_UTILITY.COMMA_TO_TABLE ( 
   list   IN  VARCHAR2,
   tablen OUT BINARY_INTEGER,
   tab    OUT lname_array);