LOADDATALOCALINFILE'd:\A.txt'INTOtablee"> When importing a text file into a MySQL table, how can I upload the changed values ​​of a column instead of writing to the text file?-Mysql Tutorial-php.cn

When importing a text file into a MySQL table, how can I upload the changed values of a column instead of writing to the text file?

WBOY
Release: 2023-09-09 11:21:07
forward
589 people have browsed it

在将文本文件导入 MySQL 表时,如何上传列的更改值,而不是写入文本文件?

Suppose if we want to upload the changed value instead of the value written in the text file, then we need to use user variables with the SET command. It can be understood through the following example -

Example

Suppose we have the following data in "A.txt"-

105,Chum,USA,11000 106,Danny,AUS,12000
Copy after login

But we want to upload after adding 500 while importing salary value without changing the salary value in the text file, then it can be done by using user variables and with the help of the following query using the SET option -

mysql> LOAD DATA LOCAL INFILE 'd:\A.txt' INTO table employee11_tbl FIELDS TERMINATED BY ',' (id,name,country,@salary) SET salary = @salary + 500; Query OK, 2 rows affected (0.21 sec) Records: 2 Deleted: 0 Skipped: 0 Warnings: 0 mysql> Select * from employee11_tbl; +------+----------------+----------+--------+ | Id | Name | Country | Salary | +------+----------------+----------+--------+ | 105 | Chum | USA | 11500 | | 106 | Danny | AUS | 12500 | +------+----------------+----------+--------+ 2 rows in set (0.00 sec)
Copy after login

As can be seen from the above result set, MySQL is in salary Add 500 to the value and then upload the data to the table.

The above is the detailed content of When importing a text file into a MySQL table, how can I upload the changed values of a column instead of writing to the text file?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!