2.2. Statement Terminators


You may use any of several terminators to end a statement. Two terminators are the semicolon character (';') and the \g sequence. They're equivalent and may be used interchangeably:

 mysql> SELECT VERSION(), DATABASE(); +----------------+-------------+ | VERSION()       | DATABASE() | +----------------+-------------+ | 5.0.10-beta-log | world      | +----------------+-------------+ mysql> SELECT VERSION(), DATABASE()\g +----------------+-------------+ | VERSION()       | DATABASE() | +----------------+-------------+ | 5.0.10-beta-log | world      | +----------------+-------------+ 

The \G sequence also terminates queries, but causes mysql to display query results in a vertical style that shows each output row with each column value on a separate line:

 mysql> SELECT VERSION(), DATABASE()\G *************************** 1. row ***************************  VERSION(): 5.0.10-beta-log DATABASE(): world 

The \G terminator is especially useful if a query produces very wide output lines because vertical format can make the result much easier to read.

If you are using mysql to define a stored routine or a trigger that uses compound statement syntax and consists of multiple statements, the definition will contain semicolons internally. In this case, it is necessary to redefine the ';' terminator to cause mysql to pass semicolons in the definition to the server rather than interpreting them itself. Terminator redefinition is covered in Section 18.4, "Defining Stored Routines."



MySQL 5 Certification Study Guide
MySQL 5.0 Certification Study Guide
ISBN: 0672328127
EAN: 2147483647
Year: 2006
Pages: 312

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net