Delimiters in MySQL?

MySQLMySQLi Database

Delimiters can be used when you need to define the stored procedures, function as well as to create triggers. The default delimiter is semicolon.

You can change the delimiters to create procedures and so on. However, but if you are considering multiple statements, then you need to use different delimiters like $$ or //.

Here we have a table “GetRecordFromNow” wherein the following are the records −

+---------------------+
| 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)

The delimiter keyword is a type of function in MySQL client. Here is the demo of delimiter that calls the above table using delimiter −

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)
raja
Published on 10-Jan-2019 17:06:04
Advertisements