MySQL強化關鍵_015_存儲過程

目? 錄

一、概述

1.說明

2.優點

3.缺點?

二、存儲過程的操作

1.創建

2.調用

3.查看

4.刪除

三、變量

1.系統變量

(1)說明

(2)查看系統變量?

(3)設置系統變量

2.用戶變量

(1)說明

(2)用戶變量賦值

(3)讀取用戶變量

?3.局部變量

(1)說明

(2)聲明、賦值、讀取與調用

?四、IF

1.語法格式

2.實例

五、參數

1.三種類型

2.in、out 實例?

3.inout 實例

?六、CASE

1.語法格式1

2.語法格式2

3.實例

七、循環

1.WHILE 循環

(1)語法格式

(2)實例

2.REPEAT 循環

(1)語法格式

(2)實例?

3.?LOOP 循環

(1)語法格式

(2)leave 實例?

(3)iterate 實例

八、游標 cursor

1.說明

2.步驟

(1)聲明

(2)開啟

(3)獲取

(4)關閉

3.實例?

?九、捕捉并處理異常

1.說明

2.實例?

十、存儲函數

1.說明

2.語法格式

3.實例

十一、觸發器

1.說明

2.語法規則?

3.關鍵字 new、old

4.實例


一、概述

1.說明

  1. 存儲過程即過程化 SQL 語言,是在普通 SQL 語句上增加了編程語言的特點,將 DML 和 DQL 組織在過程化代碼中,通過邏輯判斷、循環等實現復雜計算的程序語言;
  2. 存儲過程有自己的變量、條件判斷、循環語句等,一個存儲過程中,可以將多條 SQL 語句以邏輯代碼的方式將其串聯,所以一個存儲過程可以看作是為了完成特定任務的 SQL 語句集合;
  3. 每一個存儲過程就是一個數據庫對象,和 table、view一樣存儲在數據庫當中,一次編譯永久有效。每個存儲過程都有自己的名稱,可以通過存儲過程的名稱調用;
  4. 在數據量龐大的情況下,利用存儲過程可以提升效率;
  5. 實際開發中,只有在需要進行性能優化時考慮使用。

2.優點

? ? ? ? 速度快。降低了應用服務器和數據庫服務器之間的網絡通訊開銷。


3.缺點?

? ? ? ? 移植性差、編寫難度大、維護性差。每一個數據庫管理系統都有獨特的存儲過程語法規則,一旦使用了存儲過程,較難更換數據庫產品。且對于數據庫存儲過程語法,沒有專業的 IDE,編碼效率較低,維護成本較高。


二、存儲過程的操作

# 為了演示存儲過程的一系列操作,首先初始化
drop table if exists human;
create table human(id int not null auto_increment,name varchar(10),gender char(2) default '未知',age int,phone varchar(20),primary key (id)
);
insert into human(name, gender, age, phone) values('王磊', '男', 18, '13328345217'),('劉穎', '女', 23, '17728589999'),('周子恩', '女', 21, '11253467846');

? ? ? ? 在 dos 命令窗口下,MySQL 遇到【;】將結束輸入,?所以在創建存儲過程時會報錯。

? ? ? ? 此時,需要使用【delimiter <符號>】更改結束符。為方便操作,以下操作均在?Navicat 里進行。


1.創建

create procedure p()
beginselect name, age, gender, phone from human;
end;


2.調用

call p();


3.查看

  1. 系統表 information_schema.routines 存儲了存儲過程、函數對象、觸發器對象等狀態信息;
  2. SPECIFIC_NAME:存儲過程的具體名稱,包括名稱和參數列表;
  3. ROUTINE_SCHEMA:存儲過程所在的數據庫名稱;
  4. ROUTINE_NAME:存儲過程名稱;
  5. ROUTINE_TYPE:PROCEDURE 表示存儲過程,FUNCTION 表示一個函數;
  6. ROUTINE_DEFINITION:存儲過程定義語言;
  7. CREATED:存儲過程創建時間;
  8. LAST_ALTERED:存儲過程最后修改時間;
  9. DATA_TYPE:存儲過程返回值類型、參數類型等。
