存储过程
创始人
2024-11-19 13:06:37
0次

1、概念

完成特定功能的sql语句的集合。把定义好的sql集合在一个特定的sql函数当中,每次执行调用函数即可,还可以实现传参的调用

2、作用

执行速度比sql语句执行速度更快,执行效率也更高

客户端可以随时调用发放,也可以随时修改

可以对数据库做任何操作

3、语法

#创建库 create database xy102; #创建表 create table info1 ( id int(2) primary key, name varchar(10), high int(3), address varchar(15) );  #创建存储过程 delimiter $$ #delimiter是开始和结束的语法,$$是标志位,可以自定义,不要用汉字,不要以数字开头,不能使用特殊字符开头 create procedure test1 () #创建存储过程test1 begin   select * from info1; end $$ delimiter;  #查看当前库的存储过程 show procedure status where db='xy102'; #查看表的存储过程 show procedure status like '%test1%';  #调用执行 call test1;

4、传参

4.1in

传入参数,调用者向存储过程传入值

delimiter $$ create procedure test2 (in uname char(10)) begin select * from info1 where name = uname; end $$ delimiter; call test2('user1'); call test2('chen');

4.2out

输出参数,存储过程向调用者传出值,可以是多个值

delimiter $$ create procedure test5 (out id int,out name char(10),out high int,out address varchar(10)) BEGIN set id=3; set name='王心凌'; set high=185; set address='幸云教育'; end $$ delimiter;  call test5 (@id,@name,@high,@address) select @id,@name,@high,@addresss; insert into info1 values (@id,@name,@high,@address);

4.3inout

输入输出,既可以表示存储过程向调用者传出值,也可以表示用户向存储过程传入值

delimiter $$ create procedure test6 (inout str varchar(20)) begin #在存储过程中引用变量无需加@ set str=concat('_xy102'); #替换,把字符串进行替换  end $$ delimiter;  set @str='cyl'; call test6(@str); update info1 set name=@str where id = 3;

5、存储条件的控制语句

if 条件语句

delimiter $$ create procedure test9 (inout num int) begin if num > 10 then set num=num-5; else set num=num*2; end if; end $$ delimiter;  set @num=19; call test9(@num); update info1 set id=@num where high=111;
create table info3 ( id int,score int,grade char(30) );  delimiter $$ create procedure test13 (inout score int,out grade varchar(255)) BEGIN if score between 85 and 100 THEN set grade='优秀'; elseif score between 60 and 84 then set grade='及格'; ELSE set grade='不及格'; end if; end $$ delimiter;  set @score=90; call test13(@score,@grade); insert into info3 value (1,@score,@grade); select * from info3;  set @score=55; call test13(@score,@grade); insert into info3 value (1,@score,@grade); select * from info3;

相关内容

热门资讯

玩家必知教程!!浙江游戏大厅透... 您好,浙江游戏大厅这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩家在这款...
免费测试版开挂脚本!KELE多... 免费测试版开挂脚本!KELE多功能开挂脚本,KELE切实存在有开挂脚本KELE辅助器是一种具有地方特...
新手必备!凯旋麻将开挂脚本软件... 新手必备!凯旋麻将开挂脚本软件工具,凯旋麻将一直有开挂曝光APP(有挂攻略);凯旋麻将简单的透视挂控...
技巧知识分享外挂app!胡乐竞... 技巧知识分享外挂app!胡乐竞技多功能外挂app,胡乐竞技一直真的有外挂app1、很好的工具软件,可...
重大来袭!上游炸金花辅助器脚本... 重大来袭!上游炸金花辅助器脚本软件工具,上游炸金花最初有辅助器科普APP(果真有挂);上游炸金花是一...
技术分享辅助器工具!微乐江西麻... 技术分享辅助器工具!微乐江西麻将多功能辅助器工具,微乐江西麻将确实真的是有辅助器工具1、完成微乐江西...
实测教程!湖北雅苑麻将辅助挂脚... 实测教程!湖北雅苑麻将辅助挂脚本软件工具,湖北雅苑麻将起初是真的有辅助挂分享APP(有挂工具)是一款...
盘点几款外挂软件!大宝麻将多功... 盘点几款外挂软件!大宝麻将多功能外挂软件,大宝麻将原来存在有外挂软件大宝麻将脚本下载中分为三种模型:...
AI教程!微乐四川麻将辅助挂脚... AI教程!微乐四川麻将辅助挂脚本软件工具,微乐四川麻将果然有辅助挂分享APP(真实有挂);一、微乐四...
专业讨论辅助器技巧!开心娱乐多... 专业讨论辅助器技巧!开心娱乐多功能辅助器技巧,开心娱乐一贯真的是有辅助器技巧1、下载好开心娱乐透视辅...