程序中的MySQL全局用户定义变量

时间:2014-08-20 20:22:02

标签: mysql global-variables procedure

我想将PROCEDURE的输出存储到全局用户定义的VAR中,这样我就可以在其他数据库的其他PROCEDURE中使用这个“列表”。

其次,如果在第二个PROCEDURE上使用VAR,则应该取消设置,因为在下一个CALL上它会附加或?

感谢您的回复!

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

SELECT shout进入全局变量,所以我可以在另一个过程中使用结果......

1 个答案:

答案 0 :(得分:1)

据我所知,由于MySQL中的过程,您无法返回行集。

我会通过在第一个过程中创建一个临时表来解决它,然后在第二个过程中使用该临时表。像这样:

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 ;

记住:

  • 临时表仅对创建它的连接可见。
  • 如果关闭连接,将删除临时表。
  • 临时表是直接创建到RAM(如果它们不是很大),所以它们读起来非常快。
  • 每个连接都可以创建具有相同名称的临时表,因为每个连接都有该临时表的“副本”。