登錄壓測時,需要很多不同的用戶,此時需要向數(shù)據(jù)庫新增數(shù)據(jù)
#批量添加用戶賬號——存儲過程:
delimiter //
drop procedure if exists test;
create procedure test()
begin
DECLARE i int;
set i = 1;
while i21 do
insert into hg_user values (concat("OM_TEST",cast(i as CHAR)),concat("OM_TEST",cast(i as CHAR)),"F1B2F5B9FBC8B513",null,null,null,null,null,null,null,null,null,null,null,null,null,null,null);
set i = i+1;
end while;
select * from test;
end//
call test();
delimiter是mysql分隔符,在mysql客戶端中分隔符默認(rèn)是分號(;)。
如果一次輸入的語句較多,并且語句中間有分號,這時需要新指定一個特殊的分隔符,常用//,。
上面就是,先將分隔符設(shè)置為 //,
直到遇到下一個 //,才整體執(zhí)行語句。
執(zhí)行完后,最后一行, delimiter ; 將mysql的分隔符重新設(shè)置為分號;
如果不修改的話,本次會話中的所有分隔符都以// 為準(zhǔn)。
concat 是字符連接,將多個字符串連接成一個字符串.
語法:concat(str1, str2,...)
eg:select concat (id, name, score) as info from tt2; 1小明60
cast函數(shù)用于將某種數(shù)據(jù)類型的表達(dá)式顯式轉(zhuǎn)換為另一種數(shù)據(jù)類型。
語法:CAST (expression AS data_type)
可以轉(zhuǎn)換的類型是有限制的。這個類型可以是以下值其中的一個:
- 二進(jìn)制,同帶binary前綴的效果 : BINARY
- 字符型,可帶參數(shù) : CHAR()
- 日期 : DATE
- 時間: TIME
- 日期時間型 : DATETIME
- 浮點數(shù) : DECIMAL
- 整數(shù) : SIGNED
- 無符號整數(shù) : UNSIGNED
批量刪除方案(刪除用戶也一樣)
#刪除解決方案——存儲過程;
delimiter //
drop procedure if exists test;
create procedure test()
begin
DECLARE i int;
set i = 1;
while i11 do
DELETE from hg_application_flow_template where user_name=concat("OM_TEST",cast(i as CHAR));
DELETE from hg_application_flow_template_details where created_by=concat("OM_TEST",cast(i as CHAR));
set i = i+1;
end while;
select * from test;
end//
call test();
總結(jié)
到此這篇關(guān)于mysql批量新增和存儲的文章就介紹到這了,更多相關(guān)mysql批量新增存儲內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:- Mysql使用insert插入多條記錄 批量新增數(shù)據(jù)
- mybatis學(xué)習(xí)之路mysql批量新增數(shù)據(jù)的方法
- MySQL分表實現(xiàn)上百萬上千萬記錄分布存儲的批量查詢設(shè)計模式詳解