当前位置:网站首页>存储函数学习笔记
存储函数学习笔记
2022-07-01 06:21:00 【小美元】
存储过程的创建与调用
函数创建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();
函数创建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)
存储函数一定会有返回值,存储过程可以没有返回值,存储过程一般用于更新的操作,存储函数一般用于查询结果为一个值并且返回。存储过程可以有更多的返回值
存储过程和函数的查看、修改、删除
查看
- show create function or procedure 函数创建信息
- show procedure status
- SELECT * FROM information_schema.Routines
WHERE routine_name = ‘email_byid’;从这个表中查看存储过程和存储函数的信息
存储过程的函数的修改
ALTER PROCEDURE show_max_salary
SQL SECURITY invoker
COMMENT ‘查询最高工资’;
show PROCEDURE STATUS like ‘show_max_salary’
修改这个表的备注是查询最高工资
然后查看信息
删除存储过程和函数
DROP FUNCTION if EXISTS connt_byid
优点:存储过程创建的时候进行编译,之后就不在进行编译
存储过程安全性比价强,可以设置权限
缺点:难以调试和扩展,没有移植性,高并发的情况下增加数据库的压力
边栏推荐
猜你喜欢

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

数据库产生死锁了请问一下有没有解决办法
![[file system] how to run squashfs on UBI](/img/d7/a4769420c510c47f3c2a615b514a8e.png)
[file system] how to run squashfs on UBI

【ManageEngine卓豪 】助力世界顶尖音乐学院--茱莉亚学院,提升终端安全

ManageEngine卓豪助您符合ISO 20000标准(四)

Discrimination between left and right limits of derivatives and left and right derivatives
![[network security tool] what is the use of USB control software](/img/cc/20fc1f35c139c52c5922727368b835.png)
[network security tool] what is the use of USB control software

【Unity Shader 消融效果_案例分享】

HCM Beginner (II) - information type

高阶-二叉平衡树
随机推荐
Discrimination between left and right limits of derivatives and left and right derivatives
Understanding of C manualresetevent class
C语言课设职工信息管理系统(大作业)
【ManageEngine卓豪 】助力世界顶尖音乐学院--茱莉亚学院,提升终端安全
What are the functions of LAN monitoring software
C language course set up student elective course system (big homework)
做技术,自信不可或缺
C#如何打印輸出原版數組
SystemVerilog learning-07-class inheritance and package use
局域网监控软件有哪些功能
数据库产生死锁了请问一下有没有解决办法
Excel visualization
ManageEngine Zhuohao helps you comply with ISO 20000 standard (IV)
C语言课设物业费管理系统(大作业)
C language course set up salary management system (big homework)
端口扫描工具对企业有什么帮助?
Tidb single machine simulation deployment production environment cluster (closed pit practice, personal test is effective)
Solve the problem of garbled files uploaded by Kirin v10
Treasure taking from underground palace (memory based deep search)
C语言课设学生选修课程系统(大作业)