Home » SQL & PL/SQL » SQL & PL/SQL » Converting a string to comma seperated value
Converting a string to comma seperated value [message #363161] Fri, 05 December 2008 04:46 Go to next message
anukriti
Messages: 3
Registered: December 2008
Location: India
Junior Member
Hi

I have a requirment like i want to convert a string eg. '1234' to 1,2,3,4.

Help required...
Thanks in advance
Re: Converting a string to comma seperated value [message #363163 is a reply to message #363161] Fri, 05 December 2008 04:49 Go to previous messageGo to next message
ravi214u
Messages: 153
Registered: February 2008
Location: CANADA
Senior Member
please provide test cases eg table script,insert script etc
Re: Converting a string to comma seperated value [message #363164 is a reply to message #363163] Fri, 05 December 2008 04:51 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
...As well as your Oracle version (4 decimals), the solution is version dependent.

Regards
Michel

[Updated on: Fri, 05 December 2008 04:51]

Report message to a moderator

Re: Converting a string to comma seperated value [message #363166 is a reply to message #363163] Fri, 05 December 2008 04:58 Go to previous messageGo to next message
anukriti
Messages: 3
Registered: December 2008
Location: India
Junior Member
Hi
The version is oracle 10g.
SQl developer v1.0.14.22

One of the column in the table has the data like this i.e 1234 and i want to update this string as 1,2,3,4
so that it can be split into single digits.
without any delimiter i am not able to split this string into individual digits.Thats why i want to convert the string into comma seperated string.

Thanks
Re: Converting a string to comma seperated value [message #363167 is a reply to message #363161] Fri, 05 December 2008 05:01 Go to previous messageGo to next message
ravi214u
Messages: 153
Registered: February 2008
Location: CANADA
Senior Member
you have to read substr function in oracle that will solve your problem. e.g
select substr(col1,1,1)||','||substr(col1,2,1) from tab
Re: Converting a string to comma seperated value [message #363168 is a reply to message #363161] Fri, 05 December 2008 05:07 Go to previous messageGo to next message
anukriti
Messages: 3
Registered: December 2008
Location: India
Junior Member
Thanks so much. Smile
Re: Converting a string to comma seperated value [message #363172 is a reply to message #363168] Fri, 05 December 2008 05:15 Go to previous messageGo to next message
mamalik
Messages: 266
Registered: November 2008
Location: Pakistan
Senior Member

IF we don't know that length of string and there is bulk data then how above query will do?
Re: Converting a string to comma seperated value [message #363174 is a reply to message #363168] Fri, 05 December 2008 05:17 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
SQL> select rtrim(regexp_replace('1234','(.)','\1,'),',') from dual;
RTRIM(R
-------
1,2,3,4

1 row selected.

Regards
Michel
Re: Converting a string to comma seperated value [message #363180 is a reply to message #363174] Fri, 05 December 2008 05:23 Go to previous messageGo to next message
mamalik
Messages: 266
Registered: November 2008
Location: Pakistan
Senior Member

Yes. this is solution.

Thanks a lot michel Uncle.


Regards.
Asif.
Re: Converting a string to comma seperated value [message #363419 is a reply to message #363180] Sun, 07 December 2008 06:32 Go to previous messageGo to next message
spacters
Messages: 1
Registered: December 2008
Location: United Kingdom
Junior Member
mamalik wrote on Fri, 05 December 2008 11:23

Thanks a lot michel Uncle.



never knew Michel had a nephew in Pakistan. Wink

Re: Converting a string to comma seperated value [message #363462 is a reply to message #363419] Sun, 07 December 2008 08:42 Go to previous message
Littlefoot
Messages: 20891
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
spacters
never knew Michel had a nephew in Pakistan. Wink

You, ignoramus! ./fa/1693/0/

Just kidding, I didn't mean to offend you. The fact is, I was also confused by the "uncle" thing not that long ago. If you are curious what it means, and - perhaps - learn even something more than just Oracle - visit this thread.
Previous Topic: select rows
Next Topic: Return array values to refcursor
Goto Forum:
  


Current Time: Sun Dec 04 22:33:21 CST 2016

Total time taken to generate the page: 0.08871 seconds