select SPECIFIC_NAME, ROUTINE_SCHEMA, ROUTINE_NAME, ROUTINE_TYPE, ROUTINE_DEFINITION, CREATED, LAST_ALTERED, DATA_TYPE 
from information_schema.ROUTINES 
where ROUTINE_NAME = 'p';


4.刪除

drop procedure if exists p;


三、變量

1.系統變量

(1)說明

  1. MySQL 系統變量是 MySQL 服務器運行時控制行為的參數,可以被設置為特定值從而改變服務器的默認設置;
  2. 系統變量有全局作用域和會話作用域。全局作用域對所有連接和所有數據庫都適用,會話作用域只對當前連接和當前數據庫適用。

(2)查看系統變量?

  1. 語法格式
    1. 【show?[ global | session ] variables;】;
    2. 【show [ global | session ] variables like ' ';】;
    3. 【select @@[ global | session ].系統變量名;】。
  2. 未指定 global 和 session 時,默認是 session

(3)設置系統變量

  1. 語法格式:
    1. 【set [ global | session ] 系統變量名 = 值;】;
    2. 【set @@[ global | session ].系統變量名 = 值;】。
  2. 無論是全局設置還是會話設置,MySQL 服務器重啟之后,之前的配置都會失效。可以通過修改 MySQL 安裝根目錄下的 my.ini?配置文件實現永久修改;
  3. my.ini 默認不存在,需要新建。在 Windows 系統下,文件后綴是【.ini】,在 Linux 系統下,文件后綴是【.cnf】。

2.用戶變量

(1)說明

  1. 用戶自定義的變量;
  2. 只對當前會話有效
  3. 所有用戶變量以【@】開始

(2)用戶變量賦值

  1. 語法格式
    1. 【set @用戶變量名 = 值;】;
    2. 【set @用戶變量名 := 值;】(推薦使用“:”形式);
    3. 【set @用戶變量名 := 值, @用戶變量名 := 值;】;
    4. 【select @用戶變量名 := 值;】;
    5. 【select 字段名 into @用戶變量名 from 表名 where 條件;】。
  2. MySQL 中用戶變量無需聲明,可直接賦值。若未聲明直接讀取,則返回 NULL。
set @id = 1;
set @`name` := '張鵬';
set @age := 23;
set @gender = '男', @phone = '13325678910';

(3)讀取用戶變量

? ? ? ? 語法格式:【select @變量名1,??@變量名2, …;】。

select @id, @`name`, @age, @gender, @phone;


?3.局部變量

(1)說明

  1. 存儲過程可以使用局部變量,使用【declare】聲明,在 begin 和 end 之間有效;
  2. 局部變量只在存儲過程中有效

(2)聲明、賦值、讀取與調用

  1. 語法格式:【declare 變量名 數據類型 [default …];】;
  2. declare 通常出現在 begin 和 end 之間。
drop procedure if exists p1;
create procedure p1()
begin-- 1.聲明declare name varchar(10) default '佚名';declare age int default 0;-- 2.賦值set name := '徐佳禾';set age := 22;-- 3.讀取select name, age;
end;-- 4.調用
call p1();


?四、IF

1.語法格式

? ? ? ? if [條件1] then [分支1]

? ? ? ? elseif [條件2] then [分支2]

????????elseif [條件3] then [分支3]

? ? ? ? else [分支4]

? ? ? ? end if;


2.實例

????????員工月薪高于 10000 屬于“高收入”,6000 ~ 10000 屬于中收入,低于 6000 屬于低收入。查詢員工薪資收入級別。

drop procedure if exists p2;create procedure p2()
begin -- 聲明一個局部變量,存儲月薪declare sal int default 0;-- 聲明一個局部變量,存儲薪資等級declare gra varchar(3);-- 賦值月薪set sal := 6000;if sal > 10000 then set gra := '高收入';elseif sal between 6000 and 10000 thenset gra := '中收入';elseset gra := '低收入';end if;select gra;
end;call p2();


五、參數

1.三種類型

  1. in:入參,接收調用者傳入數據。未指定時默認為 in;
  2. out:出參,保存存儲過程執行結果;
  3. inout:即是入參也是出餐。

2.in、out 實例?

