2016-06-13 54 views
0

我试图创建一个varChar表来格式化一个字符串 (基本上我试图做一个骗子split()函数)。动态创建varchar表

所以,如果我做

type tableOfStrings is table of varchar2(50); 
vWords tableOfStrings := tableOfStrings ('a','few','words'); 
dbms_output.put_line(vwords.count); -- 3 

但如果我尝试

type tableOfStrings is table of varchar2(50); 
vTemp varchar(300) := '''a'',''few'',''words'''; 
vWords tableOfStrings := tableOfStrings (vTemp); 
dbms_output.put_line(vwords.count); -- 1 (it's a single string 'a','few','words') 

我想一个字符串传递给函数,已添加到表中的每个字。

喜欢的东西

FUNCTION FLABELFORMAT(pMyString in varchar2) return varchar2 

type tableOfStrings is table of varchar2(50); 
vWords tableOfStrings := tableOfStrings (pMyString); 

for i in 1 .. vWords.count loop 
    {do some cool stuff} 
end loop; 
END FLABELFORMAT 

我怎样才能做到使用类似vWords tableOfStrings := tableOfStrings (pMyString);,并把它添加的每个值表?

TIA

回答

0

基于this answer,试试这个:

SELECT regexp_substr('a,few,words', '[^,]+', 1, LEVEL) 
FROM dual 
CONNECT BY regexp_substr('a,few,words', '[^,]+', 1, LEVEL) IS NOT NULL; 
+0

不作为 “简单” 为我所期待的,但它的工作原理。谢谢。 – Travis