为什么我需要在mysql存储过程结束时重置分隔符



假设我有这样一个存储过程:

为什么我需要重置分隔符?如果我不重置分隔符,我应该可以使用"$$"而不是" ">

DELIMITER $$
/* This is a complete statement, not part of the procedure, so use the custom delimiter $$ */
DROP PROCEDURE selectSales$$
/* Now start the procedure code */
CREATE PROCEDURE selectSales()
BEGIN
SELECT * FROM sales;

/* whole procedure ends with the custom delimiter */
END$$
/* I'm not resetting the delimiter, so I should be able to use "$$" instead of ";" */
SELECT * from sales$$  <--- gives syntax error
SELECT * from sales

我不相信你。

查看控制台输出:

mysql> CREATE TABLE sales SELECT 11 id;
Query OK, 1 row affected (0.53 sec)
Records: 1  Duplicates: 0  Warnings: 0
mysql> DELIMITER $$
mysql> CREATE PROCEDURE selectSales()
-> BEGIN
->     SELECT * FROM sales;
-> END$$
Query OK, 0 rows affected (0.08 sec)
mysql> SELECT * from sales$$
+----+
| id |
+----+
| 11 |
+----+
1 row in set (0.00 sec)

当然有可能你做了一些没有在描述中列出的事情……

最新更新