MySQL 自定义函数CREATE FUNCTION示例
作者:whsnow 时间:2024-01-26 00:48:07
mysql>
mysql> delimiter $$
mysql>
mysql> CREATE FUNCTION myFunction
-> (in_string VARCHAR(255),
-> in_find_str VARCHAR(20),
-> in_repl_str VARCHAR(20))
->
-> RETURNS VARCHAR(255)
-> BEGIN
-> DECLARE l_new_string VARCHAR(255);
-> DECLARE l_find_pos INT;
->
-> SET l_find_pos=INSTR(in_string,in_find_str);
->
-> IF (l_find_pos>0) THEN
-> SET l_new_string=INSERT(in_string,l_find_pos,LENGTH(in_find_str),in_repl_str);
-> ELSE
-> SET l_new_string=in_string;
-> END IF;
-> RETURN(l_new_string);
->
-> END$$
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> delimiter ;
mysql> select myFunction('ABC','A','Z');
+---------------------------+
| myFunction('ABC','A','Z') |
+---------------------------+
| ZBC |
+---------------------------+
1 row in set (0.00 sec)
mysql> drop function myFunction;
Query OK, 0 rows affected (0.00 sec)
标签:自定义函数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
使用Python获取CPU、内存和硬盘等windowns系统信息的2个例子
2023-08-26 23:12:32
如何对MySQL数据库表进行锁定
2009-02-10 10:39:00
将Django框架和遗留的Web应用集成的方法
2023-04-11 11:18:52
利用Python进行图像的加法,图像混合(附代码)
2021-06-22 20:28:44
![](https://img.aspxhome.com/file/2023/6/86466_0s.gif)
基于Python编写一个简单的垃圾邮件分类器
2022-02-26 08:11:23
PYTHON基础-时间日期处理小结
2023-04-23 02:02:59
如何使用Pycharm连接SQL Sever(详细教程)
2024-01-18 22:57:41
![](https://img.aspxhome.com/file/2023/0/113560_0s.png)
golang cache带索引超时缓存库实战示例
2023-07-24 04:43:11
CSS控制字体效果的思考
2011-06-14 09:44:02
![](https://img.aspxhome.com/file/UploadPic/20072/20072311315168s.gif)
Python调用钉钉自定义机器人的实现
2023-08-29 20:08:55
![](https://img.aspxhome.com/file/2023/0/64710_0s.png)
聊聊python中的循环遍历
2022-06-17 23:44:43
用Dreamweaver MX制作文字特效
2011-06-14 09:49:47
![](https://img.aspxhome.com/file/UploadPic/20072/20072311216835s.gif)
Python反转序列的方法实例分析
2021-10-30 11:13:07
对pytorch网络层结构的数组化详解
2023-09-02 12:10:09
如何用Python进行回归分析与相关分析
2023-11-24 01:08:14
![](https://img.aspxhome.com/file/2023/2/69582_0s.png)
关于php unset对json_encode的影响详解
2023-07-06 08:33:52
![](https://img.aspxhome.com/file/2023/6/55356_0s.png)
vite+vue3中使用mock模拟数据问题
2024-04-28 09:27:56
![](https://img.aspxhome.com/file/2023/4/132954_0s.png)
Python导入模块包原理及相关注意事项
2023-01-26 04:46:31
![](https://img.aspxhome.com/file/2023/6/97266_0s.png)
python 统计一个列表当中的每一个元素出现了多少次的方法
2021-09-21 13:48:32
在Vue项目中使用d3.js的实例代码
2024-05-11 09:13:56
![](https://img.aspxhome.com/file/2023/6/126526_0s.png)