How can I combine built-in-commands (\g and \G), used for executing a MySQL statement, with termination symbol semicolon (;) to get output without any error?

MySQLMySQLi Database

As we know that built-in-commands (\G and \g) send the command to MySQL server for execution and with the help of Semicolon (;) MySQL determines the end of the statement. It is also known that both of them have different format of the result set. For combining them and getting the result without error, we need to write two queries, one query with either \G or \g and other with a semicolon (;) at the end, in a single statement.

Example

Combining \G and Semicolon (;) −

mysql> Select * from student\G select * from ratelist;
*************************** 1. row ***************************
  Name: Gaurav
RollNo: 100
 Grade: B.tech
*************************** 2. row ***************************
  Name: Aarav
RollNo: 150
 Grade: M.SC
*************************** 3. row ***************************
  Name: Aryan
RollNo: 165
 Grade: M.tech

3 rows in set (0.00 sec)
+----+------+-------+
| Sr | Item | Price |
+----+------+-------+
| 1  | A    | 502   |
| 2  | B    | 630   |
| 3  | C    | 1005  |
| 4  | h    | 850   |
| 5  | T    | 250   |
+----+------+-------+
5 rows in set (0.00 sec)

MySQL statement in the example above first encounter \G after the first query and throws the result set based on it in vertical format and then encounters semicolon (;) as termination symbol after the second query and throws the result set based on it in a tabular format.

Example

Combining \g and Semicolon (;) −

mysql> Select * from student\g select * from ratelist;
+--------+--------+--------+
| Name   | RollNo | Grade  |
+--------+--------+--------+
| Gaurav | 100    | B.tech |
| Aarav  | 150    | M.SC   |
| Aryan  | 165    | M.tech |
+--------+--------+--------+

3 rows in set (0.00 sec)
+----+------+-------+
| Sr | Item | Price |
+----+------+-------+
| 1  | A    | 502   |
| 2  | B    | 630   |
| 3  | C    | 1005  |
| 4  | h    | 850   |
| 5  | T    | 250   |
+----+------+-------+
5 rows in set (0.00 sec)

In the example above, MySQL statement first encounters \g after the first query, and based on it throws the result set in tabular format and then encounters semicolon (;) as termination symbol after the second query and based on it throws the result set in tabular format too.

raja
Published on 22-Feb-2018 06:17:18
Advertisements