Wednesday, June 18, 2014

Oracle: Split a String Based on Delimiter

We can split a string based on Delimiter using a combination of  INSTR and SUBSTR functions:

INSTR Returns the position of a String within a String. For more information see Oracle instr function
SUBSTR Returns a substring. For more information see Oracle substring
Syntax of SUBSTR:

Example 1:
select substr('',1,(instr('','.')) - 1)  
 from  dual  


Example 2:
select substr('',1,(instr(','.')) - 1) as First,  
        substr('', (instr('','.')) + 1) as Second  
 from  dual 

First         Second
orange           apple

No comments:

Post a Comment