简体   繁体   中英

Creating MySQL Stored Procedure

I am using Aqua Data Studio 20.6 to create a MySQL stored procedure. The following is my procedure, I have named it 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' ). I can view and alter this created stored procedure in another window ( resulting stored procedure in '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. You are returning the selected ObjectID in the OUT parameter which can hold only one value. Yet you limit the query to 20 rows.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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