当前位置: 首页 > news >正文

中国证券登记结算有限公司官网aso搜索优化

中国证券登记结算有限公司官网,aso搜索优化,百度蜘蛛抓取网站,建站优化收费存储过程中的流程控制 在存储过程中支持流程控制语句用于实现逻辑的控制 一、分支语句 语法:if-then-else 1.单分支语句 语法 if conditions then ——SQL end if; if conditions then——SQLend if; ——如果参数a的值为1,则添加一条班级信息 …

存储过程中的流程控制

在存储过程中支持流程控制语句用于实现逻辑的控制

一、分支语句

语法:if-then-else

1.单分支语句

语法

if conditions then

             ——SQL

end if;

if conditions then——SQLend if;

——如果参数a的值为1,则添加一条班级信息

案例

创建一个储存过程,如果参数a的值为1,则添加一条班级信息

代码实现
创建存储过程
#创建一个储存过程
create procedure proc_test7(in a int)
begin#单分支 if语句if a=1 theninsert into classes(name,class_remark) values('Java2204','test');end if;
end;
#———如果参数a的值为1,则添加一条班级信息
调用存储过程
#调用存储过程
call proc_test7 (1);
call proc_test7 (2);
运行结果
创建存储过程

调用存储过程

2.双分支语句

双分支:如果条件成立执行SQL1,否则执行SQL2

语法

if conditions then 

        ——SQL1

else

        ——SQL2

end if;

if conditions then ——SQL1else——SQL2end if;
案例

如果参数为1,创建学生信息,如果参数不为1,创建班级信息

代码实现
创建存储过程
#创建存储过程
create procedure proc_test8(in a int)
beginif a=1 theninsert into classes(name,class_remark) values('Java2208','test');elseinsert into students(stu_num,name ,stu_gender,stu_age,cid)values('20220110','小虎','女',19,1);end if;
end;
调用存储过程
#调用储存过程
call proc_test8 (1); 
call proc_test8 (3);
运行结果
创建存储过程
调用储存过程

3.switch case语句

语法

create procedure 储存过程名(参数)

begin

        case a

                when 1 then

                        执行的SQL语句1;

                when 2 then

                        执行的SQL语句2;

                else

                        执行的SQL语句3;

        end case;

end;

create procedure 储存过程名(参数)begincase awhen 1 then执行的SQL语句1;when 2 then执行的SQL语句2;else执行的SQL语句3;end case;end;
案例

case 多分支语句

代码实现
创建储存过程
create procedure proc_test9(in num int)
begincase numwhen 1 then#如果a的值为1,执行以下操作insert into classes(name,class_remark) values('Java2208','test');when 2 then#如果a的值为2,执行以下操作insert into students(stu_num,name ,stu_gender,stu_age,cid)values('20220111','小刚','男',22,2);else#如果a的值不为1也不为2,执行以下操作update students set stu_age=18 where stu_num ='20220110';#修改学生年龄end case;
end;
调用储存过程
#调用储存过程
call proc_test9 (2);
call proc_test9 (3);
运行结果
创建储存过程

调用储存过程

二、循环语句

1.while循环

语法

create procedure 储存过程名(传递的参数)

begin

        declare i int        #局部变量

                set i=0        #局部变量赋值

                while 循环条件 do

                        SQL语句

                end while;        #结束循环

        end;                        #结束储存过程

create procedure 储存过程名(传递的参数)begindeclare i int        #局部变量set i=0        #局部变量赋值while 循环条件 doSQL语句end while;        #结束循环end;                        #结束储存过程
案例
代码实现
创建储存过程
#while循环 创建储存过程
create procedure proc_test10(in num int)
begindeclare i int;set i=0;while i<num doinsert into classes (name,class_remark)values(concat('Java',i),'......');#concat()拼接字符串函数set i=i+1;end while;
end;
调用储存过程
#调用储存过程
call proc_test10 (4);
运行结果
创建储存过程

调用储存过程

执行结果

编号自动增加

2.repeat循环

案例
代码实现
创建储存过程
#repeat循环
#创建储存过程
create procedure proc_test11(in num int)
begindeclare i int;set i=1;repeatinsert into classes (name,class_remark)values(concat('C++',i),'......');#concat()拼接字符串函数set i=i+1;#循环结束条件 类似于do while语句until i>numend repeat;
end;
调用储存过程
#调用储存过程
call proc_test11 (4);
运行结果
创建储存过程

调用储存过程

执行结果

3.loop循环

语法

create procedure 储存过程名(参数)

begin

        declare i int;        #定义局部变量

        set i=0;                #赋值局部变量

        myloop:loop        #给loop循环起名

                执行的SQL语句;

                set i=i+1        #迭代语句

               if i=num then  #循环结束条件

                        leave myloop;

                end if;             #结束判断

        end loop;                #结束循环

end;

create procedure 储存过程名(参数)begindeclare i int;        #定义局部变量set i=0;                #赋值局部变量myloop:loop        #给loop循环起名执行的SQL语句;set i=i+1        #迭代语句if i=num then  #循环结束条件leave myloop;end if;             #结束判断end loop;                #结束循环end;
案例

创建储存过程

loop == 循环+判断

代码实现
创建储存过程
#创建储存过程
# loop == 循环+判断
create procedure proc_test12(in num int)
begindeclare i int;set i=0;myloop:loopinsert into classes (name,class_remark)values(concat('Python',i),'......');set i=i+1;if i=num thenleave myloop;end if;end loop;
end;
调用储存过程
#调用储存过程
call proc_test12(4); 
运行结果
创建储存过程

调用储存过程

 

执行结果

http://www.15wanjia.com/news/13047.html

相关文章:

  • 企业铭做网站电商培训内容有哪些
  • 最好的模板网站百度站长平台注册
  • 做网络歌手的网站seo发包技术教程
  • 如何做响应式布局网站网站查询ip地址
  • 做印刷去哪个网站找工作seo最新优化技术
  • 24小时看b站视频的软件有哪些广州推广系统
  • 在哪里买空间做网站自己建个网站要多少钱
  • 广告推广的方式有哪些seo研究中心
  • 如何用office做网站电脑培训学校哪家好
  • 网站建设与管理需要什么软件seo技术优化服务
  • 长沙php网站建设怎么在百度做广告
  • 做网站电商东莞网络科技公司排名
  • 论坛网站用的虚拟主机网络科技公司
  • wordpress主题有广告windows优化大师会员兑换码
  • 网站建设的话术百度投诉中心
  • 河北网站建设推广公司福州seo顾问
  • 网站开发实训新的体会网址关键词查询网站
  • 建设ca网站必应搜索引擎首页
  • jsp动态网站开发项目教程 ppt微信营销方式有哪些
  • 如何修改代码wordpress快速优化网站排名软件
  • 做网站和管理系统南宁网络推广软件
  • 北京网站建设哪家专业信阳seo公司
  • 海淀网站建设服务网站域名ip地址查询
  • 做调查问卷权威网站如何在百度上做广告宣传
  • 网站建设代理加盟今日竞彩足球最新比赛结果查询
  • 儿童网站模板免费下载cpa广告联盟平台
  • 品牌网站建设价格平原县网站seo优化排名
  • 连锁酒店网站建设淘宝店铺怎么引流推广
  • 36kr网站用什么做的深圳招聘网络推广
  • 怎样推广才能让更多人看到上海小红书seo