? ? ? ? 上方使用 if 語句判斷薪資等級,每次修改月薪需要在存儲過程中進行,如此不利于維護。可以使用參數改進。

drop procedure if exists p3;create procedure p3(in sal int, out gra varchar(3))
beginifsal > 10000thenset gra := '高收入';elseifsal < 6000thenset gra := '低收入';elseset gra := '中收入';end if;
end;call p3(10001, @grade);select @grade;


3.inout 實例

? ? ? ? 將傳入的薪資上調 10%。?

drop procedure if exists p4;create procedure p4(inout sal int)
begin set sal := sal * 1.1;
end;set @sal := 100;
call p4(@sal);
select @sal;


?六、CASE

1.語法格式1

????????case 匹配條件

? ? ? ? ????????when [值1] then [處理1]

????????????????when [值2] then [處理2]

? ? ? ? ????????else [處理3]

? ? ? ? end case;


2.語法格式2

? ? ? ? case

? ? ? ? ? ? ? ? when [條件1]?then [處理1]

????????????????when [條件1]?then [處理1]

????????????????else [處理3]

? ? ? ? end case;


3.實例

? ? ? ? 3、4、5 月為春季,6、7、8 月為夏季,9,10,11 月為秋季,12,1,2 月為冬季。根據月份輸出季節,其他輸入為非法輸入。?

-- 語法1
drop procedure if exists p5;
create procedure p5(in month int, out result char(2))
begincase monthwhen 3 then set result := '春季';when 4 then set result := '春季';when 5 then set result := '春季';when 6 then set result := '夏季';when 7 then set result := '夏季';when 8 then set result := '夏季';when 9 then set result := '秋季';when 10 then set result := '秋季';when 11 then set result := '秋季';when 12 then set result := '冬季';when 1 then set result := '冬季';when 2 then set result := '冬季';else set result := '非法';end case;
end;call p5(1, @season);
select @season;-- 語法2
drop procedure if exists p6;
create procedure p6(in month int, out result char(2))
begincasewhen month between 3 and 5 then set result := '春季';when month between 6 and 8 then set result := '夏季';when month between 9 and 11 then set result := '秋季';when month = 12 or month between 1 and 2 then set result := '冬季';else set result := '非法';end case;
end;call p6(6, @season);
select @season;


七、循環

1.WHILE 循環

(1)語法格式

? ? ? ? while [條件] do

????????????????-- 循環體

? ? ? ? end while;


(2)實例

? ? ? ? 傳入整數 n,計算 1 ~ n 中所有偶數和。?

drop procedure if exists p7;create procedure p7(in n int)
begindeclare sum int default 0;while n > 0doif n % 2 = 0then set sum := sum + n;end if;set n := n - 1;end while;select sum;
end;call p7(10);


2.REPEAT 循環

(1)語法格式

? ? ? ? ?repeat

? ? ? ? ? ? ? ? -- 循環體

? ? ? ? ? ? ? ? until 條件

? ? ? ? end repeat;


(2)實例?

????????傳入整數 n,計算 1 ~ n 中所有偶數和。?

drop procedure if exists p8;create procedure p8(in n int)
begindeclare sum int default 0;repeatif n % 2 = 0then set sum := sum + n;end if;set n := n - 1;until n <= 0end repeat;select sum;
end;call p8(10);


3.?LOOP 循環

(1)語法格式

? ? ? ? 循環名:loop

? ? ? ? ? ? ? ? -- 循環體

? ? ? ? ? ? ? ? [ leave \ iterate ]?循環名;

? ? ? ? end loop;

# leave:類似于 Java 中的 break,結束當前循環;

# iterate:類似于 Java 中的 continue,結束本次循環。


(2)leave 實例?

? ? ? ? 輸出 1 ~ 6。

drop procedure if exists p9;create procedure p9()
begindeclare i int default 0;num:loopset i := i + 1;if i = 7then leave num;end if;select i;end loop;
end;call p9();


(3)iterate 實例

????????輸出 1、2、3、4、6、7、8、9。

drop procedure if exists p10;create procedure p10()
begindeclare i int default 0;num:loopset i := i + 1;if i = 11then leave num;elseif i = 5then iterate num;elseif i = 10then iterate num;end if;select i;end loop;
end;call p10();


