PL/SQL (MOSC)

MOSC Banner

Data seperation between commas

edited Sep 14, 2012 3:58AM in PL/SQL (MOSC) 4 commentsAnswered
Hi,

Suppose i have comma seperated input e.g. 'ABC,DEF,MNO'

Now i want to retrieve the data before the first comma, between first and second comma and after the second comma.

I have designed the below logic:

SELECT SUBSTR ('ABC,DEF,MNO',1,(INSTR ('ABC,DEF,MNO',',',1,1)-1)) FROM DUAL; --Before First Comma

SELECT SUBSTR ('ABC,DEF,MNO',(INSTR ('ABC,DEF,MNO',',',1,1) + 1), (INSTR ('ABC,DEF,MNO',',',1,2) - INSTR ('ABC,DEF,MNO',',',1,1)) - 1) FROM DUAL;  --Between first and second comma

SELECT SUBSTR ('ABC,DEF,MNO',INSTR ('ABC,DEF,MNO',',',1,2)+1)  FROM DUAL;  --After the second comma

Howdy, Stranger!

Log In

To view full details, sign in to My Oracle Support Community.

Register

Don't have a My Oracle Support Community account? Click here to get started.

Category Leaderboard

Top contributors this month

New to My Oracle Support Community? Visit our Welcome Center

MOSC Help Center