好吧,这很接近你的实现偏差的边缘,虽然记得forall是一个批量绑定操作,而不是一个真正的循环,但你看过dbms_utility.comma_to_table函数?
它是一个优化的内部oracle解析函数,虽然有一些限制,你可以在这里阅读:http://www.techiegyan.com/2009/02/17/oracle-breaking-comma-separated-string-using-dbms_utilitycomma_to_table/
您需要使用replace()使其以逗号分隔,如果您已经解析了以数字,特殊字符,逗号等开头的字段,则还需要双引号括起来。
但是如果您的数据允许 - 它确保您的代码看起来更清晰(并且可能也会更快地运行)
declare
myvar varchar2(32000) := 'tcd1~#testmsg1^~tcd2~#testmsg2^~tcd3~#testmsg3';
mycnt binary_integer;
myresults sys.dbms_utility.lname_array;
begin
sys.dbms_utility.comma_to_table('"'||replace(myvar,'^~','","')||'"', mycnt, myresults );
delete from t;
forall ix in myresults.first..myresults.last
insert into tvalues (myresults(ix));
commit;
end;
|