八、游標 cursor

1.說明

  1. 游標是指向結果集中某條記錄的指針,允許程序逐個訪問結果集中的每條記錄,并進行逐行操作;
  2. 使用游標需要在存儲過程或函數中定義一個游標變量,并通過【declare】進行聲明和初始化;
  3. 使用【open】開啟游標;
  4. 使用【fetch】逐行獲取游標指向的記錄并處理;
  5. 最后使用【close】關閉游標,釋放資源;
  6. 聲明游標的語句必須在聲明普通變量的下方。

2.步驟

(1)聲明

? ? ? ? declare 游標名稱 cursor for 查詢語句;


(2)開啟

? ? ? ? ?open 游標名稱;


(3)獲取

? ? ? ? fetch 游標名稱 into 變量1, 變量2, …;?


(4)關閉

? ? ? ? close 游標名稱;?


3.實例?

? ? ? ? 從 二 中的 human 表中查詢 name 和 gender,并插入一張新表 human_summary。

drop procedure if exists p11;create procedure p11()
begin-- 聲明變量declare human_name varchar(10);declare human_gender char(2);-- 聲明游標declare human_cursor cursor for select `name`, gender from human;-- 新建 human_summary 表drop table if exists human_summary;create table human_summary(id int primary key auto_increment,`name` varchar(10),gender char(2) default '未知');-- 開啟游標open human_cursor;-- 循環獲取數據while true dofetch human_cursor into human_name, human_gender;-- 插入數據insert into human_summary(`name`, gender) values(human_name, human_gender);end while;-- 關閉游標close human_cursor;
end;call p11();


?九、捕捉并處理異常

1.說明

  1. 語法格式:【declare [ 異常處理程序名 ] handler for [ SQL狀態碼 ] [ 執行語句 ];】;
  2. 異常處理程序
    1. continue:發生異常后,程序不終止,正常執行后續過程。即捕捉;
    2. exit:發生異常后,終止存儲過程的執行。即上拋。
  3. SQL 狀態碼
    1. 可以填具體的數字狀態碼;
    2. SQLWARNING:代表所有 01 開始的 SQL 狀態碼;
    3. NOT FOUND:代表所有 02 開始的 SQL 狀態碼;
    4. SQLEXCEPTION:代表所有除 01、02 開始的 SQL 狀態碼。
  4. 執行語句:異常發生時執行的語句。

2.實例?

? ? ? ? 上述游標中的實例,執行時會報錯,因為循環是死循環。

????????那么,如何改進呢?

drop procedure if exists p11;create procedure p11()
begindeclare human_name varchar(10);declare human_gender char(2);declare human_cursor cursor for select `name`, gender from human;-- 異常處理,在發生未發現異常時終止并關閉游標declare exit handler for not found close human_cursor;drop table if exists human_summary;create table human_summary(id int primary key auto_increment,`name` varchar(10),gender char(2) default '未知');open human_cursor;while true dofetch human_cursor into human_name, human_gender;insert into human_summary(`name`, gender) values(human_name, human_gender);end while;close human_cursor;
end;call p11();

十、存儲函數

1.說明

  1. 存儲函數是帶有返回值的存儲過程;
  2. 參數只能是 in,但不能顯示地寫 in。沒有 out 和 inout。

2.語法格式

????????create function 存儲函數名稱(參數列表) returns 數據類型 [ 特征 ]

? ? ? ? begin

? ? ? ? ? ? ? ? -- 函數體

? ? ? ? return …;

? ? ? ? end;

# 特征重要取值:

  1. deterministic:標記該函數為確定性函數,即每次調用函數時,傳入相同的參數,返回值是固定的。這是一種優化策略,此情況下全部函數體的執行會省略,直接返回之前緩存的結果,提高函數的執行效率;
  2. no sql:標記該函數執行過程不會查詢數據庫,以向 MySQL 優化器表示不需要使用查詢緩存和優化器緩存優化。避免不必要的查詢消耗;
  3. reads sql data:標記該函數會進行查詢操作,以向 MySQL 優化器表示該函數需要查詢數據庫,可以使用查詢緩存優化。同時 MySQL 還會進行優化器緩存處理。

