mysql 建立存储过程错误,求助!
mysql> create procedure productpricing() BEGIN select Avg(prod_price) as priceaverage from products; 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 '' at line 1
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' at line 1
看mysql必知必会这书,里面的例句执行失败
mysql版本:Server version: 5.1.41-3ubuntu12.10 (Ubuntu)
mysql> show columns from products;
+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| prod_id | char(10) | NO | PRI | NULL | |
| vend_id | int(11) | NO | MUL | NULL | |
| prod_name | char(255) | NO | | NULL | |
| prod_price | decimal(8,2) | NO | | NULL | |
| prod_desc | text | YES | | NULL | |
+------------+--------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
------解决方案--------------------delimiter$$
create procedure productpricing()
BEGIN select Avg(prod_price) as priceaverage from products;
END$$
delimiter;
------解决方案--------------------SQL code
create procedure productpricing() select Avg(prod_price) as priceaverage from products;
------解决方案--------------------
SQL code
mysql> create procedure productpricing() select Avg(prod_price) as priceaverage
from products;
Query OK, 0 rows affected (0.00 sec)
------解决方案--------------------
需要先设置结束符 delimiter $
否则的话遇到;就会自动结束
mysql> DELIMITER $$
mysql> CREATE PROCEDURE productpricing()
-> BEGIN
-> SELECT AVG(prod_price) AS priceaverage FROM products;
-> END$$
mysql> DELIMITER ;