phpMyAdmin SQL Error Unrecognized keyword near FIELDS

时光总嘲笑我的痴心妄想 提交于 2020-01-24 00:23:18

问题


I'm trying to execute this MySQL to import some data into a csv file.

SELECT *
FROM purchase WHERE purchase.PO_DATE >= '1-1-2016'
INTO OUTFILE "D:\\Reports\\Jan.csv"
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'

But I'm receiving the output

Static analysis:

11 errors were found during analysis.

    Unrecognized keyword. (near "FIELDS" at position 99)
    Unrecognized keyword. (near "TERMINATED" at position 106)
    Unrecognized keyword. (near "BY" at position 117)
    Unexpected token. (near "','" at position 120)
    Unrecognized keyword. (near "ENCLOSED" at position 125)
    Unrecognized keyword. (near "BY" at position 134)
    Unexpected token. (near "'"'" at position 137)
    Unrecognized keyword. (near "LINES" at position 142)
    Unrecognized keyword. (near "TERMINATED" at position 148)
    Unrecognized keyword. (near "BY" at position 159)
    Unexpected token. (near "'\n'" at position 162)

SQL query: Documentation

SELECT * FROM purchase WHERE purchase.PO_DATE >= '1-1-2016' INTO OUTFILE "D:\\Reports\\Jan.csv" FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' 

Anyone knows how to solve this issue ?


回答1:


The information regarding your output file should be specified between SELECT and FROM clauses:

SELECT *
INTO OUTFILE "D:\Reports\Jan.csv"
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'    
FROM purchase 
WHERE purchase.PO_DATE >= '1-1-2016'

MySQL 5.7 Reference Manual | LOAD DATA INFILE Syntax




回答2:


The from clause is in wrong position should be

SELECT * 
INTO OUTFILE "D:\Reports\Jan.csv"
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM purchase 
WHERE purchase.PO_DATE >= '1-1-2016'


来源:https://stackoverflow.com/questions/40525968/phpmyadmin-sql-error-unrecognized-keyword-near-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!