[英]MySQL select query to read variable value from file
I have a simple query我有一个简单的查询
select user and class
from student
where school='pass variable from a text file in location /home/user/school.txt'
Text file format:文本文件格式:
Nehru Bhavan
Mahatma Gandhi School
One school name (school name contains space) per row in the text file.文本文件中每行一个学校名称(学校名称包含空格)。
How to do it right.怎么做才对。
I tried我试过了
echo "select user and class from student where school in ($(cat school.txt));" | mysql -u admin -p database_name
It didn't work.它没有用。
You can create a temp table with a definition and can import CSV content into it.您可以创建一个带有定义的临时表,并且可以将 CSV 内容导入其中。
CREATE TABLE #T(Name VARCHAR(200))
BULK INSERT #T
FROM 'F:\Test.txt'
WITH
(
FIELDTERMINATOR = ';',
ROWTERMINATOR = '\n'
)
SELECT * FROM student WHERE ColumnName IN (SELECT Name FROM #T)
Refer this URL, BULK INSERT in MYSQL for MYSQL Version.请参阅 URL,MYSQL 中的BULK INSERT 以获取 MYSQL 版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.