MySQL为什么可以将变量添加到OUTFILE预处理语句而不是INFILE?

时间:2012-03-15 17:16:24

标签: mysql prepared-statement

示例OUT文件(工作)

DELIMITER ##
CREATE PROCEDURE exportFile(IN inFilePath varchar(100))
BEGIN

DECLARE filename VARCHAR(255);

SET filename = CONCAT(
inFilePath,
NOW(),
'.csv');

SET @outfilestmt = concat(
'SELECT * INTO OUTFILE ',
"'", filename,"'",
'FIELDS TERMINATED BY \',\'',
' FROM RESULTS');

PREPARE stmt FROM @outfilestmt;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

END ##
DELIMITER ;

示例INFILE(不工作)

DELIMITER ##
CREATE PROCEDURE loadFile1(IN inFilePath varchar(100))
BEGIN

DECLARE filename VARCHAR(255);

SET filename = inFilePath;

SET @loadFilestmt = CONCAT(
'LOAD DATA INFILE ',
"'", filename,"'",
' INTO TABLE INPUT'
);


PREPARE stmt FROM @loadFilestmt;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

END ##
DELIMITER ;

这会产生相同的行为吗?

0 个答案:

没有答案