当前位置:网站首页>Storage function learning notes
Storage function learning notes
2022-07-01 06:35:00 【Small dollar】
Creation and call of stored procedure
Function creation 1
delimiter $
CREATE FUNCTION email_byname()
RETURNS VARCHAR(25)
DETERMINISTIC
CONTAINS SQL
READS SQL DATA
BEGIN
RETURN(SELECT email FROM emp WHERE last_name = “abel”);
END $
delimiter ;
SELECT email_byname();
Function creation 2
SET GLOBAL log_bin_trust_function_creators = 1;
delimiter //
CREATE FUNCTION email_byid(emp_id INT)
RETURNS VARCHAR(15)
BEGIN
RETURN (SELECT email FROM emp WHERE employee_id = emp_id);
END //
delimiter ;
SELECT email_byid(101);
delimiter //
CREATE FUNCTION count_byid(dept_id INT)
RETURNS INT
BEGIN
RETURN(SELECT count(*) FROM emp WHERE department_id = dept_id);
END //
delimiter ;
SET @dept_id:= 30;
SELECT count_byid(@dept_id)
The storage function must have a return value , A stored procedure may not return a value , Stored procedures are generally used for update operations , The storage function is generally used to query that the result is a value and returns . Stored procedures can have more return values
View of stored procedures and functions 、 modify 、 Delete
see
- show create function or procedure Function creation information
- show procedure status
- SELECT * FROM information_schema.Routines
WHERE routine_name = ‘email_byid’; View information about stored procedures and stored functions from this table
Modification of stored procedure functions
ALTER PROCEDURE show_max_salary
SQL SECURITY invoker
COMMENT ‘ Query maximum wage ’;
show PROCEDURE STATUS like ‘show_max_salary’
The note to modify this table is to query the maximum salary
Then view the information
Deletes stored procedures and functions
DROP FUNCTION if EXISTS connt_byid
advantage : The stored procedure is compiled when it is created , After that, it will not be compiled
The security of stored procedure is better than that of price , You can set permissions
shortcoming : Difficult to debug and extend , There's no portability , Increasing the pressure on the database in the case of high concurrency
边栏推荐
猜你喜欢

产品学习(一)——结构图

ESP32 ESP-IDF GPIO按键中断响应

C language course set up student elective course system (big homework)
![[ManageEngine Zhuohao] what is network operation and maintenance management and what is the use of network operation and maintenance platform](/img/a4/b1476515260e3af0ca0dcc031deb98.png)
[ManageEngine Zhuohao] what is network operation and maintenance management and what is the use of network operation and maintenance platform

Async and await

ManageEngine Zhuohao helps you comply with ISO 20000 standard (IV)

C语言课设职工信息管理系统(大作业)

On whether variables are thread safe

Forkjoin and stream flow test

K8S搭建Redis集群
随机推荐
PAT (Advanced Level) Practice 1057 Stack
C语言课设学生信息管理系统(大作业)
产品学习(一)——结构图
High order binary search tree
Database notes
C language course design student information management system (big homework)
Draw a directed graph based on input
Some pits designed by NOC
Student attendance system for C language course (big homework)
DML statement in SQL (data operation language)
存储函数学习笔记
[ManageEngine Zhuohao] what is network operation and maintenance management and what is the use of network operation and maintenance platform
SQL语句
Promise
三说 拷贝构造之禁用
How does the port scanning tool help enterprises?
[ManageEngine] how to realize network automatic operation and maintenance
Chapter V input / output (i/o) management
mysql约束学习笔记
[unity shader amplify shader editor (ASE) Chapter 9]