如何将表作为存储过程的参数传递或如何从存储过程返回表

时间:2018-11-22 06:56:59

标签: mysql stored-procedures

CREATE PROCEDURE list_db(TABLE user_details)
BEGIN
DECLARE wordpress_db varchar(100) DEFAULT "";
DECLARE wordpress_cursor_done INTEGER DEFAULT 0;
DECLARE wp_users_done INTEGER DEFAULT 0;

DECLARE wordpress_cursor CURSOR FOR select schema_name 
from information_schema.schemata where schema_name like '%wordpress%'; 
DECLARE CONTINUE HANDLER FOR NOT FOUND SET wordpress_cursor_done = 1;

OPEN wordpress_cursor;
wordpress_cursor_loop:LOOP
FETCH wordpress_cursor INTO wordpress_db;
IF wordpress_cursor_done = 1 THEN
    LEAVE wordpress_cursor_loop;
END IF;

IF EXISTS(SELECT wp_users FROM wordpress_db) THEN
    SET user_details = SELECT user_login , user_email , user_pass , user_url 
FROM wp_users;
END IF;
END LOOP;

CLOSE wordpress_cursor;
END

如何传递一个空表并在该表中设置值? 还是函数可以返回表? 如果使用存储过程发生错误,如何打印错误消息? 如果有办法,请告诉我使用存储过程或函数打印表并打印错误

0 个答案:

没有答案