how to insert string data into table as different column data in a row

后端 未结 1 1228
暗喜
暗喜 2021-01-26 03:03

How to insert string data into table in column data of one row. I have string as :

 data= pawan,123,jhs,abc@gmail  

and i want to insert this

相关标签:
1条回答
  • 2021-01-26 03:04

    Assuming you have only four columns separated by comma in string:

     INSERT INTO table_name VALUES(
        REPLACE(SUBSTRING(SUBSTRING_INDEX(data_string, ',',1), LENGTH(SUBSTRING_INDEX(data_string, ',',0)) + 1), ',', ''),
        REPLACE(SUBSTRING(SUBSTRING_INDEX(data_string, ',',2), LENGTH(SUBSTRING_INDEX(data_string, ',',1)) + 1), ',', ''),
        REPLACE(SUBSTRING(SUBSTRING_INDEX(data_string, ',',3), LENGTH(SUBSTRING_INDEX(data_string, ',',2)) + 1), ',', ''),
        REPLACE(SUBSTRING(SUBSTRING_INDEX(data_string, ',',4), LENGTH(SUBSTRING_INDEX(data_string, ',',3)) + 1), ',', '') 
    
    0 讨论(0)
提交回复
热议问题