日期:2014-05-16  浏览次数:22160 次

创建存储过程的语法问题
SQL code
CREATE PROCEDURE sign (
                       IN user_mail CHAR(20),
                       IN user_name CHAR(20),
                       IN user_pw   CHAR(20),
                      OUT user_id   INT
                      )
BEGIN
     -- 创建两个变量, 也就是这块提示有语法错误
     DECLARE v_id INT(10);
     DECLARE v_result INT(10) DEFAULT 0;
     SELECT u_id FROM user WHERE u_mail = user_mail INTO v_id;
     IF ( v_id IS NULL ) THEN
         INSERT INTO user (u_mail, u_name, u_password, u_signTime)
                   VALUES ('user_mail', 'user_name', 'user_pw', );
         SELECT u_id FROM user WHERE u_mail = user_mail INTO v_result;
     END IF;
     SELECT v_result INTO user_id;
END;



------解决方案--------------------
SQL code
mysql> delimiter //
mysql>
mysql> CREATE PROCEDURE sign (
    ->                        IN user_mail CHAR(20),
    ->                        IN user_name CHAR(20),
    ->                        IN user_pw   CHAR(20),
    ->                       OUT user_id   INT
    ->                       )
    -> BEGIN
    ->      -- 创建两个变量, 也就是这块提示有语法错误
    ->      DECLARE v_id INT(10);
    ->      DECLARE v_result INT(10) DEFAULT 0;
    ->      SELECT u_id FROM user WHERE u_mail = user_mail INTO v_id;
    ->      IF ( v_id IS NULL ) THEN
    ->          INSERT INTO user (u_mail, u_name, u_password, u_signTime)
    ->                    VALUES ('user_mail', 'user_name', 'user_pw', now);  -- acmain: missing the value for last column
    ->          SELECT u_id INTO v_result FROM user WHERE u_mail = user_mail ; -- acmain: syntax is "select col into var ..."
    ->      END IF;
    ->      SELECT v_result INTO user_id;
    -> END;
    -> //
Query OK, 0 rows affected (0.44 sec)

mysql>

------解决方案--------------------
INSERT INTO user (u_mail, u_name, u_password, u_signTime)
VALUES ('user_mail', 'user_name', 'user_pw', );

这句多了个,