i trying return first line of text text box in sql query (oracle 11). content of text box looks this:
x withdrawn explanation.
i want return top line, i.e. x withdrawn. i'm not sure if can specify @ first line only, or return text before carriage return - either work.
i think need use regexp_substr i'm not quite sure on syntax. have tried:
regexp_substr(table.text,'^.*$')
but didn't work, assistance appreciated!
edit: solution used:
select regexp_substr(table.text, '[^,]+['||chr(10)||']') tab
edit: noticed getting mixture of line feed , carriage returns returned in answer, i've use following solution return text , no additional characters.
select replace(replace(regexp_substr(table.text, '[^,]+['||chr(10)||']'),chr(10),''),chr(13),'') tab
edit: following @ben's answer, i've amended solution following:
select initcap(replace(regexp_substr(table.text, '.*$', 1, 1, 'm'),chr(13),'')) tab
parado's regular expression matches that's not comma multiple times followed carriage return. means won't work line-feed or if there's comma in text.
oracle supports multi-line expressions using m
match parameter. when using mode, $
matches end of each line end of string. can use expression massively to:
regexp_substr(str, '.*$', 1, 1, 'm')
that match first occurrence (the first line) of string matches anything, followed end of string, counting first character.
as example:
with strings ( select 'hi hi again' str dual union select 'bye , again' dual ) select regexp_substr(str, '.*$', 1, 1, 'm') strings
Comments
Post a Comment