在MySQL預存程序中建立暫存資料表的語法如下:
CREATE PROCEDURE yourProcedureName() BEGIN CREATE TEMPORARY TABLE yourTemporaryTableName SELECT yourValue; END
Let us implement the above syntax to create a temporary table and insert some records in the table. Following is the query to create a stored procedure and a temporary table in it −
mysql> DELIMITER // mysql> CREATE PROCEDURE create_Temporary_Table() -> BEGIN -> CREATE TEMPORARY TABLE tmpDemoTable SELECT 500; -> END// Query OK, 0 rows affected (0.15 sec)
以下是在表中插入記錄的查詢:
mysql> CREATE PROCEDURE insert_Record_InTempTable() -> BEGIN -> INSERT INTO tmpDemoTable VALUES (300); -> END// Query OK, 0 rows affected (0.06 sec)
mysql> DELIMITER
現在您可以呼叫上述預存程序來建立一個臨時表−
mysql> call create_Temporary_Table(); Query OK, 1 row affected (0.00 sec) mysql> call insert_Record_InTempTable(); Query OK, 1 row affected (0.00 sec)
使用select語句顯示表中的所有記錄−
mysql> select *from tmpDemoTable;
這將產生以下輸出−
+-----+ | 500 | +-----+ | 500 | | 300 | +-----+ 2 rows in set (0.00 sec)
以上是在 MySQL 過程中建立臨時表?的詳細內容。更多資訊請關注PHP中文網其他相關文章!