sql – 如何在存储过程中拆分逗号分隔的字符串?
发布时间:2020-12-12 16:27:26 所属栏目:MsSql教程 来源:网络整理
导读:如何将逗号分隔的字符串拆分为存储过程中的字符串并将它们插入表字段? 使用Firebird 2.5 解决方法 这里有一个示例如何拆分字符串并将子字符串写入表中: create procedure SPLIT_STRING ( AINPUT varchar(8192))asdeclare variable LASTPOS integer;declare
如何将逗号分隔的字符串拆分为存储过程中的字符串并将它们插入表字段?
使用Firebird 2.5 解决方法这里有一个示例如何拆分字符串并将子字符串写入表中:create procedure SPLIT_STRING ( AINPUT varchar(8192)) as declare 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(',LASTPOS); end suspend; end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |