0

Is it real to get fragment of text in field if i don't know where it's end? I have text with fragment like 'type work: blablabla' and need to get it. Start point of fragment - 'type work:'

But length of it is not constant and after this fragment may be different other text - not constant delimiter like ; or , or something else which can give me endpoint for my fragment.

Examples:

type work: blablabla

start: 01-01-2019

need to get

type work: blablabla

OR

type work: blablabla

blablablabla

sendornot:yes

need to get

type work: blablabla

blablablabla

4

1 回答 1

1

I am not 100% sure but the following query might be what you need:

-- Sample data:
WITH dat(text) AS (SELECT 'type work: blablabla
start: 01-01-2019' FROM dual UNION ALL 
SELECT 'type work: blablabla
blablablabla
sendornot:yes' FROM dual)
-- Query:
SELECT REGEXP_REPLACE(
          -- Make sure text starts with 'type work:':
          CASE WHEN INSTR(text, 'type work:') > 0 THEN SUBSTR(text, INSTR(text, 'type work:')) END
     , '(type work:[^:]*)'||CHR(10)||'[^:'||CHR(10)||']*:.*$','\1'
     ,1,1,'n') FROM dat

This query searches for the first : after type work and trades all of the line before that as key and then gets you the text from type work till that key.

If you have a list of the keys you might want to check for them instead of [^:'||CHR(10)||']:

SELECT REGEXP_REPLACE(
          CASE WHEN INSTR(text, 'type work:') > 0 THEN SUBSTR(text, INSTR(text, 'type work:')) END
     , '(type work:[^:]*)'||CHR(10)||'(start|sendornot):.*$','\1'
     ,1,1,'n') FROM dat
于 2019-07-03T08:28:49.660 回答