简体   繁体   中英

MySQL View, get result from stored procedure

I would like to create a view on MySQL, and the content will be read from stored procedure, is that a way to make it?

Which mean when I exec "mystoredProcedure()" I will receive a list of result, can I use view table to exec it, so result will directly show on view table.

Please advice me if you have any other solution.

Appreciate your help.

Thank you

I don't think it's possible. The syntax of CREATE VIEW requires a SELECT statement, but a stored procedure is executed with a CALL statement.

If you have access to the stored procedure, you can do something like this inside the procedure:

CREATE OR REPLACE TEMPORARY TABLE tmpData (id int PRIMARY KEY, name varchar(50)) ENGINE=MEMORY;

then insert the data you want to return.

When you want to use the result or even join it somewhere, just call ABC , after that then you can reference the tmpData table.

Note: temporary tables are visible only in your session, it will not interfere with others, but it's a good idea to name them as unique as possible so it will not hide any real tables with the same name. I always use tmp prefix.

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