3.實例

? ? ? ? 傳入整數 n,計算 1 ~ n 中所有偶數和。

drop function if exists f;create function f(n int) returns int deterministic
begindeclare sum int default 0;while n > 0 doif n % 2 = 0 then set sum := sum + n;end if;set n := n - 1;end while;return sum;
end;set @result := f(10);
select @result;


十一、觸發器

1.說明

  1. MySQL 觸發器是一種數據庫對象, 是與表相關聯的特殊程序;

  2. 可以在 插入、更新、刪除 觸發時自動執行;

  3. 作用

    1. 強制實施業務規則:可以確保表中業務規則強制執行;

    2. 數據審計:可以聲明在執行數據修改時自動記錄日志或審計數據變化的操作;

    3. 執行特定業務操作:可以自動執行特定業務操作。

  4. 分類

    1. before:在執行 insert、update、delete 語句之前執行;

    2. after:在執行 insert、update、delete 語句之后執行。

  5. 觸發器是一種數據庫高級功能,只在必要條件下使用。過量的觸發器和復雜的觸發器邏輯可能會影響查詢性能和擴展性。


2.語法規則?

? ? ? ? create trigger 觸發器名稱 [ before \ after ] [ insert \ update \ delete ] on 表名 for each row

? ? ? ? begin

? ? ? ? ? ? ? ? -- 觸發器執行的 SQL 語句

? ? ? ? end;


3.關鍵字 new、old

  1. new 和 old 是兩個特殊的關鍵字,用于引用在觸發器中修改前后的舊值、新值。
    1. new:觸發 insert 或 update 操作期間,new 用于引用將要插入或更新到表中新行的值;
    2. old:出發 update 和 delete 操作期間,old 用于引用更新或刪除之前在表中舊行的值。
  2. 可以像引用其他列一樣引用 new 和 old。

4.實例

# 1.首先,初始化一個日志表 log
drop table if exists log;
create table log(id bigint primary key auto_increment,table_name varchar(255) not null,operate varchar(10) not null,time datetime not null,operate_id bigint not null,description text 
);
# 2.向 human 表插入的觸發器
drop trigger if exists trigger_human_insert;
create trigger trigger_human_insert after insert on human for each row
begininsert into log(table_name, operate, time, operate_id, description) values('human', '新增', now(), new.id, concat('插入:id = ', new.id, ',name = ', new.name, ',gender = ', new.gender, ',age = ', new.age, ',phone = ', new.phone));
end;-- 查詢 log 日志表
select * from log;-- 向 human 表插入一條新數據
insert into human values(null, '柳梓熙', '女', '24', '18333256677');-- 查詢 log 日志表
select * from log;
# 3.向 human 表更新的觸發器
drop trigger if exists trigger_human_update;
create trigger trigger_human_update after update on human for each row
begininsert into log values(null, 'human', '更新', now(), new.id, concat('更新:[原數據:name = ', old.name, ',gender = ', old.gender, ',age = ', old.age, ',phone = ', old.phone, '];[新數據:name = ', new.name, ',gender = ', new.gender, ',age = ', new.age, ',phone = ', new.phone, ']'));
end;-- 查詢 log 日志表
select * from log;-- 向 human 表修改一條新數據
update human set name = '劉梓琪' where id = 4;-- 查詢 log 日志表
select * from log;
# 4.向 human 表刪除的觸發器
drop trigger if exists trigger_human_delete;
create trigger trigger_human_delete after delete on human for each row
begininsert into log values(null, 'human', '刪除', now(), old.id, concat('刪除:name = ', old.name, ',gender = ', old.gender, ',age = ', old.age, ',phone = ', old.phone));
end;-- 查詢 log 日志表
select * from log;-- 向 human 表刪除一條新數據
delete from human where name = '劉梓琪';-- 查詢 log 日志表
select * from log;

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/pingmian/82081.shtml
繁體地址,請注明出處:http://hk.pswp.cn/pingmian/82081.shtml
英文地址,請注明出處:http://en.pswp.cn/pingmian/82081.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

動態規劃dp

