0

I have a column with data like

I~A~G~S

How could i separate them using select query.

Output : Updated

  Rows       Column(Data)
  First      I
  Second     A
  Third      G
  Fourth     S
Java_Alert
  • 1,159
  • 6
  • 24
  • 50
  • 1
    is this what you are expecting? select replace('I~A~G~S','~',' ') as x from dual; you can use replace function in oracle. you replace the ~ with with space. – Shann Nov 27 '13 at 05:45
  • possible duplicate http://stackoverflow.com/questions/18770581/oracle-split-multiple-comma-separated-values-in-oracle-table-to-multiple-rows – Noel Nov 27 '13 at 06:01

2 Answers2

2
declare @s varchar(10)
set @s='I~A~G~S'

select replace(@s,'~',' ')

for updated question

create table #vij11 (s varchar(100))

insert into #vij11(s) values ('I~A~G~S')
SELECT   
     Split.a.value('.', 'VARCHAR(100)') AS String  
 FROM  (SELECT [s],  
         CAST ('<M>' + REPLACE([s], '~', '</M><M>') + '</M>' AS XML) AS String  
     FROM  #vij11) AS A CROSS APPLY String.nodes ('/M') AS Split(a); 

fiddle demo

vhadalgi
  • 7,027
  • 6
  • 38
  • 67
2

if you are using oracle database then it should be as follows:

select replace('I~A~G~S','~',' ') as x from dual;

select replace(<fieldname>,'~',' ') from <tablename>

as for the question of splitting the string in different rows please check the below query.

SELECT trim(regexp_substr(replace('I~A~G~S','~',','), '[^,]+', 1, LEVEL)) str_2_tab
  FROM dual
  CONNECT BY LEVEL <= regexp_count(replace('I~A~G~S','~',','), ',')+1;
Shann
  • 660
  • 1
  • 6
  • 19