mysql存储过程读书笔记2(control and conditional logic)
1. If
create procedure example3(stu_id int)
begin
declare stu_name varchar(30);
select name into stu_name from student where student_id = stu_id;
If stu_name is not null Then
select stu_name;
End If;
End;
2. If ... Else....
create procedure example4(stu_id int)
begin
declare stu_name varchar(30);
select name into stu_name from student where student_id = stu_id;
If stu_name is not null Then
select stu_name;
Else
select 'student is not exist';
End If;
End;
3. IF ... ELSEIF ... ELSE ... END;
drop procedure if exists discounted_price;
create procedure discounted_price(normal_price numeric(8,2), OUT discount_price numeric(8,2))
Begin
IF (normal_price) > 500 Then
SET discount_price = normal_price * 0.8;
ElseIF (normal_price > 400) Then
SET discount_price = normal_price * 0.9;
Else
SET discount_price = normal_price;
End If;
End
4. Loop
drop procedure if exists simple_loop;
create procedure simple_loop()
begin
DECLARE counter int;
SET counter = 0;
my_simple_loop: LOOP
IF counter = 10 Then
LEAVE my_simple_loop;
END IF;
SET counter = counter + 1;
END LOOP my_simple_loop;
select ' now counter is 10';
END
- Mysql update error: Error Code: 1175. You are using safe update mode and you tried to update a table
- Credentials and Access Control in Linux
- Inversion of Control Containers and the Dependency Injection pattern
- 项目管理实践【三】每日构建【Daily Build Using CruiseControl.NET and MSBuild】
- Statement Execution and Transaction Control【每日一译】--2012-11-04
- Installing JBoss jBPM 3.2.2 on Apache Tomcat 5.5 and MySQL
- DNN and Mysql .Net Connector
- how to choose one of compenent and control
- PHP5 and MySQL bible
- Access Control List and Process(如何设置DACL)
- master and slave have equal MySQL server UUIDs 解决方法
- MySQL(Flow Control Statements)
- Edit Control with Icon and Background Text
- Resource Allocation and Cross Layer Control in Wireless Networks (Foundations and Trends in Networki
- mysql连接error,Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection .....
- Atlas Control Toolkit and Source Code for the Build-in Asp.Net 2.0 Providers
- MYSQL锁之InnoDB record,gap and next-key locks
- Mysql:函数之三: date and time functions
- 14.2.1 MySQL and the ACID Model
- The run order about Loaded event and OnApplyTemplate in custom control of Silverlight 2 beta 2