MySQL declaring variables and assigning values

Source: Internet
Author: User

Variables in SQL Server must be affirmed first and then assigned values:

The local variables are identified with one @ and the global variables with two @ (common global variables are usually defined );

Declare the local variable Syntax: declare @ variable name data type; for example, declare @ num int;

Value assignment: There are two methods (@ num is the variable name and value is the value)

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

If you want to obtain a field value in the query statement, you can use select to assign values to the variable, as shown below:

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

MySQL variables do not need to be stated beforehand. You can simply use "@ variable name" when using them.

First usage: Set @ num = 1; or set @ num: = 1; // use the variable to save the data. Use the @ num variable directly.

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

Note that the above two values can be set with "=" or ": =", but ": =" must be used for select"

 

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.