简体   繁体   中英

how to write mulitple select statement in stored procedure?

DELIMITER $$
CREATE PROCEDURE abc(IN _uid VARCHAR(15))
BEGIN
    SELECT COUNT(filename)
    FROM    file
    WHERE userid = _uid
    UNION ALL
    SELECT COUNT(file)
    FROM    fileupload
    WHERE userid = _uid
END $$
DELIMITER ;

As this my query , As I need two select statement output

but it getting error

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'END' at line 10

Try:

mysql> DELIMITER $$

mysql> CREATE PROCEDURE abc(IN _uid VARCHAR(15))
    -> BEGIN
    ->     SELECT COUNT(filename)
    ->     FROM    file
    ->     WHERE userid = _uid
    ->     UNION ALL
    ->     SELECT COUNT(file)
    ->     FROM    fileupload
    ->     -- WHERE userid = _uid
    ->     WHERE userid = _uid;
    -> END$$
Query OK, 0 rows affected (0.00 sec)

mysql> DELIMITER ;

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