小编use*_*095的帖子

在MySQL存储过程中创建的临时表的范围

问题撤回!当我拼写正确的一切时,问题就消失了!

我有一个MySQL存储过程,它创建一个临时表.当我从mysql提示符调用该过程时,它似乎运行成功,但如果我然后从临时表中SELECT COUNT(*),我得到一个错误说该表不存在.

存储过程结束时,存储过程内创建的临时表是否不再存在?

mysql> delimiter //
mysql> drop procedure if exists sp_temp_reciepts//
mysql> create procedure sp_temp_receipts ()
begin
  drop temporary table if exists receipts;
  create temporary table receipts
  (  ... snip ...
  );
  insert into receipts
  select ... snip ...
end//
mysql> delimiter ;
mysql> call sp_temp_reciepts();
Query OK, 46903 rows affected, 1 warning (2.15 sec)
mysql> select count(*) from receipts;
ERROR 1146 (42S02): Table 'receipts' doesn't exist
Run Code Online (Sandbox Code Playgroud)

mysql stored-procedures temp-tables

15
推荐指数
1
解决办法
8207
查看次数

标签 统计

mysql ×1

stored-procedures ×1

temp-tables ×1