当前位置:网站首页>Stored procedure learning notes
Stored procedure learning notes
2022-07-01 06:35:00 【Small dollar】
function
Self defined
stored procedure
Relative to the function, there can be no return value , Stored procedure stored function is stored in mysql On the server of , And pre compiled
stored procedure :
No parameters
Only in type ( No return with parameters )
Only out type ( No parameters return )
Yes in and out Parameters of type ( There are parameters and returns )
If you don't specify it when you create it, the default is in type
stored procedure
characteristics: Indicate the constraints in the stored procedure
language sql: Indicates whether the result of the stored procedure behavior is certain
sql security: Indicate the permissions of the stored procedure
delimit $ Replace the seal to indicate the end
Creation of stored procedures
delimiter //
CREATE PROCEDURE show_max_salary()
BEGIN
SELECT MAX(salary) FROM emp;
END //
delimiter ;
Calls to stored procedures
CALL show_max_salary
Create calls with parameters in stored procedures
elimiter //
CREATE PROCEDURE show_min_salary(OUT ms DOUBLE)
BEGIN
SELECT min(salary) INTO ms
FROM emp;
END //
delimit ;
call show_min_salary(@ms);
SELECT @ms
Call of stored procedure with parameters 2
delimiter //
CREATE procedure show_some_one_salary (IN empname VARCHAR(20))
BEGIN
SELECT salary FROM emp WHERE last_name = empname;
END //
delimiter ;
Call mode 1
call show_some_one_salary(“abel”)
Call mode 2
set @empname = ‘Abel’;
call show_some_one_salary(@empname);
Creation and call of stored procedure with parameters 3
delimiter //
CREATE PROCEDURE show_someone_salary(IN empname varchar(20),OUT empsalary DECIMAL(10,2))
BEGIN
SELECT salary INTO empsalary FROM emp WHERE last_name = empname;
END //
delimiter ;
SET @empname = "abel";
call show_someone_salary (@empname,@empsalary);
SELECT @empsalary
stored procedure inout3
delimiter $
CREATE procedure show_mgr_name(inout empname VARCHAR(25))
BEGIN
SELECT last_name INTO empname FROM emp
WHERE employee_id =
(SELECT manager_id FROM emp WHERE last_name = empname);
end $
delimiter ;
set @empname := "abel";
call show_mgr_name(@empname);
SELECT @empname
ps: When using stored procedures, it is difficult to troubleshoot errors because they cannot be debugged
边栏推荐
猜你喜欢
随机推荐
What are the functions of LAN monitoring software
Rotate the animation component around the circle, take it and use it directly
C language course design student information management system (big homework)
HW(OD)岗面试题
SQL语句
PAT (Advanced Level) Practice 1057 Stack
Free trial of self-developed software noisecreater1.1
[automatic operation and maintenance] what is the use of the automatic operation and maintenance platform
json模块
Student attendance system for C language course (big homework)
数据库对象:视图学习记录
图解事件坐标screenX、clientX、pageX, offsetX的区别
[unity shader custom material panel part II]
【#Unity Shader#自定义材质面板_第二篇】
MySQL learning
三说 拷贝构造之禁用
Async and await
C语言课设学生选修课程系统(大作业)
[ManageEngine Zhuohao] the role of LAN monitoring
如果我在广州,到哪里开户比较好?究竟网上开户是否安全么?









