MySQL中變量的定義與賦值


MySQL中變量的使用
https://www.cnblogs.com/easonjim/p/7966918.html
MySQL變量共四種:
局部變量
用戶變量
會話變量
全局變量


局部變量只在當前 Begin/End范圍內有效;
# 使用方式
declare var_name varchar(30) '老王';  // 默認值是老王
# 賦值方式
set c = a+b;
select [column] into var_name from xxx where xxx;
select [column] as var_name from xxx where xxx;

用戶變量,在客戶端連接到數據庫實例整個過程中都有效
# 用法1: 
set @var_name1 = 1; 或者 set @var_name1:= 1;

# 用法2 : (使用select時,只能使用 := )
select @var_name2:=[column] from xxx where xxxx;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM