Firebird: Create Array from CSV String

CREATE OR ALTER PROCEDURE SPLIT(ASTRLIST VARCHAR(32000)) returns ( STR VARCHAR(255) ) as declare variable StrList varchar(32000); declare variable CommaPos integer; declare variable StrVal varchar(10); begin StrList = AStrList || ''; CommaPos = Position(',', StrList); while (CommaPos > 0) do begin StrVal = Trim(SubString(StrList from 1 for CommaPos - 1)); if (Char_Length(StrVal) > 0) then begin STR = StrVal; suspend; end if (Char_Length(StrList) > CommaPos) then StrList = SubString(StrList from CommaPos + 1); else StrList = ''; CommaPos = Position(',', StrList); end StrList = Trim(StrList); if (Char_Length(StrList) > 0) then begin begin STR = StrList; suspend; end end end; /* use: SELECT * FROM CITY WHERE COD_CITY IN (SELECT STR FROM Split('ABC, DEF, GH, IJK, LM, NOP')) */

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.