Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the mysql code execution structure

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

What the editor wants to share with you this time is what is the mysql code execution structure. The article is rich in content. Interested friends can learn about it. I hope you can get something after reading this article.

The content of this article is:

What is the code execution structure, sequence structure, branch structure, loop structure?

Launch date: 2018-04-18

What is the code execution structure: the code execution structure mentioned here is the order in which multiple sql statements are executed. The code execution structure is mainly used to store multiple sql statements such as triggers, stored procedures and functions. Sequential structure: sql statements are executed sequentially from top to bottom. Generally speaking, the execution of the branch structure is a sequential structure branch structure: the execution of the branch structure is based on certain conditions to choose the execution path, and it will choose to execute those sql statements according to our given conditions. Only if-else: syntax: if conditional then sql statement [elseif conditional then sql statement] [else sql statement] end if Examples:-- create table pass (id int primary key auto_increment,name varchar (15), score int); create table unpass (id int primary key auto_increment,name varchar (15), score int);-- using stored procedures to create procedure myif (in name varchar (15), in score int) begin if score > = 60 then insert into pass (name,score) values (name,score); else insert into unpass (name,score) values (name,score); end if;end -- call and view the result call myif ("lilei", 61); call myif ("hanmeimei", 95); select * from pass;select * from unpass;call myif ("tuhao", 59); the condition in select * from unpass;if can basically refer to the condition of the while clause of the select statement. What in\ not in\ =\! = and so on can be used. Create procedure myif3 (in a char (1) begin if an in) then select 1; else select 2; end if;end;call myif3 ('a'); call myif3 ('b'); call myif3 ('c') Add: in theory, if you make a judgment that does not match, but do not want to continue execution, you should perform a return (for example, return in C language to interrupt the function), but there is no corresponding interrupt mechanism in mysql, so we need to interrupt actively (there are many ways to interrupt, such as executing a statement that conforms to syntax but cannot be run) [such as judging whether a student exists or not No action will be performed if it does not exist, so you should execute a statement that cannot be run successfully to report an error return. In fact, there is also a branch structure: case when [it seems that many books don't talk about it much, so I won't talk about it here. Those who are interested can have their own Baidu. Loop structure: a loop structure is a program structure that needs to perform a function repeatedly in a program. The loop structure in mysql is used to loop through the same sql statement multiple times. The loop structures in mysql are loop structure, while structure and repeat structure. Here we only talk about while structure. If you are interested in learning about others, you can use Baidu on your own. Syntax: while conditional do sql statement end while; has learned from other languages that there are continue (ending the loop early) and break (jumping out of the loop) in the loop structure of mysql, using leave instead of break and iterate instead of continue, but their syntax is: leave\ iterate loop name, so how to define the loop name? Loop name: while conditional do sql statement; leave\ iterate loop name; end while; example:-- A meaningless example, demonstrating create table whilenum (id int) only;-- create procedure mywhile () begin declare num int; set num=10; c1:while num > 0 do insert into whilenum values (num) with its own condition; create procedure mywhile2 (in num int) begin c1:while num > 0 do insert into whilenum values (num) where set num=num-1; end while;end;-- takes incoming parameters as conditions Set num=num-1; end while;end;-- create procedure mywhile3 with interruptions (in num int) begin c1:while num > 0 do if num%2=0 then set num=num-1; iterate C1; end if; insert into whilenum values (num); set num=num-1; end while;end; has finished reading this article on what is the execution structure of mysql code, and if you think the article is well written, you can share it with more people.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report