當執行:MySQL的語法錯誤
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
SELECT 1;
END;
DECLARE EXIT HANDLER FOR SQLWARNING
BEGIN
ROLLBACK;
SELECT 1;
END;
-- delete all users in the main profile table that are in the MaineU18 by email address
DELETE FROM ap_form_1 WHERE element_5 IN (SELECT email FROM MaineU18);
-- delete all users from the MaineU18 table
DELETE from MaineU18;
COMMIT;
END;
我得到:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'e1:
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK' at line 2
任何想法?謝謝。
更新2:
I have tried putting the script into a PROCEDURE:
DELIMITER |
DROP PROCEDURE IF EXISTS temp_clapro|
CREATE PROCEDURE temp_clapro()
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION, SQLWARNING ROLLBACK;
SET AUTOCOMMIT=0;
-- delete all users in the main profile table that are in the MaineU18 by email address
DELETE FROM ap_form_1 WHERE element_5 IN (SELECT email FROM MaineU18);
-- delete all users from the MaineU18 table
DELETE from MaineU18;
COMMIT;
SET AUTOCOMMIT=1;
END
|
DELIMITER ;
CALL temp_clapro();
我仍然有問題:
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (2.40 sec)
Query OK, 0 rows affected (2.40 sec)
Query OK, 0 rows affected (2.40 sec)
Query OK, 0 rows affected (2.40 sec)
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END;
|
DELIMITER ;
CALL temp_clapro()' at line 1
更新3:
看來,我的很多問題都來自這樣的事實來我使用「SOURCE」命令從文件運行腳本。如果我只在文件中具有DROP和CREATE命令,並在文件外部運行DELIMITER和CALL命令,那麼一切正常。
是否可以從單個腳本文件運行此操作?
Bill:您的意思是SQL Server,而不是Oracle。 Oracle僅對程序和函數的主體使用BEGIN/END; SQL Server *喜歡*它是BEGIN/END語句... – 2009-10-06 17:15:14
感謝您的幫助,但即使將腳本放在PROCEDURE塊中,我仍然遇到問題。感謝您的幫助。 「更新1」位於上方。 – 2009-10-06 17:23:30
@rexem,謝謝你的提醒。我以爲我看到Oracle腳本使用裸BEGIN/END塊,但也許我只是把它與微軟混淆。 – 2009-10-06 20:38:29