這里寫目錄標題 動態規劃01背包完全背包多重背包混合背包二維費用的背包分組背包有依賴的背包背包問題求方案數背包問題求具體方案數位 DP狀壓 DP常用例題 動態規劃 01背包 有 n n n 件物品和一個容量為 W W W 的背包&#xff0c;第 i i i 件物品的體積為 w [ i ] w[i] w…

arcgis js統計FeatureLayer的橢球面積、平面面積

1、導入依賴 import FeatureLayer from arcgis/core/layers/FeatureLayer import { geodesicArea, planarArea, simplify } from arcgis/core/geometry/geometryEngine; import { project, load as projectionLoad } from arcgis/core/geometry/projection2、初始化project o…

2.2.1 05年T2

引言 本文將從一預習、二自習、三學習、四復習等四個階段來分析2005年考研英語閱讀第二篇文章。為了便于后續閱讀&#xff0c;我將第四部分復習放在了首位。 四、復習 方法&#xff1a;錯誤思路分析總結考點文章梳理 4.1 錯題分析 題目&#xff1a;26&#xff08;細節題&…

Java 連接并操作 Redis 萬字詳解:從 Jedis 直連到 RedisTemplate 封裝,5 種方式全解析

引言 在分布式系統和高并發場景中&#xff0c;Redis 作為高性能內存數據庫的地位舉足輕重。對于 Java 開發者而言&#xff0c;掌握 Redis 的連接與操作是進階必備技能。然而&#xff0c;從基礎的 Jedis 原生客戶端到 Spring 封裝的 RedisTemplate&#xff0c;不同連接方式的原…

談談對《加密算法》的理解

文章目錄 一、什么是加密算法&#xff1f;二、常見的加密算法有哪些&#xff1f;2.1 對稱加密2.2 非對稱加密2.3 哈希算法 三、加密算法代碼展示3.1 MD5加密3.2 秘鑰加密3.3 AES加密解密 四、加密算法的使用場景 一、什么是加密算法&#xff1f; 加密算法是一種通過數學方法將…

Fuzz 模糊測試篇JS 算法口令隱藏參數盲 Payload未知文件目錄

1 、 Fuzz 是一種基于黑盒的自動化軟件模糊測試技術 , 簡單的說一種懶惰且暴力的技術融合了常見 的以及精心構建的數據文本進行網站、軟件安全性測試。 2 、 Fuzz 的核心思想 : 口令 Fuzz( 弱口令 ) 目錄 Fuzz( 漏洞點 ) 參數 Fuzz( 利用參數 ) PayloadFuzz(Bypass)…

哈希表的實現(下)

目錄 前言 開散列概念 開散列實現 Insert 優化 Find Erase 前言 上一章節我們用閉散列實現了一下哈希表&#xff0c;但存在一些問題&#xff0c;比如空間浪費比較嚴重&#xff0c;如果連續一段空間都已經存放值&#xff0c;那么在此位置插入新值的時候就會一直挪動&…

再談Linux 進程:進程等待、進程替換與環境變量

目錄 1.進程等待 為什么需要進程等待&#xff1f; 相關系統調用&#xff1a;wait()和waitpid() wait(): waitpid(): 解析子進程狀態&#xff08;status&#xff09; 2.進程替換 為什么需要進程替換&#xff1f; 相關系統調用&#xff1a;exec函數家族 3.環境變量 ?…

基于深度學習的無線電調制識別系統

基于深度學習的無線電調制識別系統 本項目實現了一個基于深度學習的無線電調制識別系統&#xff0c;使用LSTM&#xff08;長短期記憶網絡&#xff09;模型對不同類型的 無線電信號進行自動分類識別。該系統能夠在不同信噪比(SNR)條件下&#xff0c;準確識別多種調制類型&#…

Python 爬蟲之requests 模塊的應用

requests 是用 python 語言編寫的一個開源的HTTP庫&#xff0c;可以通過 requests 庫編寫 python 代碼發送網絡請求&#xff0c;其簡單易用&#xff0c;是編寫爬蟲程序時必知必會的一個模塊。 requests 模塊的作用 發送網絡請求&#xff0c;獲取響應數據。 中文文檔&#xf…

隨機森林(Random Forest)學習

隨機森林是一種基于集成學習的機器學習算法&#xff0c;屬于Bagging&#xff08;Bootstrap Aggregating&#xff09;方法的一種擴展。它通過組合多個決策樹來提升模型的泛化能力和魯棒性&#xff0c;廣泛用于分類、回歸和特征選擇任務。 1.隨機森林核心思想 1.1少數服從多數 在…

從 0 到 1!Java 并發編程基礎全解析,零基礎入門必看!

寫在前面 博主在之前寫了很多關于并發編程深入理解的系列文章&#xff0c;有博友反饋說對博主的文章表示非常有收獲但是對作者文章的某些基礎描述有些模糊&#xff0c;所以博主再根據最能接觸到的基礎&#xff0c;為這類博友進行掃盲&#xff01;當然&#xff0c;后續仍然會接…

el-input寬度自適應方法總結

使用 style 或 class 直接設置寬度 可以通過內聯樣式或 CSS 類來直接設置 el-input 的寬度為 100%&#xff0c;使其自適應父容器的寬度 <template><div style"width: 100%;"><el-input style"width: 100%;" v-model"input">…

解決 Supabase “permission denied for table XXX“ 錯誤

解決 Supabase “permission denied for table” 錯誤 問題描述 在使用 Supabase 開發應用時&#xff0c;你可能會遇到以下錯誤&#xff1a; [Nest] ERROR [ExceptionsHandler] Object(4) {code: 42501,details: null,hint: null,message: permission denied for table user…

java每日精進 5.20【MyBatis 聯表分頁查詢】

1. MyBatis XML 實現分頁查詢 1.1 實現方式 MyBatis XML 是一種傳統的 MyBatis 使用方式&#xff0c;通過在 XML 文件中編寫 SQL 語句&#xff0c;并結合 Mapper 接口和 Service 層實現分頁查詢。分頁需要手動編寫兩條 SQL 語句&#xff1a;一條查詢分頁數據列表&#xff0c;…

linux taskset 查詢或設置進程綁定CPU

1、安裝 taskset larkubuntu&#xff1a;~$ sudo apt-get install util-linux larkubuntu&#xff1a;~$ taskset --help 用法&#xff1a; taskset [選項] [mask | cpu-list] [pid|cmd [args...]] 顯示或更改進程的 CPU 關聯性。 選項&#xff1a; -a&#xff0c; --all-tasks…

Python應用字符串格式化初解

大家好!在 Python 編程中&#xff0c;字符串格式化是一項基礎且實用的技能。它能讓你更靈活地拼接字符串與變量&#xff0c;使輸出信息更符合需求。本文將為和我一樣的初學者詳細介紹 Python 字符串格式化的常用方法。 定義: 字符串格式化就是將變量或數據插入到字符串中的特定…

EasyRTC嵌入式音視頻通信SDK一對一音視頻通信,打造遠程辦公/醫療/教育等場景解決方案

一、方案概述? 數字技術發展促使在線教育、遠程醫療等行業對一對一實時音視頻通信需求激增。傳統方式存在低延遲、高畫質及多場景適配不足等問題&#xff0c;而EasyRTC憑借音視頻處理、高效信令交互與智能網絡適配技術&#xff0c;打造穩定低延遲通信&#xff0c;滿足基礎通信…

SEO長尾詞優化精準布局

內容概要 長尾關鍵詞作為SEO策略的核心要素&#xff0c;其價值在于精準捕捉細分需求與低競爭流量入口。相較于短尾詞的高泛化性&#xff0c;長尾詞通過語義擴展與場景化組合&#xff0c;能夠更高效地匹配用戶搜索意圖&#xff0c;降低優化成本的同時提升轉化潛力。本文將從詞庫…

【MySQL】第7節|Mysql鎖機制與優化實踐以及MVCC底層原理剖析

鎖等待分析 我們通過檢查InnoDB_row_lock相關的狀態變量來分析系統上的行鎖的爭奪情況 示例場景 假設有兩個用戶同時操作賬戶表 accounts&#xff08;主鍵為 id&#xff09;&#xff1a; 1. 用戶A&#xff1a;執行轉賬&#xff0c;鎖定賬戶 id1 并等待3秒&#xff1a; BEG…