0,'成功','失败'); # 使用\r","marks":[]}]}]},{"type":"block","id":"VzTG-1657635128282","name":"code-line","data":{},"nodes":[{"type":"text","id":"3UVZ-1657635128281","leaves":[{"text":"end $\r","marks":[]}]}]},{"type":"block","id":"ZtL6-1657635128284","name":"code-line","data":{},"nodes":[{"type":"text","id":"dsyR-1657635128283","leaves":[{"text":"\r","marks":[]}]}]},{"type":"block","id":"cped-1657635128286","name":"code-line","data":{},"nodes":[{"type":"text","id":"9zsr-1657635128285","leaves":[{"text":"-- 调用\r","marks":[]}]}]},{"type":"block","id":"IrJq-1657635128288","name":"code-line","data":{},"nodes":[{"type":"text","id":"8lDT-1657635128287","leaves":[{"text":"call myp3('john','18888');\r","marks":[]}]}]},{"type":"block","id":"vaVp-1657635128290","name":"code-line","data":{},"nodes":[{"type":"text","id":"xsVV-1657635128289","leaves":[{"text":"\r","marks":[]}]}]},{"type":"block","id":"SOTz-1657635128292","name":"code-line","data":{},"nodes":[{"type":"text","id":"ar2b-1657635128291","leaves":[{"text":"-- 3、创建带out模式的存储过程\r","marks":[]}]}]},{"type":"block","id":"tE1n-1657635128294","name":"code-line","data":{},"nodes":[{"type":"text","id":"Rng4-1657635128293","leaves":[{"text":"# 案例1:根据女神名,返回对应的男神名\r","marks":[]}]}]},{"type":"block","id":"pKKW-1657635128296","name":"code-line","data":{},"nodes":[{"type":"text","id":"xcIN-1657635128295","leaves":[{"text":"/* 在存储过程定义时,存储体是select查询语句的情况下,如果参数没有定义out模式的参数或者打印变量,执行后的结果会自动打印显示,如果定义了out模式的参数,那么在调用的时候必须定义一个变量去接收才会打印显示结果\r","marks":[]}]}]},{"type":"block","id":"0Fbm-1657635128298","name":"code-line","data":{},"nodes":[{"type":"text","id":"UI2e-1657635128297","leaves":[{"text":"*/\r","marks":[]}]}]},{"type":"block","id":"K3tn-1657635128300","name":"code-line","data":{},"nodes":[{"type":"text","id":"RMHQ-1657635128299","leaves":[{"text":"delimiter $\r","marks":[]}]}]},{"type":"block","id":"IOO0-1657635128302","name":"code-line","data":{},"nodes":[{"type":"text","id":"L1ft-1657635128301","leaves":[{"text":"create procedure myp4(in bwname varchar(50),out bmname varchar(50))\r","marks":[]}]}]},{"type":"block","id":"DgfO-1657635128304","name":"code-line","data":{},"nodes":[{"type":"text","id":"pl7g-1657635128303","leaves":[{"text":"begin\r","marks":[]}]}]},{"type":"block","id":"vZHg-1657635128306","name":"code-line","data":{},"nodes":[{"type":"text","id":"ZdmG-1657635128305","leaves":[{"text":"select bs.boyName into bmname\r","marks":[]}]}]},{"type":"block","id":"coaz-1657635128308","name":"code-line","data":{},"nodes":[{"type":"text","id":"uvH1-1657635128307","leaves":[{"text":"from beauty b join boys bs on b.boyfriend_id=bs.id where b.name=bwname;\r","marks":[]}]}]},{"type":"block","id":"s6nL-1657635128310","name":"code-line","data":{},"nodes":[{"type":"text","id":"zF8t-1657635128309","leaves":[{"text":"end $\r","marks":[]}]}]},{"type":"block","id":"eVr3-1657635128312","name":"code-line","data":{},"nodes":[{"type":"text","id":"3XfN-1657635128311","leaves":[{"text":"\r","marks":[]}]}]},{"type":"block","id":"4O29-1657635128315","name":"code-line","data":{},"nodes":[{"type":"text","id":"ggqR-1657635128314","leaves":[{"text":"-- 调用\r","marks":[]}]}]},{"type":"block","id":"tUFS-1657635128317","name":"code-line","data":{},"nodes":[{"type":"text","id":"X7Wv-1657635128316","leaves":[{"text":"-- 需要先定义一个用户变量接收男神名\r","marks":[]}]}]},{"type":"block","id":"nmSl-1657635128319","name":"code-line","data":{},"nodes":[{"type":"text","id":"5kQv-1657635128318","leaves":[{"text":"set @bmname=''; -- 该步骤可以省略,直接在调用时写上用户变量\r","marks":[]}]}]},{"type":"block","id":"XCnL-1657635128321","name":"code-line","data":{},"nodes":[{"type":"text","id":"3DvE-1657635128320","leaves":[{"text":"call myp4('Angelababy',@bmname);\r","marks":[]}]}]},{"type":"block","id":"sNpc-1657635128323","name":"code-line","data":{},"nodes":[{"type":"text","id":"gbKf-1657635128322","leaves":[{"text":"select @bmname;\r","marks":[]}]}]},{"type":"block","id":"6Qlg-1657635128325","name":"code-line","data":{},"nodes":[{"type":"text","id":"ZpSo-1657635128324","leaves":[{"text":"\r","marks":[]}]}]},{"type":"block","id":"UCm3-1657635128327","name":"code-line","data":{},"nodes":[{"type":"text","id":"YVkH-1657635128326","leaves":[{"text":"-- 删除指定的存储过程(调试用)\r","marks":[]}]}]},{"type":"block","id":"qAUZ-1657635128329","name":"code-line","data":{},"nodes":[{"type":"text","id":"vYNy-1657635128328","leaves":[{"text":"drop procedure myp5;\r","marks":[]}]}]},{"type":"block","id":"FSEb-1657635128331","name":"code-line","data":{},"nodes":[{"type":"text","id":"XJ9L-1657635128330","leaves":[{"text":"# 案例2:根据女神名,返回对应的男神明和男生魅力值\r","marks":[]}]}]},{"type":"block","id":"pwDo-1657635128333","name":"code-line","data":{},"nodes":[{"type":"text","id":"jJcf-1657635128332","leaves":[{"text":"delimiter $\r","marks":[]}]}]},{"type":"block","id":"xjqh-1657635128336","name":"code-line","data":{},"nodes":[{"type":"text","id":"VNty-1657635128334","leaves":[{"text":"create procedure myp5(in bwname varchar(50),out bmname varchar(50),out cpnum int)\r","marks":[]}]}]},{"type":"block","id":"iVoM-1657635128338","name":"code-line","data":{},"nodes":[{"type":"text","id":"xpaN-1657635128337","leaves":[{"text":"begin\r","marks":[]}]}]},{"type":"block","id":"BjDS-1657635128340","name":"code-line","data":{},"nodes":[{"type":"text","id":"RWzC-1657635128339","leaves":[{"text":"select bs.boyName,bs.userCP into bmname,cpnum\r","marks":[]}]}]},{"type":"block","id":"lrEK-1657635128342","name":"code-line","data":{},"nodes":[{"type":"text","id":"CUyM-1657635128341","leaves":[{"text":"from beauty b join boys bs on b.boyfriend_id=bs.id where b.name=bwname;\r","marks":[]}]}]},{"type":"block","id":"BVKM-1657635128344","name":"code-line","data":{},"nodes":[{"type":"text","id":"80N2-1657635128343","leaves":[{"text":"end $\r","marks":[]}]}]},{"type":"block","id":"QeYG-1657635128346","name":"code-line","data":{},"nodes":[{"type":"text","id":"RutX-1657635128345","leaves":[{"text":"-- 调用\r","marks":[]}]}]},{"type":"block","id":"vylb-1657635128348","name":"code-line","data":{},"nodes":[{"type":"text","id":"iUuj-1657635128347","leaves":[{"text":"call myp5('Angelababy',@bmname,@cpnum);\r","marks":[]}]}]},{"type":"block","id":"4fZU-1657635128350","name":"code-line","data":{},"nodes":[{"type":"text","id":"UPzq-1657635128349","leaves":[{"text":"select @bmname,@cpnum;\r","marks":[]}]}]},{"type":"block","id":"Lblu-1657635128352","name":"code-line","data":{},"nodes":[{"type":"text","id":"bEij-1657635128351","leaves":[{"text":"\r","marks":[]}]}]},{"type":"block","id":"wqDK-1657635128355","name":"code-line","data":{},"nodes":[{"type":"text","id":"mzCC-1657635128353","leaves":[{"text":"\r","marks":[]}]}]},{"type":"block","id":"Eth0-1657635128357","name":"code-line","data":{},"nodes":[{"type":"text","id":"ahFO-1657635128356","leaves":[{"text":"-- 4、带inout模式的参数的存储过程\r","marks":[]}]}]},{"type":"block","id":"F6QG-1657635128359","name":"code-line","data":{},"nodes":[{"type":"text","id":"XCYy-1657635128358","leaves":[{"text":"-- 案例:传入a和b,最终a和b都翻倍并返回\r","marks":[]}]}]},{"type":"block","id":"E9UC-1657635128361","name":"code-line","data":{},"nodes":[{"type":"text","id":"nSPQ-1657635128360","leaves":[{"text":"delimiter $\r","marks":[]}]}]},{"type":"block","id":"6Lpj-1657635128363","name":"code-line","data":{},"nodes":[{"type":"text","id":"kTy6-1657635128362","leaves":[{"text":"create procedure myp6(inout a int,inout b int)\r","marks":[]}]}]},{"type":"block","id":"zOna-1657635128365","name":"code-line","data":{},"nodes":[{"type":"text","id":"cFVW-1657635128364","leaves":[{"text":"begin\r","marks":[]}]}]},{"type":"block","id":"G7ds-1657635128367","name":"code-line","data":{},"nodes":[{"type":"text","id":"Bl92-1657635128366","leaves":[{"text":"SELECT a*2,b*2 into a,b;\r","marks":[]}]}]},{"type":"block","id":"e3b5-1657635128369","name":"code-line","data":{},"nodes":[{"type":"text","id":"RMfP-1657635128368","leaves":[{"text":"end $\r","marks":[]}]}]},{"type":"block","id":"48iN-1657635128371","name":"code-line","data":{},"nodes":[{"type":"text","id":"JZIO-1657635128370","leaves":[{"text":"\r","marks":[]}]}]},{"type":"block","id":"Rgjq-1657635128373","name":"code-line","data":{},"nodes":[{"type":"text","id":"oA4d-1657635128372","leaves":[{"text":"-- 调用(inout调用时需要先定义和已封装的存储过程数量一致的变量并赋值,然后传入存储过程)\r","marks":[]}]}]},{"type":"block","id":"Yfwm-1657635128375","name":"code-line","data":{},"nodes":[{"type":"text","id":"R1qQ-1657635128374","leaves":[{"text":"set @c=5;\r","marks":[]}]}]},{"type":"block","id":"lMyF-1657635128377","name":"code-line","data":{},"nodes":[{"type":"text","id":"6yac-1657635128376","leaves":[{"text":"set @d=6;\r","marks":[]}]}]},{"type":"block","id":"2E6d-1657635128379","name":"code-line","data":{},"nodes":[{"type":"text","id":"H35O-1657635128378","leaves":[{"text":"call myp6(@c,@d);\r","marks":[]}]}]},{"type":"block","id":"MgRw-1657635128381","name":"code-line","data":{},"nodes":[{"type":"text","id":"rsFg-1657635128380","leaves":[{"text":"select @c,@d;","marks":[]}]}]},{"type":"block","id":"EahB-1657711820896","name":"code-line","data":{},"nodes":[{"type":"text","id":"hCsA-1657711820893","leaves":[{"text":"","marks":[]}]}]},{"type":"block","id":"9RaW-1657711821168","name":"code-line","data":{},"nodes":[{"type":"text","id":"YeNC-1657711821167","leaves":[{"text":"","marks":[]}]}]},{"type":"block","id":"KHuR-1657711821277","name":"code-line","data":{},"nodes":[{"type":"text","id":"P5My-1657711821276","leaves":[{"text":"","marks":[]}]}]},{"type":"block","id":"Lwft-1657711821581","name":"code-line","data":{},"nodes":[{"type":"text","id":"wEOX-1657711821579","leaves":[{"text":"","marks":[]}]}]},{"type":"block","id":"G6MC-1657711821763","name":"code-line","data":{},"nodes":[{"type":"text","id":"E9PK-1657711821762","leaves":[{"text":"\r","marks":[]}]}]},{"type":"block","id":"w5gK-1657711822566","name":"code-line","data":{},"nodes":[{"type":"text","id":"emIt-1657711822565","leaves":[{"text":"# 1、创建存储过程或函数实现传入用户名和密码,插入到admin表中\r","marks":[]}]}]},{"type":"block","id":"6v1n-1657711822568","name":"code-line","data":{},"nodes":[{"type":"text","id":"xQAY-1657711822567","leaves":[{"text":"delimiter $\r","marks":[]}]}]},{"type":"block","id":"UsyZ-1657711822570","name":"code-line","data":{},"nodes":[{"type":"text","id":"g3CQ-1657711822569","leaves":[{"text":"create procedure myp7 (in username varchar(20),in password varchar(20))\r","marks":[]}]}]},{"type":"block","id":"6JdM-1657711822572","name":"code-line","data":{},"nodes":[{"type":"text","id":"bkWF-1657711822571","leaves":[{"text":"begin\r","marks":[]}]}]},{"type":"block","id":"OwEa-1657711822574","name":"code-line","data":{},"nodes":[{"type":"text","id":"wREq-1657711822573","leaves":[{"text":"insert into admin set admin.username=username,admin.password=password;\r","marks":[]}]}]},{"type":"block","id":"6j8R-1657711822576","name":"code-line","data":{},"nodes":[{"type":"text","id":"yZi6-1657711822575","leaves":[{"text":"end $\r","marks":[]}]}]},{"type":"block","id":"fVfH-1657711822578","name":"code-line","data":{},"nodes":[{"type":"text","id":"xPPM-1657711822577","leaves":[{"text":"\r","marks":[]}]}]},{"type":"block","id":"zmJd-1657711822580","name":"code-line","data":{},"nodes":[{"type":"text","id":"dwBl-1657711822579","leaves":[{"text":"call myp7('群员站岗','888888888');\r","marks":[]}]}]},{"type":"block","id":"7b0C-1657711822582","name":"code-line","data":{},"nodes":[{"type":"text","id":"cKTD-1657711822581","leaves":[{"text":"select * from admin;\r","marks":[]}]}]},{"type":"block","id":"lvtt-1657711822584","name":"code-line","data":{},"nodes":[{"type":"text","id":"TtTW-1657711822583","leaves":[{"text":"# 2、创建存储过程或函数实现传入女神编号,返回女神名称和女神电话\r","marks":[]}]}]},{"type":"block","id":"bQVG-1657711822586","name":"code-line","data":{},"nodes":[{"type":"text","id":"TmnV-1657711822585","leaves":[{"text":"-- 手机号用int存会超出范围\r","marks":[]}]}]},{"type":"block","id":"6Cmn-1657711822589","name":"code-line","data":{},"nodes":[{"type":"text","id":"q6KM-1657711822588","leaves":[{"text":"delimiter $\r","marks":[]}]}]},{"type":"block","id":"imJw-1657711822591","name":"code-line","data":{},"nodes":[{"type":"text","id":"uaXZ-1657711822590","leaves":[{"text":"create procedure myp8(in wnum int,out wname varchar(20),out whone bigint)\r","marks":[]}]}]},{"type":"block","id":"1aXF-1657711822593","name":"code-line","data":{},"nodes":[{"type":"text","id":"JRBK-1657711822592","leaves":[{"text":"begin\r","marks":[]}]}]},{"type":"block","id":"6J0q-1657711822595","name":"code-line","data":{},"nodes":[{"type":"text","id":"JL85-1657711822594","leaves":[{"text":"select name,phone into wname,whone from beauty where id=wnum;\r","marks":[]}]}]},{"type":"block","id":"EKcN-1657711822597","name":"code-line","data":{},"nodes":[{"type":"text","id":"jGr7-1657711822596","leaves":[{"text":"end $\r","marks":[]}]}]},{"type":"block","id":"M7o2-1657711822599","name":"code-line","data":{},"nodes":[{"type":"text","id":"yrDg-1657711822598","leaves":[{"text":"\r","marks":[]}]}]},{"type":"block","id":"jl0d-1657711822601","name":"code-line","data":{},"nodes":[{"type":"text","id":"xofk-1657711822600","leaves":[{"text":"-- 调用\r","marks":[]}]}]},{"type":"block","id":"vxUb-1657711822603","name":"code-line","data":{},"nodes":[{"type":"text","id":"WPys-1657711822602","leaves":[{"text":"call myp8(1,@wn,@wh);\r","marks":[]}]}]},{"type":"block","id":"hCTj-1657711822605","name":"code-line","data":{},"nodes":[{"type":"text","id":"QqYv-1657711822604","leaves":[{"text":"select @wn,@wh;\r","marks":[]}]}]},{"type":"block","id":"b5Qs-1657711822607","name":"code-line","data":{},"nodes":[{"type":"text","id":"9zmH-1657711822606","leaves":[{"text":"\r","marks":[]}]}]},{"type":"block","id":"2FQF-1657711822609","name":"code-line","data":{},"nodes":[{"type":"text","id":"pmci-1657711822608","leaves":[{"text":"# 3、创建存储过程或函数实现传入两个女神生日,返回大小\r","marks":[]}]}]},{"type":"block","id":"5veC-1657711822611","name":"code-line","data":{},"nodes":[{"type":"text","id":"wJvO-1657711822610","leaves":[{"text":"delimiter $\r","marks":[]}]}]},{"type":"block","id":"Oq9t-1657711822613","name":"code-line","data":{},"nodes":[{"type":"text","id":"YIcy-1657711822612","leaves":[{"text":"create procedure myp9(in none datetime,in ntwo datetime,out result varchar(20))\r","marks":[]}]}]},{"type":"block","id":"x4hL-1657711822615","name":"code-line","data":{},"nodes":[{"type":"text","id":"XcBl-1657711822614","leaves":[{"text":"begin\r","marks":[]}]}]},{"type":"block","id":"flJb-1657711822617","name":"code-line","data":{},"nodes":[{"type":"text","id":"KwQT-1657711822616","leaves":[{"text":"select DATEDIFF(none,ntwo) into result;\r","marks":[]}]}]},{"type":"block","id":"Telc-1657711822619","name":"code-line","data":{},"nodes":[{"type":"text","id":"iO5u-1657711822618","leaves":[{"text":"end $\r","marks":[]}]}]},{"type":"block","id":"EK30-1657711822621","name":"code-line","data":{},"nodes":[{"type":"text","id":"vVGA-1657711822620","leaves":[{"text":"\r","marks":[]}]}]},{"type":"block","id":"GbLy-1657711822623","name":"code-line","data":{},"nodes":[{"type":"text","id":"rFry-1657711822622","leaves":[{"text":"-- 调用\r","marks":[]}]}]},{"type":"block","id":"Qegk-1657711822625","name":"code-line","data":{},"nodes":[{"type":"text","id":"XU9K-1657711822624","leaves":[{"text":"set @no='2022-01-06';\r","marks":[]}]}]},{"type":"block","id":"VmzY-1657711822627","name":"code-line","data":{},"nodes":[{"type":"text","id":"Xse8-1657711822626","leaves":[{"text":"set @nt='2022-01-05';\r","marks":[]}]}]},{"type":"block","id":"ONbV-1657711822629","name":"code-line","data":{},"nodes":[{"type":"text","id":"YbZv-1657711822628","leaves":[{"text":"call myp9(@no,@nt,@r);\r","marks":[]}]}]},{"type":"block","id":"TUNl-1657711822631","name":"code-line","data":{},"nodes":[{"type":"text","id":"aSSg-1657711822630","leaves":[{"text":"select @r;","marks":[]}]}]}],"state":{}},{"type":"block","id":"2t1b-1657635127248","name":"paragraph","data":{},"nodes":[{"type":"text","id":"YkaU-1657635127249","leaves":[{"text":"3、删除存储过程","marks":[]}]}],"state":{}},{"type":"block","id":"PwVN-1657711836691","name":"paragraph","data":{},"nodes":[{"type":"text","id":"q6o9-1657711836689","leaves":[{"text":"drop procedure 存储过程名;","marks":[]}]}],"state":{}},{"type":"block","id":"44I0-1657712397272","name":"paragraph","data":{},"nodes":[{"type":"text","id":"2SVQ-1657712397270","leaves":[{"text":"4、查看存储过程信息","marks":[]}]}],"state":{}},{"type":"block","id":"wfiB-1657712407439","name":"paragraph","data":{},"nodes":[{"type":"text","id":"O64c-1657712407437","leaves":[{"text":"show create procedure 存储过程名;","marks":[]}]}],"state":{}}]'>
一、存储过程和函数
存储过程和函数:类似于java中的方法
二、存储过程
一组预先编译好的sql语句的集合,可以理解为批处理语句
优点:
提高代码的重用性
简化操作
减少了编译次数并且减少了和数据库服务器的连接次数,提高效率
1、创建语法
create procedure 存储过程名(参数列表)
begin
存储过程体(一组合法的sql语句)
end
注意:
1、参数列表包含三部分:参数模式 参数名 参数类型
举例:in stuname varchar(20);
参数模式:(在存储过程定义时,存储体是select查询语句的情况下,如果参数没有定义out模式的参数或者打印变量,执行后的结果会自动打印显示,如果定义了out模式的参数,那么在调用的时候必须定义一个变量去接收才会打印显示结果)
in:该参数可以作为输入,也就是该参数需要调用方传入值
out:该参数可以作为输出,也就是该参数可以作为返回值
inout:该参数既可以作为输入又可以作为输出,也就是该参数既需要传入值,又可以返回值
2、如果存储过程体仅仅只有一句话,begin end可以省略
存储过程体中的每条sql语句的结尾要求必须加分号
存储过程的结尾可以使用delimiter重新设置
语法:
delimiter 结束标记;
3、调用语法
call 存储过程名(实参列表);
-- 1、空参列表 -- 案例:插入到admin表中五条记录 use girls; select * from admin; -- 设置结束标志 delimiter $ create procedure myp1() begin insert into admin(username,password) values ('a','1111'),('b','2222'),('c','3333'),('d','4444'),('e','5555'); end $ -- 调用 call myp1 (); -- 2、创建带in模式参数的存储过程 -- 案例1:创建存储过程实现 根据女神名查询对应的男神信息 delimiter $ create procedure myp2(in bname varchar(50)) begin select bs.* from beauty b join boys bs on b.boyfriend_id=bs.id where b.name=bname; end $ -- 调用 call myp2('Angelababy'); -- 案例2:创建存储过程实现,用户是否登录成功 delimiter $ create procedure myp3(in username varchar(50),in password varchar(50)) begin declare result int default 0; # 声明并初始化 -- 因为参数名和表列名相同,所以表列名需要加上表名进行声明 select count(*) into result # 赋值 from admin where admin.username=username and admin.password=password; select if(result>0,'成功','失败'); # 使用 end $ -- 调用 call myp3('john','18888'); -- 3、创建带out模式的存储过程 # 案例1:根据女神名,返回对应的男神名 /* 在存储过程定义时,存储体是select查询语句的情况下,如果参数没有定义out模式的参数或者打印变量,执行后的结果会自动打印显示,如果定义了out模式的参数,那么在调用的时候必须定义一个变量去接收才会打印显示结果 */ delimiter $ create procedure myp4(in bwname varchar(50),out bmname varchar(50)) begin select bs.boyName into bmname from beauty b join boys bs on b.boyfriend_id=bs.id where b.name=bwname; end $ -- 调用 -- 需要先定义一个用户变量接收男神名 set @bmname=''; -- 该步骤可以省略,直接在调用时写上用户变量 call myp4('Angelababy',@bmname); select @bmname; -- 删除指定的存储过程(调试用) drop procedure myp5; # 案例2:根据女神名,返回对应的男神明和男生魅力值 delimiter $ create procedure myp5(in bwname varchar(50),out bmname varchar(50),out cpnum int) begin select bs.boyName,bs.userCP into bmname,cpnum from beauty b join boys bs on b.boyfriend_id=bs.id where b.name=bwname; end $ -- 调用 call myp5('Angelababy',@bmname,@cpnum); select @bmname,@cpnum; -- 4、带inout模式的参数的存储过程 -- 案例:传入a和b,最终a和b都翻倍并返回 delimiter $ create procedure myp6(inout a int,inout b int) begin SELECT a*2,b*2 into a,b; end $ -- 调用(inout调用时需要先定义和已封装的存储过程数量一致的变量并赋值,然后传入存储过程) set @c=5; set @d=6; call myp6(@c,@d); select @c,@d; # 1、创建存储过程或函数实现传入用户名和密码,插入到admin表中 delimiter $ create procedure myp7 (in username varchar(20),in password varchar(20)) begin insert into admin set admin.username=username,admin.password=password; end $ call myp7('群员站岗','888888888'); select * from admin; # 2、创建存储过程或函数实现传入女神编号,返回女神名称和女神电话 -- 手机号用int存会超出范围 delimiter $ create procedure myp8(in wnum int,out wname varchar(20),out whone bigint) begin select name,phone into wname,whone from beauty where id=wnum; end $ -- 调用 call myp8(1,@wn,@wh); select @wn,@wh; # 3、创建存储过程或函数实现传入两个女神生日,返回大小 delimiter $ create procedure myp9(in none datetime,in ntwo datetime,out result varchar(20)) begin select DATEDIFF(none,ntwo) into result; end $ -- 调用 set @no='2022-01-06'; set @nt='2022-01-05'; call myp9(@no,@nt,@r); select @r;