How to split a comma-separated value to columns

后端 未结 30 4100
刺人心
刺人心 2020-11-21 04:38

I have a table like this

Value   String
-------------------
1       Cleo, Smith

I want to separate the comma delimited string into two colu

30条回答
  •  春和景丽
    2020-11-21 05:09

    Using instring function :)

    select Value, 
           substring(String,1,instr(String," ") -1) Fname,  
           substring(String,instr(String,",") +1) Sname 
    from tablename;
    

    Used two functions,
    1. substring(string, position, length) ==> returns string from positon to length
    2. instr(string,pattern) ==> returns position of pattern.

    If we don’t provide length argument in substring it returns until end of string

提交回复
热议问题