0

I have worked with MySQL and new to oracle. In MySQL we have a function SUBSTRING_INDEX(), I want to replace it in oracle, Any help plz

 SQL>select SUBSTRING_INDEX('JD;EQ;0001', ';', -1) from dual;

Result:

0001

I want a same result in oracle. Is there any function in oracle that return the same result in oracle?

I have tried but no expected result.

  SELECT substr('CLUBORACLE',3,2) RES FROM dual; 
user272735
  • 10,473
  • 9
  • 65
  • 96
Atul Rai
  • 332
  • 1
  • 10
  • 25

2 Answers2

2
SELECT SUBSTR('JD;EQ;0001', INSTR('JD;EQ;0001', ';', -1) + 1) FROM dual

In the query above, INSTR('JD;EQ;0001', ';', -1) would return 6, which is the position of the last semicolon in the expression. You want to take the substring from the position after the last semicolon until the end of the string.

Look here for a good SO question about Oracle's INSTR.

Community
  • 1
  • 1
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
0

You can also use regex: SELECT REGEXP_SUBSTR('JD;EQ;0001', '[^;]+', 1, your_occurance_number) FROM dual; but SUBSTR+INSTR should be faster.

nilsman
  • 346
  • 1
  • 9