有人可以解释为什么MySQL工作台会在
上抱怨语法错误 DECLARE @fil_name, @fil_path STRING;
2个错误:意外的'@fil_name'(在文本后缀处)和STRING(缺少冒号)
SELECT * FROM gumcad INTO OUTFILE @fil_path FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
处的 @fil_path
错误:意外的'@fil_path'(文字后缀)
DELIMITER //
CREATE EVENT `Export` ON SCHEDULE EVERY 2 SECOND
ON COMPLETION PRESERVE
ENABLE
DO BEGIN
DECLARE @fil_name, @fil_path STRING;
SET @fil_name=CONCAT('GUMCAD-', DATE_FORMAT(now(), '%d%m%y'));
SET @fil_path=CONCAT('C:/app/reports/gumcad/', @fil_name, '.csv'));
SELECT * FROM gumcad INTO OUTFILE @fil_path FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
INSERT INTO imported_reports (imr_est_id, imr_type, imr_create_date, imr_created, imr_record_status, imr_file_path, imr_file_name, imr_created_by)
VALUES (2, GUMCAD, CURDATE(), NOW(), 'approved', @fil_path, @fil_name, 'SHEP');
END
DELIMITER;
修改
我刚才发现使用@var时我不必使用DECLARE。这是我的新剧本:
DELIMITER //
CREATE EVENT `Export` ON SCHEDULE EVERY 2 SECOND
ON COMPLETION PRESERVE
ENABLE
DO BEGIN
SET @fil_name=CONCAT('GUMCAD-', DATE_FORMAT(now(), '%d%m%y'), '.csv');
SET @fil_path='C:/app/reports/gumcad/';
SET @export_path=CONCAT(@fil_path, @fil_name);
SELECT * FROM gumcad INTO OUTFILE @export_path FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
INSERT INTO imported_reports (imr_est_id, imr_type, imr_create_date, imr_created, imr_record_status, imr_file_path, imr_file_name, imr_created_by)
VALUES (2, GUMCAD, CURDATE(), NOW(), 'approved', @fil_path, @fil_name, 'SHEP');
END
DELIMITER;
但是我在@export_path
(unexpected '@export_path' (at text suffix))
时遇到错误,有人可以解释一下吗?
NEW UPDATE 此刻没有更多的错误消息,我能够运行脚本,但现在一个问题是脚本似乎不会每2秒运行一次。
请看一下我修改过的脚本,我正在使用MySQL 5.5:
DELIMITER $$
CREATE EVENT `Export` ON SCHEDULE EVERY 2 SECOND
ON COMPLETION PRESERVE
ENABLE
DO BEGIN
DECLARE fil_name varchar(200);
DECLARE export_path varchar(200);
DECLARE fil_path varchar(200);
SET fil_name=CONCAT('GUMCAD-', DATE_FORMAT(now(), '%d%m%y'), '.csv');
SET fil_path='C:/cellma/reports/gumcad/';
SET export_path=CONCAT(fil_path, fil_name);
SELECT * FROM gumcad INTO OUTFILE "export_path" FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
INSERT INTO imported_reports (imr_est_id, imr_type, imr_create_date, imr_created, imr_record_status, imr_file_path, imr_file_name, imr_created_by)
VALUES (2, GUMCAD, CURDATE(), NOW(), 'approved', @fil_path, @fil_name, 'SHEP');
END $$