当前位置:网站首页>存储函数学习笔记
存储函数学习笔记
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
优点:存储过程创建的时候进行编译,之后就不在进行编译
存储过程安全性比价强,可以设置权限
缺点:难以调试和扩展,没有移植性,高并发的情况下增加数据库的压力
边栏推荐
- Recueillir des trésors dans le palais souterrain (recherche de mémoire profonde)
- C language course set up property fee management system (big work)
- idea 好用插件汇总!!!
- 10-golang运算符
- 浅谈SIEM
- 三分钟带你快速了解网站开发的整个流程
- Dongle data collection
- 10 golang operator
- 阿里OSS Postman Invalid according to Policy: Policy Condition failed: [“starts-with“, “$key“, “test/“]
- 高阶-二叉平衡树
猜你喜欢

To sort out the anomaly detection methods, just read this article!

Understanding of C manualresetevent class

How does the port scanning tool help enterprises?

【企业数据安全】升级备份策略 保障企业数据安全

【ManageEngine卓豪】网络运维管理是什么,网络运维平台有什么用
![[unity shader amplify shader editor (ASE) Chapter 9]](/img/f5/f0f6786406e149187e71c8e12cde0d.png)
[unity shader amplify shader editor (ASE) Chapter 9]

【#Unity Shader#Amplify Shader Editor(ASE)_第九篇】

B-tree series

连续四年入选Gartner魔力象限,ManageEngine卓豪是如何做到的?

SystemVerilog learning-08-random constraints and thread control
随机推荐
Golang panic recover custom exception handling
基金定投是高风险产品吗?
Flink practice -- multi stream merge
B-树系列
FPGA - clocking -02- clock wiring resources of internal structure of 7 Series FPGA
Mysql 表分区创建方法
码力十足学量化|如何在财务报告寻找合适的财务公告
High order binary search tree
C语言课设学生考勤系统(大作业)
SystemVerilog learning-07-class inheritance and package use
UOW of dev XPO comparison
Servlet
Uniapp tree level selector
XAF Bo of dev XPO comparison
Tidb database characteristics summary
[self use of advanced mathematics in postgraduate entrance examination] advanced mathematics Chapter 1 thinking map in basic stage
【网络安全工具】USB控制软件有什么用
HCM Beginner (I) - Introduction
【#Unity Shader#自定义材质面板_第一篇】
libpng12.so. 0: cannot open shared object file: no such file or directory