The role of delimiter in MySQL and the special syntax when there is only one element in the element group in Python

Source: Internet
Author: User
Tags mysql gui
What is the role of delimiter in MySQL?

This command has nothing to do with the stored procedure.
In fact, it is to tell the MySQL interpreter whether the command has ended and whether MySQL can be executed.
By default, Delimiter is a semicolon;. In the command line client, if a command line ends with a semicolon,
After you press enter, MySQL will execute this command. Enter the following statement.
Mysql> select * From test_table;
Press enter, and MySQL will immediately execute the statement.

But sometimes, you don't want MySQL to do this. The statement contains a semicolon.
If you try to enter the following statement in the command line client:
Mysql> Create Function 'shorten '(s varchar (255), n int)
Mysql> Returns varchar (255)
Mysql> begin
Mysql> If isnull (s) then
Mysql>Return '';
Mysql> elseif n <15 then
Mysql> return left (S, N );
Mysql> else
Mysql> If char_length (s) <= n then
Mysql> return S;
Mysql> else
Mysql> return Concat (left (S, N-10), '...', right (s, 5 ));
Mysql> end if;
Mysql> end if;
Mysql> end;
By default, it is impossible for the user to execute the entire statement after entering all these statements.
MySQL runs automatically when it encounters a semicolon.
That is, in the statementReturn '';MySQL interpreter will be executed.
In this case, you need to replace delimiter with another symbol, such as // or $.
Mysql> delimiter //
Mysql> Create Function 'shorten '(s varchar (255), n int)
Mysql> Returns varchar (255)
Mysql> begin
Mysql> If isnull (s) then
Mysql>Return '';
Mysql> elseif n <15 then
Mysql> return left (S, N );
Mysql> else
Mysql> If char_length (s) <= n then
Mysql> return S;
Mysql> else
Mysql> return Concat (left (S, N-10), '...', right (s, 5 ));
Mysql> end if;
Mysql> end if;
Mysql> end;//
In this way, only when//This statement is executed by the MySQL interpreter only after it appears.

Example:

 

Delimiter //

Createprocedure simpleproc (Out param1 INT)

Begin

Selectcount (*) into param1 from T;

End ;//

Queryok, 0 rows affected( 0.00 Sec)

Mysql> delimiter;

Mysql> call simpleproc (@ );
Query OK, 0 rows affected (0.00 Sec)

 

I can run smoothly on the MySQL graphical client EMS SQL Manager 2005 for MySQL. However, an error occurs on the sqlyog MySQL GUI v5.02 client. The final reason is that Delimiter is not properly configured. By default, delimiter ";" is used to submit query statements to MySQL. In the stored procedure, each SQL statement ends with a ";". If ";" is submitted to MySQL at this time, a problem may occur.

 

It can be seen that MYSQL client tools are different in some places.

I think ODBC, mysqldb, and other database interfaces have their own processing methods !!!

 

Note the writing method when only one element exists in Python !!!

Tuples that contain 0 or 1 project. An empty tuples consist of an empty pair of parentheses, such as myempty = (). However, tuples containing a single element are not that simple. You must be followed by a comma in the first (unique) project so that python can distinguish between a tuple and an object with parentheses in the expression. That is, if you want a tuples containing project 2, you should specify Singleton = (2 ,).

 

View stored procedure: Show procedure status

View the trigger: Show triggers or select * frominformation_schema.triggers

 

Delimiter //

Create trigger demo_trigger beforeinsert on Zhang for each row

Begin

Set @ x = "Hello trigger ";

End;

//

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.