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:

SUBSTR([input],[start],[length])  
Example 1:
 
select substr('orange.apple',1,(instr('orange.apple','.')) - 1)  
 from  dual  

Output:
first

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

Output:
First         Second
orange           apple

No comments:

Post a Comment

Python contextlib for Timing Python code

If you've ever found yourself needing to measure the execution time of specific portions of your Python code, the `contextlib` module o...