当前位置:网站首页>存储函数学习笔记
存储函数学习笔记
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
优点:存储过程创建的时候进行编译,之后就不在进行编译
存储过程安全性比价强,可以设置权限
缺点:难以调试和扩展,没有移植性,高并发的情况下增加数据库的压力
边栏推荐
- To sort out the anomaly detection methods, just read this article!
- 【ITSM】什么是ITSM,IT部门为什么需要ITSM
- ManageEngine Zhuohao helps you comply with ISO 20000 standard (IV)
- [leetcode] day91- duplicate elements exist
- C语言课设学生考勤系统(大作业)
- 【ManageEngine卓豪】局域网监控的作用
- Treasure taking from underground palace (memory based deep search)
- Using Baidu map to query national subway lines
- How did ManageEngine Zhuohao achieve the goal of being selected into Gartner Magic Quadrant for four consecutive years?
- Three minutes to quickly understand the whole process of website development
猜你喜欢
![[ITSM] what is ITSM and why does it department need ITSM](/img/e1/85b5f00f124829b6a6b40c5cf621bd.png)
[ITSM] what is ITSM and why does it department need ITSM

自开发软件NoiseCreater1.1版本免费试用

浅谈SIEM

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

ForkJoin和Stream流测试

Student attendance system for C language course (big homework)

HCM Beginner (III) - quickly enter pa70 and pa71 to browse employee information PA10

Detailed steps for installing redis on Windows system
![[unity shader custom material panel part II]](/img/d1/8632ae680299a27b7431b2d6e03fd3.png)
[unity shader custom material panel part II]

JDBC database operation
随机推荐
三分钟带你快速了解网站开发的整个流程
Treasure taking from underground palace (memory based deep search)
C how to print out the original array
libpng12.so. 0: cannot open shared object file: no such file or directory
码力十足学量化|如何在财务报告寻找合适的财务公告
【ManageEngine卓豪】用统一终端管理助“欧力士集团”数字化转型
[postgraduate entrance examination advanced mathematics Wu Zhongxiang +880 version for personal use] advanced mathematics Chapter II Basic Stage mind map
What are the functions of LAN monitoring software
[network security tool] what is the use of USB control software
C语言课设学生选修课程系统(大作业)
HDU - 1501 zipper (memory deep search)
Record MySQL troubleshooting caused by disk sector damage
[ManageEngine Zhuohao] helps Huangshi Aikang hospital realize intelligent batch network equipment configuration management
[automatic operation and maintenance] what is the use of the automatic operation and maintenance platform
Tidb single machine simulation deployment production environment cluster (closed pit practice, personal test is effective)
[ManageEngine Zhuohao] the role of LAN monitoring
C language course set up student elective course system (big homework)
async 与 await
FPGA - clocking -02- clock wiring resources of internal structure of 7 Series FPGA
make: g++:命令未找到