How to match 3rd repeated keyword in json string with my keyword in oracle sql?

23 Views Asked by At

I'm able to match the first repeated keyword in json string using INSTR(json_string,'keyword') but trying to figure out how to match 3rd repeated keyword occuring in that json document?

Appreciate if someone can give me a clue here?

Thanks, N

1

There are 1 best solutions below

1
VvdL On

You can pass the occurence to the INSTR function:

INSTR(string , substring [, start_position [, occurrence]])

Take a look at this example:

WITH EXAMPLE AS (
  SELECT 'abcabcabc' AS TEST_STRING FROM DUAL
)
SELECT 
  INSTR(TEST_STRING, 'a', 1, 1) AS FIRST_ENCOUNTER,
  INSTR(TEST_STRING, 'a', 1, 2) AS SECOND_ENCOUNTER,
  INSTR(TEST_STRING, 'a', 1, 3) AS THIRD_ENCOUNTER
FROM EXAMPLE
FIRST_ENCOUNTER SECOND_ENCOUNTER THIRD_ENCOUNTER
1 4 7

dbfiddle