显示临时表不存在为什么?

时间:2014-02-18 07:12:39

标签: mysql database stored-procedures

我的尝试, 但是不存在表'dbname.rep3'之类的错误消息。

为什么?

DROP TEMPORARY TABLE IF EXISTS rep1;
DROP TEMPORARY TABLE IF EXISTS rep2;
DROP TEMPORARY TABLE IF EXISTS rep3;

CREATE TEMPORARY TABLE `rep1`(SELECT * FROM `config`);
CREATE TEMPORARY TABLE `rep2`(SELECT * FROM `config`);
/*CREATE TEMPORARY TABLE `rep3` SELECT * FROM `rep1` UNION ALL SELECT * FROM `rep2`; 
SELECT * FROM `rep3`; */

CREATE TEMPORARY TABLE `rep3` SELECT * FROM `rep1` UNION ALL SELECT * FROM `rep2`; 
SELECT * FROM `rep3`; 

1 个答案:

答案 0 :(得分:0)

它为我工作

abdul@xmpp3:~$ mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 334
Server version: 5.5.29-0ubuntu0.12.04.1 (Ubuntu)

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use world_innodb;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> DROP TEMPORARY TABLE IF EXISTS rep1;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> DROP TEMPORARY TABLE IF EXISTS rep2;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> DROP TEMPORARY TABLE IF EXISTS rep3;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> 
mysql> CREATE TEMPORARY TABLE `rep1`(SELECT * FROM world_innodb.City);
Query OK, 4079 rows affected (1.70 sec)
Records: 4079  Duplicates: 0  Warnings: 0

mysql> CREATE TEMPORARY TABLE `rep2`(SELECT * FROM world_innodb.City);
Query OK, 4079 rows affected (1.29 sec)
Records: 4079  Duplicates: 0  Warnings: 0

mysql> 
mysql> CREATE TEMPORARY TABLE `rep3` SELECT * FROM `rep1` UNION ALL SELECT * FROM `rep2`; 
Query OK, 8158 rows affected (2.50 sec)
Records: 8158  Duplicates: 0  Warnings: 0

mysql> SELECT * FROM `rep3` LIMIT 10; 
+----+----------------+-------------+---------------+------------+
| ID | Name           | CountryCode | District      | Population |
+----+----------------+-------------+---------------+------------+
|  1 | Kabul          | AFG         | Kabol         |    1780000 |
|  2 | Qandahar       | AFG         | Qandahar      |     237500 |
|  3 | Herat          | AFG         | Herat         |     186800 |
|  4 | Mazar-e-Sharif | AFG         | Balkh         |     127800 |
|  5 | Amsterdam      | NLD         | Noord-Holland |     731200 |
|  6 | Rotterdam      | NLD         | Zuid-Holland  |     593321 |
|  7 | Haag           | NLD         | Zuid-Holland  |     440900 |
|  8 | Utrecht        | NLD         | Utrecht       |     234323 |
|  9 | Eindhoven      | NLD         | Noord-Brabant |     201843 |
| 10 | Tilburg        | NLD         | Noord-Brabant |     193238 |
+----+----------------+-------------+---------------+------------+
10 rows in set (0.00 sec)
TEMPORARY TABLES中的{p> MySQL是基于会话的,您无法从其他会话访问它们。您是否正在从其他会话中访问表。您需要在同一会话中访问它们。