MySQL 中的分隔符?


當你需要定義儲存過程、函式以及建立觸發器的時候,可以使用分隔符。預設分隔符為分號;

你可以更改分隔符來建立過程等等。但是,如果你考慮多個語句,則需要使用不同的分隔符,例如 $$ 或 //。

這裡有一個名為“GetRecordFromNow”的表,其中包含以下記錄 −

+---------------------+
| YourDateTime        |
+---------------------+
| 2018-12-07 22:30:18 |
| 2018-12-03 22:30:31 |
| 2018-12-02 22:30:41 |
| 2018-12-01 22:30:56 |
| 2018-12-03 22:31:04 |
+---------------------+
5 rows in set (0.00 sec)

分隔符關鍵字是 MySQL 中的一種函式型別。這裡是用分隔符呼叫上述表的演示 −

mysql> delimiter //
mysql> create procedure DisplayALL()
   −> begin
   −> select *from GetRecordsFromNow;
   −> end
   −> //
Query OK, 0 rows affected (0.40 sec)

mysql> delimiter ;
mysql> call DisplayALL();
+---------------------+
| YourDateTime        |
+---------------------+
| 2018-12-07 22:30:18 |
| 2018-12-03 22:30:31 |
| 2018-12-02 22:30:41 |
| 2018-12-01 22:30:56 |
| 2018-12-03 22:31:04 |
+---------------------+
5 rows in set (0.07 sec)

Query OK, 0 rows affected (0.10 sec)

更新於: 2019-07-30

6K+ 瀏覽

開啟你的 職業

透過完成課程獲得認證

開始
廣告
© . All rights reserved.