我有返回结果的 oracle 查询
Column1 Column2 Column3
1 -A,D -DEF
2 -B,C -JHI
我怎样才能得到这样的结果
Column1 Column2 Column3 Column4
1 -A -D -DEF
利用SUBSTRING
函数接收部分字符串和INSTR
查找逗号位置的函数。
select
column1,
substring(column2,1,instr(column2,',')-1) as column2a,
substring(column2,instr(column2,',')+1) as column2b,
column3
from mytable
请试试:
select
Column1,
substr(Column2 , 1, instr(Column2, ',')-1) as Column2,
substr(Column2 , instr(Column2, ',')+1) as Column3,
Column3 as Column4
from(
select 1 as Column1, '-A,D' as Column2, '-DEF' as Column3 from dual
)x