Home Database Mysql Tutorial mysql variable declaration and assignment

mysql variable declaration and assignment

Dec 16, 2016 pm 02:06 PM

Variables in sql server must be declared first and then assigned a value:

Local variables are marked with one @, and global variables are marked with two @s (commonly used global variables are generally already defined);

The syntax for declaring local variables: declare @variable Name data type; for example: declare @num int;

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

set @num=value; or select @num=value;

If you want To obtain a field value in a query statement, you can use select to assign a value to a variable, as follows:

select @num=Field name from table name where...

Variables in MySQL do not need to be declared in advance. When using them, use "@variable name" directly. "Just use it.

First usage: set @num=1; or set @num:=1; //Variables are used to save data here, use @num variables directly

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

Pay attention to the above two assignment symbols. You can use "=" or ":=" when using set, but you must use ":= assignment" when using select

The above is the content of mysql variable declaration and value assignment. For more related articles, please pay attention to the PHP Chinese website (www.php.cn)!


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to enable copy and paste for VMware virtual machines How to enable copy and paste for VMware virtual machines Feb 21, 2024 am 10:09 AM

How to enable copy and paste for VMware virtual machines

How to copy a page in Word How to copy a page in Word Feb 20, 2024 am 10:09 AM

How to copy a page in Word

Disable or enable automatic copy selection for copying in Terminal Disable or enable automatic copy selection for copying in Terminal Mar 24, 2024 am 09:46 AM

Disable or enable automatic copy selection for copying in Terminal

Unlock macOS clipboard history, efficient copy and paste techniques Unlock macOS clipboard history, efficient copy and paste techniques Feb 19, 2024 pm 01:18 PM

Unlock macOS clipboard history, efficient copy and paste techniques

What are the assignment methods in php? What are the assignment methods in php? Jul 26, 2023 pm 01:11 PM

What are the assignment methods in php?

Tips and Notes: Different String Array Assignment Methods Tips and Notes: Different String Array Assignment Methods Dec 26, 2023 am 11:30 AM

Tips and Notes: Different String Array Assignment Methods

What are the methods of assigning values ​​to string arrays? What are the methods of assigning values ​​to string arrays? Dec 25, 2023 pm 05:07 PM

What are the methods of assigning values ​​to string arrays?

Learn variable definition and assignment in Golang Learn variable definition and assignment in Golang Jan 18, 2024 am 10:00 AM

Learn variable definition and assignment in Golang

See all articles