Separar los valores de la columna de datos

I have a column with data like

I~A~G~S

How could i separate them using select query.

salida: Actualizado

  Rows       Column(Data)
  First      I
  Second     A
  Third      G
  Fourth     S

preguntado el 27 de noviembre de 13 a las 05:11

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. -

2 Respuestas

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;

respondido 27 nov., 13:06

you are welcome. if the answer has answered all you questions, please mark as answered. thnxs - Shann

can we get I~A~G~S into different- different variables like income = I, Age=A, Gender=G and State=S; - Java_Alerta

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

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

es 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); 

demo de violín

respondido 27 nov., 13:06

Could i get the same as values in different-2 row. like I in first row then A in 2nd row. - Java_Alerta

what you mean ? like I A G S *2 - vhadalgi

FIRST ROW I, SECOND ROW A , THIRD ROW G , FOURTH ROW S - Java_Alerta

@Java_Alert i have updated the answer above for splitting the string in different rows. please check - Shann

can we get I~A~G~S into different- different variables like income = I, Age=A, Gender=G and State=S; - Java_Alerta

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.