当前位置:网站首页>Detailed explanation of MySQL creation stored procedure and function
Detailed explanation of MySQL creation stored procedure and function
2022-04-23 11:06:00 【liming89】
Source of the article : Learn through http://www.bdgxy.com/
1. stored procedure
1.1. Basic grammar
create procedure name ([params])
UNSIGNED [characteristics] routine_body
?params : in|out|inout Specify the parameter list Represents input and output
routine_body: SQL Code content , With begin ........? ?end
characteristics: Specify stored procedure properties , contain 5 Kind of
? ? ? ? ? ? ? ? ? ? ? ? ? ?1 DETERMINISTIC Not sure of
2 NO SQL No, SQl sentence , Of course, it doesn't change the data
3 READS SQL DATA Just read the data , Of course, it doesn't change the data
4 MODIFIES SQL DATA To modify data
5 CONTAINS SQL Contains SQL sentence
1.2 Create a stored procedure with specified execution permission
create DEFINER=`root`@`%` procedure name ([params])
UNSIGNED [characteristics] routine_body
DEFINER: Indicate who has the authority to perform .
1.3?DELIMITER Use
? ? ? ”DELIMITER //“ Presentation settings “//” The symbol is the conclusion , because mysql The default statement ends with a semicolon ‘;', To avoid stored procedures and mysql Statement symbol conflict , So sometimes DELIMITER To change the closing symbol , To cooperate end // To use ;
? Example : Create a root Stored procedures executed by the account , Output the length of the given string
DELIMITER //
CREATE definer=`root`@`%` PROCEDURE `avgFruitPrice`(
in f_string VARCHAR(200)
)
BEGIN
select length(f_string);
END//
2. Create a function ?
The creation of a function is the same as that of a stored procedure
Example
DELIMITER //
CREATE definer=`root`@`%` FUNCTION `my_length`(
f_string VARCHAR(200)
)
RETURNS INT(11)
UNSIGNED NO SQL
BEGIN
return length(f_string);
END//
Be careful : When creating a function, you need to pay attention to 3 A place to ,
1.??RETURNS: You need to specify the return type
2.?UNSIGNED ?NO SQL You need to specify the stored procedure properties
3.return: Return the required data
Mistakes encountered :
![]()
If an error is reported, the above information means that the stored procedure characteristics are not specified .
In the stored procedure function, you can use mysql The query result is copied for its parameters : The sentence is select .... into
begin
declare onename char(50) default‘0’;
declare twoname char(50);
select f_name, b_name into onename, twoname from t_user where id =1;
…
end//
explain :
declare: Variables defined inside stored procedures and functions
default: The default value is
This is about mysql This is the end of the article on creating stored procedures and functions , More about mysql Please search the rookie tutorial for the contents of stored procedures and functions www.piaodoo.com Previous articles or continue to browse the relevant articles below. I hope you can support rookie tutorials in the future www.piaodoo.com!
版权声明
本文为[liming89]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231102124557.html
边栏推荐
- The courses bought at a high price are open! PHPer data sharing
- Cygwin 中的 rename 用法
- 学习 Go 语言 0x04:《Go 语言之旅》中切片的练习题代码
- 详解MySQL中timestamp和datetime时区问题导致做DTS遇到的坑
- Kaggle - real battle of house price prediction
- Solutions to common problems in visualization (IX) background color
- Gets the current time in character format
- 全栈交叉编译X86完成过程经验分享
- Common parameters of ffmpeg command line
- 一个微博数据库设计带来的简单思考
猜你喜欢

Jupyter Lab 十大高生产力插件

The courses bought at a high price are open! PHPer data sharing

Excel · VBA custom function to obtain multiple cell values

使用zerotier让异地设备组局域网

Promise details

Solution architect's small bag - 5 types of architecture diagrams

一道有趣的阿里面试题

Visual solutions to common problems (VIII) mathematical formulas

Excel · VBA array bubble sorting function

VIM + ctags + cscope development environment construction guide
随机推荐
MySQL索引优化之分页探索详细介绍
Three web components (servlet, filter, listener)
SVN的使用:
Esp32 learning - add folder to project
MBA-day5數學-應用題-工程問題
PlatoFarm推出正式版游戏经济模型的特点分析
数据库管理软件SQLPro for SQLite for Mac 2022.30
Full stack cross compilation x86 completion process experience sharing
Embedded related surface (I)
Structure of C language (Advanced)
Data analysis learning (I) data analysis and numpy Foundation
JDBC – PreparedStatement – 如何设置 Null 值?
升级cpolar内网穿透能获得的功能
How to use JDBC callablestatement The wasnull () method is called to check whether the value of the last out parameter is SQL null
Learning notes 7-depth neural network optimization
Mysql排序的特性详情
Solutions to common problems in visualization (VIII) solutions to problems in shared drawing area
SWAT—Samba WEB管理工具介绍
使用 PHP PDO ODBC 示例的 Microsoft Access 数据库
Qinglong panel pull library command update [April 20, 2022] collection is not lost