简体   繁体   English

创建MySQL存储过程

[英]Creating MySQL Stored Procedure

I am using Aqua Data Studio 20.6 to create a MySQL stored procedure.我正在使用 Aqua Data Studio 20.6 创建一个 MySQL 存储过程。 The following is my procedure, I have named it sp_GetObjIDByProType :以下是我的过程,我将其命名为sp_GetObjIDByProType

( IN prono char(15), IN imgtype char(8), OUT objid bigint )
BEGIN
    SELECT ObjectID INTO objid FROM images WHERE ProNumber = prono AND DocType = imgtype LIMIT 20;
END

When I try to create the stored procedure, I get this error message:当我尝试创建存储过程时,我收到以下错误消息:

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 'IN imgtype char(8) )
( OUT objid bigint )
BEGIN
    SELECT ObjectID INTO objid F' at line 3

However, it appears as if creating the task was actually successfully ( sp_GetObjIDByProType appears under 'Procedures' ).但是,似乎创建任务实际上是成功的( sp_GetObjIDByProType 出现在 'Procedures' 下)。 I can view and alter this created stored procedure in another window ( resulting stored procedure in 'Alter' window ).我可以在另一个 window 中查看和更改这个创建的存储过程(在 'Alter' window 中生成存储过程)。 Does this mean that creation of the stored procedure was actually successful, or is there something wrong with what I did?这是否意味着存储过程的创建实际上是成功的,还是我所做的有问题?

Looks like your procedure was created.看起来您的程序已创建。 However, the LIMIT 20 in the query does not make sense.但是,查询中的LIMIT 20没有意义。 You are returning the selected ObjectID in the OUT parameter which can hold only one value.您将在OUT参数中返回选定的ObjectID ,该参数只能包含一个值。 Yet you limit the query to 20 rows.然而,您将查询限制为 20 行。

If you want to return max 20 rows, return the rows as a result set (leave out the out parameter and the INTO objid ), or limit the rows to just one row.如果要返回最多 20 行,请将行作为结果集返回(省略 out 参数和INTO objid ),或将行限制为仅一行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM