As the string after orange ends with an ¶, you can chec for4 the position of that character after fruit comes.
as your last entry also contains and ending character
i added LENGTH
additional so that you only need to exchange the category, the rest makes the query then automatically.
Last You can add a TRIM
because there will be some spaces too much
CREATE TABLE n (note varchar2(200))
INSERT INTO n VALUES ('Veg: Lettuce 200 ¶ Fruit: Oranges 200 ¶ Dairy: Milk 300 ¶')
SELECT SUBSTR(N.NOTE
, INSTR(N.NOTE, 'Fruit:')+ LENGTH('Fruit:'),INSTR(N.NOTE,'¶',INSTR(N.NOTE, 'Fruit:')+ LENGTH('Fruit:'), 1) - 1 - INSTR(N.NOTE, 'Fruit:') - LENGTH('Fruit:') ) as Substring FROM n
| SUBSTRING |
| :----------- |
| Oranges 200 |
SELECT INSTR(N.NOTE,'¶',INSTR(N.NOTE, 'Fruit:')+ LENGTH('Fruit:'), 1) - 1 - INSTR(N.NOTE, 'Fruit:') - LENGTH('Fruit:') FROM n
| INSTR(N.NOTE,'¶',INSTR(N.NOTE,'FRUIT:')+LENGTH('FRUIT:'),1)-1-INSTR(N.NOTE,'FRUIT:')-LENGTH('FRUIT:') |
| -----------------------------------------------------------------------------------------------------: |
| 12 |
SELECT SUBSTR(N.NOTE
, INSTR(N.NOTE, 'Dairy:')+ LENGTH('Dairy:'),INSTR(N.NOTE,'¶',INSTR(N.NOTE, 'Dairy:')+ LENGTH('Dairy:'), 1) - 1 - INSTR(N.NOTE, 'Dairy:') - LENGTH('Dairy:') ) as Substring FROM n
| SUBSTRING |
| :-------- |
| Milk 300 |
db<>fiddle here