简体   繁体   中英

MySQL Global userdefined variable in procedure

I want to store the output from a PROCEDURE into a global userdefined VAR so i can use this "list" in an other PROCEDURE on a different database.

Second, if the VAR is used on the 2nd PROCEDURE it should be unset, because on next CALL it will append or?

Thanks for response!

BEGIN
SELECT `steamid` FROM `mybb_users` WHERE `steamid`!='';
END

The SELECT shout go into a global variable, so i can use the result in another procedure...

As far as I know, you can't return a row set as a result of a procedure in MySQL.

I would solve it by creating a temporary table in the first procedure, and then use that temp table in the second procedure. Something like this:

delimiter $$
create procedure procedure1()
begin
    drop table if exists temp_table;
    create temporary table temp_table
        select steamid from mybb_users where steamid != '';
    -- add the appropriate indexes here
    -- alter table temp_table
    --     add index ...
end $$
create procedure procedure2()
begin
    -- Do whatever you want to do with temp_table
end $$
delimiter ;

Remember:

  • A temporary table is visible only to the connection that created it.
  • If the connection is closed, the temporary table will be deleted.
  • Temporary tables are created directly to RAM (if they are not very big), so they can be pretty fast to read.
  • Each connection can create temporary tables with the same name, as each connection will have a "copy" of that temp table.

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