用MYSQL编写存储过程很困难 [英] Difficulty in writing Stored Procedure in MYSQL

查看:151
本文介绍了用MYSQL编写存储过程很困难的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的存储过程的代码是:

The code my Stored Procedure is:

CREATE PROCEDURE insert_sait_inf(IN name TEXT,IN title TEXT,IN link TEXT)

BEGIN

INSERT INTO sait_inf(sait_name,sait_title,sait_link) VALUES (name,title,link);

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 '' at line 3 

推荐答案

  • 如果您使用 mysql 客户端程序来定义包含以下内容的存储程序分号字符,会出现问题.默认情况下, mysql 本身将分号识别为语句定界符,因此您必须临时重新定义定界符,以使 mysql 将整个存储程序定义传递给服务器.

    If you use the mysql client program to define a stored program containing semicolon characters, a problem arises. By default, mysql itself recognizes the semicolon as a statement delimiter, so you must redefine the delimiter temporarily to cause mysql to pass the entire stored program definition to the server.

    phpMyAdmin也是如此.

    The same is true of phpMyAdmin.

    要重新定义 mysql 分隔符,请使用delimiter命令.

    To redefine the mysql delimiter, use the delimiter command.

    并非所有版本的phpMyAdmin都可以识别delimiter命令.相反,可以使用SQL输入框下方的Delimiter输入框:请参阅如何在phpMyAdmin(MySQL)中编写SP? a>

    Not all versions of phpMyAdmin recognise the delimiter command; instead, one can use the Delimiter input box beneath the SQL input box: see How do I write an SP in phpMyAdmin (MySQL)?

    以下是使用参数,使用SQL函数执行操作并返回结果的函数示例.在这种情况下,不必使用delimiter,因为函数定义不包含内部的;语句定界符:

    The following is an example of a function that takes a parameter, performs an operation using an SQL function, and returns the result. In this case, it is unnecessary to use delimiter because the function definition contains no internal ; statement delimiters:

    
    mysql> CREATE FUNCTION hello (s CHAR(20))
    mysql> RETURNS CHAR(50) DETERMINISTIC
        -> RETURN CONCAT('Hello, ',s,'!');
    Query OK, 0 rows affected (0.00 sec)
    

    根据您的情况,您可以删除 BEGIN ... END 复合语句块,避免更改定界符.

    In your case, you can remove the BEGIN ... END compound statement block and avoid the need to change delimiter.

    这篇关于用MYSQL编写存储过程很困难的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