简体   繁体   中英

How return empty resultset always from MySQL stored procedure?

I want to know How return empty resultset always from MySQL stored procedure, if there is any type error is raise on Procedure during data fetching.

Thanks

Inside your procedure, can use the ERROR HANDLER

CREATE PROCEDURE `procedure_namme`(OUT return_data TEXT)
BEGIN
    DECLARE v_error_code CHAR(5);
    DECLARE v_error_msg TEXT;    
    DECLARE EXIT HANDLER FOR SQLEXCEPTION
         BEGIN
         GET DIAGNOSTICS CONDITION 1
            v_error_code = RETURNED_SQLSTATE,
            v_error_msg = message_text;
            SET return_data = NULL; -- IF ERROR OCCUR THEN ITS SET NULL
            SELECT v_error_code,v_error_msg;
         END
         -- BODY WHAT YOU WANT TO WRITE(LOGIC)

 END;

To know more about it you can refer this one
http://www.mysqltutorial.org/mysql-error-handling-in-stored-procedures/

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