原文鏈接http://zhhll.icu/2021/01/02/%E6%95%B0%E6%8D%AE%E5%BA%93/%E5%85%B3%E7%B3%BB%E5%9E%8B%E6%95%B0%E6%8D%AE%E5%BA%93/MySQL/MySQL%E5%8F%98%E9%87%8F/
MySQL變數
MySQL變數分為系統變數和自定義變數
系統變數
系統變數有全域變數和會話變數
查看系統變數
#查看全域系統變數
show global variables;
#根據條件查詢全域系統變數
show global variables like '%%';
#查詢某個全域系統變數
select @@global.變數名
#查看會話系統變數
show 【session】 variables;
#根據條件查詢會話系統變數
show 【session】 variables like '%%';
#查詢某個會話系統變數
select @@【session.】變數名
設定系統變數
#方式一
set global 變數名 = 值
#方式二
set @@global.變數名 = 值
set @@【session.】變數名 = 值
自定義變數
自定義變數的步驟:宣告、賦值、使用
自定義變數分為用戶變數和區域變數
用戶變數
用戶變數針對于當前會話有效,用戶變數在宣告時必須進行初始化
#用戶變數宣告初始化方式
#方式一
set @用戶變數名 = 值;
#方式二
set @用戶變數名:=值
#方式三
select @用戶變數名:=值;
#查看用戶變數
select @用戶變數名;
區域變數
僅在定義該區域變數的begin end中有效
#①宣告 在begin end中第一句話宣告
declare 變數名 型別;
#宣告并賦默認值
declare 變數名 型別 default 默認值;
#②賦值
#方式一
set 區域變數名 = 值;
#方式二
set 區域變數名:=值
#方式三
select @區域變數名:=值;
#③查看
select 區域變數名;
由于本身的博客百度沒有收錄,博客地址http://zhhll.icu
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/257700.html
標籤:MySQL
