Home » SQL & PL/SQL » SQL & PL/SQL » converting comma seperated CHAR to Number
converting comma seperated CHAR to Number [message #20924] Tue, 02 July 2002 01:16 Go to next message
balagopal
Messages: 3
Registered: April 2002
Junior Member
hello
I have a column with VARCHAR type and data like 1,2,3,4,5.
I want to seperate this one to numbers as
1
2
3
4
5

Any one can help me

Thanking you
Balagopal R
Re: converting comma seperated CHAR to Number [message #20939 is a reply to message #20924] Tue, 02 July 2002 07:33 Go to previous messageGo to next message
vipin
Messages: 40
Registered: May 2002
Member
Hi,

select replace('1,2,3,4', ',') from dual;

vipin
Re: converting comma seperated CHAR to Number [message #20943 is a reply to message #20924] Tue, 02 July 2002 09:13 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
SQL> select * from test;

        ID VALUE
---------- ------------------------------
         1 1,2,3,4,5,6,
         2 9,8,7,6,5,4,3

SQL> get rip
  1  create or replace procedure
  2  rip (n in number)
  3  as
  4  retval varchar2(30);
  5  a number;
  6  begin
  7  select value into retval from test where id=n;
  8  retval:=replace(retval,',');
  9  for mag in 1..length(retval) loop
 10     a:=substr(retval,mag,1);
 11     dbms_output.put_line(a);
 12  end loop;
 13* end;
SQL> /

Procedure created.

SQL> exec rip(1);
1
2
3
4
5
6

PL/SQL procedure successfully completed.

SQL> exec rip(2);
9
8
7
6
5
4
3

PL/SQL procedure successfully completed.

SQL> 
Re: converting comma seperated CHAR to Number [message #20981 is a reply to message #20924] Thu, 04 July 2002 04:34 Go to previous message
Rohit Mehrotra
Messages: 9
Registered: July 2002
Junior Member
Hello Balgopal,

I think that the most convenient way would be.

select replace('1,2,3,4,5,6',',',chr(10)) from dual;

Regards
Rohit
Previous Topic: invalid sql statement
Next Topic: Urgent: Finding the top 10 NET- SALES- FIGURES
Goto Forum:
  


Current Time: Fri Apr 26 14:22:12 CDT 2024