在MySQL中,我可以運行:如何在Ruby/Rails中使用load命令和MySQL?
LOAD DATA LOCAL INFILE "/home/pt/test/bal.csv" INTO TABLE bal FIELDS
TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '"' IGNORE 1
LINES;
然而,在我的Ruby程序:
str="LOAD DATA LOCAL INFILE "/home/pt/test/bal.csv" INTO TABLE bal
FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '"'
IGNORE 1 LINES;"
puts str
dbh.query(str)
輸出是:
LOAD DATA LOCAL INFILE "/home/pt/test/bal.csv" INTO TABLE bal FIELDS
TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '"' IGNORE 1
LINES;
/home/pt/test/ptb.rb:34:in `query': Field separator argument is not what
is expected; check the manual (Mysql::Error)
from /home/pt/test/ptb.rb:34:in `<main>'
有什麼不對的代碼?
海峽= 「LOAD DATA LOCAL INFILE \」/家/ PT /測試/ bal.csv \」 INTO TABLE BAL FIELDS '''''''''''''''''''' IGNORE 1 LINES;「 試試這個會工作.. :) – 2015-08-24 11:55:57