今天我在书上有个ecshop实例,其中用到了paypal支持工具。 
里面有很多存储过程,因为这例子居于linux系统开发的,我在写了一个存储过程:
CREATE PROCEDURE catalog_get_departments_list()
BEGIN
  SELECT department_id, name FROM department ORDER BY department_id;
END$$
报了
#1064 - 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 'SELECT department_id, name FROM department ORDER BY department_id' at line 3 
这种错误。
如果把'ELECT department_id, name FROM department ORDER BY department_id;'去掉,这是正确的
估计少了什么,然后从mysql用户手册上知道:
27.3. Adding New Procedures to MySQL
In MySQL, you can define a procedure in C++ that can access and modify the data in a query before it is sent to the client. The modification can be done on a row-by-row or GROUP BY level. We have created an example procedure in MySQL 3.23 to show you what can be done. Additionally, we recommend that you take a look at mylua. With this you can use the LUA language to load a procedure at runtime into mysqld. 27.3.1. Procedure Analyse
analyse([max_elements,[max_memory]]) This procedure is defined in the sql/sql_analyse.cc. This examines the result from your query and returns an analysis of the results: max_elements (default 256) is the maximum number of distinct values analyse does notice per column. This is used by analyse to check whether the optimal column type should be of type ENUM. max_memory (default 8192) is the maximum amount of memory that analyse should allocate per column while trying to find all distinct values. SELECT ... FROM ... WHERE ... PROCEDURE ANALYSE([max_elements,[max_memory]])27.3.2. Writing a Procedure
For the moment, the only documentation for this is the source. You can find all information about procedures by examining the following files: sql/sql_analyse.cc sql/procedure.h sql/procedure.cc sql/sql_select.cc 

解决方案 »

  1.   

    测试正常。mysql> delimiter $$
    mysql>
    mysql> CREATE PROCEDURE catalog_get_departments_list(
        -> BEGIN
        ->  SELECT id, c1 FROM t5 ORDER BY id;
        -> END$$
    Query OK, 0 rows affected (0.27 sec)mysql> delimiter ;
    mysql>
    mysql> call catalog_get_departments_list();
    +------+----------------------+
    | id   | c1                   |
    +------+----------------------+
    |    1 | 2008-12-31按排期交货 |
    |    2 | 2008-12-31?????      |
    |    3 | 2008-12-31?????      |
    |    4 | 2008-12-31?????      |
    |    9 | NULL                 |
    |   11 | 111                  |
    +------+----------------------+
    6 rows in set (0.06 sec)Query OK, 0 rows affected (0.08 sec)mysql>
    测试版本
    [code=BatchFile]mysql> select version();
    +----------------------+
    | version()            |
    +----------------------+
    | 5.1.33-community-log |
    +----------------------+
    1 row in set (0.00 sec)
    [/code]
      

  2.   

    你是在MYSQL SHELL下?
    mysql> DELIMITER $$
    mysql> CREATE PROCEDURE QQ()
        -> BEGIN
        -> SELECT department_id, name FROM department ORDER BY department_id; 
        -> END
        -> $$