如何在存储过程中拆分逗号分隔的字符串?

如何在存储过程中拆分逗号分隔的字符串?,第1张

如何在存储过程中拆分逗号分隔的字符串

这里有一个示例如何分割字符串并将子字符串写入表中:

create procedure SPLIT_STRING (  AINPUT varchar(8192))asdeclare variable LASTPOS integer;declare variable NEXTPOS integer;declare variable TEMPSTR varchar(8192);begin  AINPUT = :AINPUT || ',';  LASTPOS = 1;  NEXTPOS = position(',', :AINPUT, LASTPOS);  while (:NEXTPOS > 1) do  begin    TEMPSTR = substring(:AINPUT from :LASTPOS for :NEXTPOS - :LASTPOS);    insert into new_table("VALUE") values(:TEMPSTR);    LASTPOS = :NEXTPOS + 1;    NEXTPOS = position(',', :AINPUT, LASTPOS);  end  suspend;end


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5011243.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-15
下一篇 2022-11-14

发表评论

登录后才能评论

评论列表(0条)

保存