如何将字符串数据作为行中的不同列数据插入表中 [英] how to insert string data into table as different column data in a row
本文介绍了如何将字符串数据作为行中的不同列数据插入表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在一行的列数据中将字符串数据插入表中.我的字符串为:
How to insert string data into table in column data of one row. I have string as :
data= pawan,123,jhs,abc@gmail
我想将此插入为
insert into table values(pawan,123,jhs,abc@gmail)
推荐答案
假定字符串中只有四列用逗号隔开:
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), ',', '')
这篇关于如何将字符串数据作为行中的不同列数据插入表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文