Click here to Skip to main content
14,880,672 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to split a string on basis of pipe through sql query with using any user defined function or procedure. use only oracle predefined functions.

eg. - String = " abc | sgdf | xyz "

result s1 = "abc"
s2 = "sgdf"
s3 = "xyz"
Posted

1 solution

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!
   
Comments
punkiv 16-Jun-12 9:22am
   
its not a homework. i wrk in MNC. its a part of our coding. i m doing it, bt it is being stuck while fetching 3rd string in the same sql query.....
its in between java code line so i can't use procedure or ny user defined functions, bcoz it will affect other part of code....
OriginalGriff 16-Jun-12 9:29am
   
Ah!
I don't know if this will help, but it might. It's MS SQL for a comma separated list as an IN cluase - it works by splitting the string into a temporary table. It may be simple to translate to Oracle.

DECLARE @INSTR as VARCHAR(MAX)
SET @INSTR = '2,3,177,'
DECLARE @SEPERATOR as VARCHAR(1)
DECLARE @SP INT
DECLARE @VALUE VARCHAR(1000)
SET @SEPERATOR = ','
CREATE TABLE #tempTab (id int not null)
WHILE PATINDEX('%' + @SEPERATOR + '%', @INSTR ) <> 0
BEGIN
SELECT @SP = PATINDEX('%' + @SEPERATOR + '%',@INSTR)
SELECT @VALUE = LEFT(@INSTR , @SP - 1)
SELECT @INSTR = STUFF(@INSTR, 1, @SP, '')
INSERT INTO #tempTab (id) VALUES (@VALUE)
END
SELECT * FROM myTable WHERE id IN (SELECT id FROM #tempTab)
DROP TABLE #tempTab
punkiv 16-Jun-12 9:38am
   
thnxx buddy.... i try this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900