sql - Firebird Database Split String on Field -
currently working firebird 1.5 database , attempting pull data in correct format natively sql.
consider following database:
id | full name 1 jon doe 2 sarah lee
what trying achieve simple split on full name field (space) within query.
id | first name | last name 1 jon doe 2 sarah lee
the issue faced firebird position() introduced in v2.0. there known workaround split on space has come across?
much appreciate assistance!
for firebird 1.5 solution find udf either combines both functions, or provides position (i don't use udfs, not sure if 1 exists). if none available might have write one.
the other solution write stored procedure functionality, see example: position of substring function in sp
create procedure pos (substr varchar(100), str varchar(100)) returns (pos integer) declare variable substr2 varchar(201); /* 1 + substr-lenght + str-length */ declare variable tmp varchar(100); begin if (substr null or str null) begin pos = null; exit; end substr2 = substr || '%'; tmp = ''; pos = 1; while (str not substr2 , str not tmp) begin substr2 = '_' || substr2; tmp = tmp || '_'; pos = pos + 1; end if (str tmp) pos = 0; end
this example (taken link) can extended use substring
split on space.
for search on single character space simpler solution can devised above stored procedure. exact needs might need write selectable stored procedure purpose.
however, upgrading database firebird 2.5 give more powerful internal functions simplify query (and life)!
Comments
Post a Comment