MySQL in while loop and variable declaration and Dilimiter

Source: Internet
Author: User
Tags mysql in

First we look at a correct complete one stored procedure

① where the delimiter command is interpreted as follows: By default, delimiter is a semicolon ;. In the command-line client, if a single line of commands ends with a semicolon, the command will be executed by MySQL when the carriage returns.

This default execution of a command with a semicolon will cause the stored procedure to be created incomplete and will be executed, obviously with an error. So the delimiter command will be the default; (can also be &&,//or something). When you are finished executing

After you have finished writing a sentence, use | | End, commit execution. Finally, use the delimiter command to change back.

Local variable declarations in ②mysql can only be written in SQL statement blocks, such as functions and stored procedures, scoped to a block of statements. MSYQL does not support anonymous blocks, so it is not possible to use variables arbitrarily;

User variables are not declared to be used directly, and the scope is the current entire connection. Direct assignment with select and set where select assignment can only be assigned with ": =" because in the SELECT statement, the "=" value

Perform a comparison operation

DELIMITER | |Create procedureMypro ()beginDeclareIinteger;SetI=1; startTransaction; whileI<= - DobeginEnd;End  while;Commit;End; | |delimiter;

MySQL in while loop and variable declaration and Dilimiter

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.