MySQL: Syntax: User Variables

Source: Internet
Author: User


MySQL provides this very powerful thing, but the documentation has limited instructions, so that you may doubt MySQL's capabilities!

  • Is a session-level quasi-system variable generated, maintained, and recycled by the server similar to MySQL system variables. This is because the usage of the current connection session is no different from the system variables!
  • This is especially important for prepared statement execution. It also allows data sharing between session statements!


User variables are connection-level things. Name: @ flag

User variable words 5.0 are case insensitive

Variable assignment:

  • Set @ V1 {: = | =} value1 [, @ V2: = V2] [, @ V3 = V3] [,...] -- note the value assignment operator ": =" "="
  • Select @ V1 = value1 [, @ v2 = V2] [, @ V3 = V3] [,...] -- it can only be "=", because "=" is also a comparison operator in a non-set statement.
  • User variables can only be of limited data types: Numbers, character types, and special null. Other types are automatically converted to these basic types. In addition, precision and scale cannot be retained when values of the decimal and real numeric types are assigned!
  • The character set and sorting rules of string variables are consistent.
  • Bit value is assigned to the user variable as a binary string. To assign a value as a number, you must call cast for conversion.
  • The value of uninitialized variables is a string of the null type.
  • Variables cannot be assigned and used in the same statement. A typical error is that where, having, group, and order are calculated in the SELECT statement.
  • Be careful with variable type changes

 

 

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.