我正在尝试将数据导入MySQL表,其值未在输入文件中定义。我有这个php字符串连接查询:
"LOAD DATA LOCAL INFILE '".@mysql_escape_string($this->file_name).
"' IGNORE INTO TABLE `".$this->table_name.
"` FIELDS TERMINATED BY '".@mysql_escape_string($this->field_separate_char).
"' OPTIONALLY ENCLOSED BY '".@mysql_escape_string($this->field_enclose_char).
"' ESCAPED BY '".@mysql_escape_string($this->field_escape_char).
"' LINES TERMINATED BY '". $this->line_separate_char .
"' ".
($this->use_csv_header ? " IGNORE 1 LINES " : "")
我可以在此加载语句中设置帐户ID吗?
答案 0 :(得分:2)
SET
子句可用于提供不是从输入文件派生的值。以下语句将column3
设置为当前日期和时间:LOAD DATA INFILE 'file.txt' INTO TABLE t1 (column1, column2) SET column3 = CURRENT_TIMESTAMP;
答案 1 :(得分:1)
您可以在加载数据中调用函数和SQL语句,如下所示:
load data local infile '/tmp/foo.txt' into table foo
fields terminated by '\t' lines terminated by '\n'
(@col1, @col2)
set myid=@col1,
username=CONCAT(@col2, 'abc', 'xyz');