使用过程和事件写入 OUTFILE - MySQL
Write to OUTFILE with Procedure and Event - MySQL
有人可以帮我解决下面的问题吗?
DELIMITER $$
CREATE DEFINER=`user1`@`localhost` PROCEDURE `Local_sp_ExtractPOI`()
BEGIN
SET SESSION group_concat_max_len = 1000000;
SET @OutputPath := 'C:/stuff/folder/nextfolder/files/POIExtract/';
SET @filename := date_format(now(), '%d%m%y_%H%m%s.txt');
SET @fullOutputPath := CONCAT(@OutputPath, @filename);
set @q1 := concat("SELECT group_concat(`NHS` separator '') INTO OUTFILE ",@fullOutputPath,
" FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '\'
FROM person WHERE `active` = -1 AND `NHS` IS NOT NULL AND `NHS` REGEXP [0123456789]{10}
ORDER BY 1");
prepare s1 from @q1;
execute s1; deallocate prepare s1;
END$$
DELIMITER ;
我知道我可以写入路径,因为这有效:
SELECT oid INTO OUTFILE "C:/stuff/folder/nextfolder/files/POIExtract/varmydata.txt"
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\'
LINES TERMINATED BY '\n'
FROM person limit 1;
但是,当我包装一个过程并使用变量和 concat()
时,它不会创建输出文件。
我尝试了多种格式化文件路径的方法,但还是不行。当我尝试调用它时,出现错误代码:1064。您的 SQL 语法有误...
我不理解这种使用 REGEXP
的方式吗?
我打算使用预定事件调用它。
蒂亚,
麦克
秋名是对的。修改为:
set @q1 := concat("SELECT group_concat(`NHS` separator '') INTO OUTFILE ", " '", @fullOutputPath, "' ", " FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\' FROM p_person WHERE `active` = -1 AND `NHS` IS NOT NULL AND `NHS` REGEXP", " '[0123456789]{10}' ", "ORDER BY 1");
有人可以帮我解决下面的问题吗?
DELIMITER $$
CREATE DEFINER=`user1`@`localhost` PROCEDURE `Local_sp_ExtractPOI`()
BEGIN
SET SESSION group_concat_max_len = 1000000;
SET @OutputPath := 'C:/stuff/folder/nextfolder/files/POIExtract/';
SET @filename := date_format(now(), '%d%m%y_%H%m%s.txt');
SET @fullOutputPath := CONCAT(@OutputPath, @filename);
set @q1 := concat("SELECT group_concat(`NHS` separator '') INTO OUTFILE ",@fullOutputPath,
" FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '\'
FROM person WHERE `active` = -1 AND `NHS` IS NOT NULL AND `NHS` REGEXP [0123456789]{10}
ORDER BY 1");
prepare s1 from @q1;
execute s1; deallocate prepare s1;
END$$
DELIMITER ;
我知道我可以写入路径,因为这有效:
SELECT oid INTO OUTFILE "C:/stuff/folder/nextfolder/files/POIExtract/varmydata.txt"
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\'
LINES TERMINATED BY '\n'
FROM person limit 1;
但是,当我包装一个过程并使用变量和 concat()
时,它不会创建输出文件。
我尝试了多种格式化文件路径的方法,但还是不行。当我尝试调用它时,出现错误代码:1064。您的 SQL 语法有误...
我不理解这种使用 REGEXP
的方式吗?
我打算使用预定事件调用它。
蒂亚,
麦克
秋名是对的。修改为:
set @q1 := concat("SELECT group_concat(`NHS` separator '') INTO OUTFILE ", " '", @fullOutputPath, "' ", " FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\' FROM p_person WHERE `active` = -1 AND `NHS` IS NOT NULL AND `NHS` REGEXP", " '[0123456789]{10}' ", "ORDER BY 1");