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