In MySQL, how we can write Multiple-line statement?


We can write multiple-line statements because MySQL determines the end of a statement by looking for the termination semicolon, not by looking for the end of the input line.

Example

mysql> Select *
    -> from
    -> stock_item;
+------------+-------+----------+
| item_name  | Value | Quantity |
+------------+-------+----------+
| Calculator | 15    | 89      |
| Notebooks  | 63    | 40      |
| Pencil     | 15    | 40      |
| Pens       | 65    | 32      |
| Shirts     | 13    | 29      |
| Shoes      | 15    | 29      |
| Trousers   | 15    | 29      |
+------------+-------+----------+
7 rows in set (0.00 sec)

In the example above, we write a single query into multiple lines and MySQL returns the output only after getting the termination semicolon. In this way we can also say that MySQL can recognize liberated-format input, it gathers the input lines but does not accomplish them until it notices the termination semicolon.

Updated on: 22-Jun-2020

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements