MYSQL declaration Variable and assignment

Source: Internet
Author: User

The variables in SQL Server are first declared and then assigned:

Local variables with an @ identifier, global variables with two @ (common global variables are generally defined);

Declare local variable syntax: DECLARE @ variable name data type; For example: declare @num int;

Assignment: There are two methods (@num is the variable name, value is the values)

Set @num =value; or select @num =value;

If you want to get a field value in a query statement, you can assign a value to a variable with SELECT, as follows:

Select @num = field name from table name where ...

The variables in MySQL do not have to be declared beforehand, use "@ variable name" when using it.

First usage: Set @num = 1; or set @num: = 1; To use variables to save the data, use the @num variable directly

Second usage: select @num: = 1; or select @num: = field name from table name where ...

Note the above two assignment symbols, which can be "=" or ": =" when using set, but must use ": = Assignment" When using Select

Transferred from: http://www.cnblogs.com/qixuejia/archive/2010/12/21/1913203.html

MYSQL declaration Variable and assignment

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.