我希望能够在 Oracle 9i 中拆分 csv 字符串
I want to be able to split csv strings in Oracle 9i
我已阅读以下文章http://www.oappssurd.com/2009/03/string-split-in-oracle.html
但我不明白如何进行这项工作.这是我的一些相关问题
But I didn't understand how to make this work. Here are some of my questions pertaining to it
这是一个用于 Oracle 的字符串标记器,它比那个页面更简单一些,但不知道它是否一样快:
Here's a string tokenizer for Oracle that's a little more straightforward than that page, but no idea if it's as fast:
create or replace function splitter_count(str in varchar2, delim in char) return int as
val int;
begin
val := length(replace(str, delim, delim || ' '));
return val - length(str);
end;
create type token_list is varray(100) of varchar2(200);
CREATE or replace function tokenize (str varchar2, delim char) return token_list as
ret token_list;
target int;
i int;
this_delim int;
last_delim int;
BEGIN
ret := token_list();
i := 1;
last_delim := 0;
target := splitter_count(str, delim);
while i <= target
loop
ret.extend();
this_delim := instr(str, delim, 1, i);
ret(i):= substr(str, last_delim + 1, this_delim - last_delim -1);
i := i + 1;
last_delim := this_delim;
end loop;
ret.extend();
ret(i):= substr(str, last_delim + 1);
return ret;
end;
你可以这样使用它:
select tokenize('hi you person', ' ') from dual;
VARCHAR(hi,you,person)
这篇关于如何在 oracle 9i 中最好地拆分 csv 字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!