当前位置:网站首页>mysql function函数语法
mysql function函数语法
2022-04-23 02:39:00 【一只努力xx的程序媛】
delimiter
在mysql的命令行操作中的作用:指定一个符号为一条SQL 语句的结束,默认为分号。一条SQL语句结束时会立即执行,而procedure与function中存在分号,所以定义procedure与function之前,需要先修改此符号。如:delimiter //
变量
变量名为‘@xxx’形式,不需声明,可直接使用,默认值为NULL(但procedure或函数中的局部变量名不带@,且需要声明,格式:declare 变量名 datatype。但procedure或函数等结构体中也能直接使用’@xxx’形式的变量,且可在外部访问到)
SET指令
变量进行赋值
删除函数
drop function if exists fn_name;
明确指明函数的类型
为function指定一个参数。 DETERMINISTIC, NO SQL 和 READS SQL DATA 相当于明确的告知MySQL服务器这个函数不会修改数据
1 DETERMINISTIC 确定的
2 NO SQL 没有SQl语句,当然也不会修改数据
3 READS SQL DATA 只是读取数据,当然也不会修改数据
4 MODIFIES SQL DATA 要修改数据
5 CONTAINS SQL 包含了SQL语句
示例
delimiter $$
CREATE FUNCTION `fn_cutAppName`(appName varchar(4000)) RETURNS varchar(4000) CHARSET utf8mb4
DETERMINISTIC
begin
DECLARE ret varchar(4000);
case when (appName like '%护照号%' or appName like '%身份证号%') then
set @leftindex= LOCATE('(',appName);
if (@leftindex =0) then set @leftindex = LOCATE('(',appName); end if;
if (@leftindex =0) then set @leftindex = LOCATE('护照号',appName); end if;
if (@leftindex =0) then set @leftindex = LOCATE('身份证号',appName); end if;
case when (@leftindex >0) then set ret = trim(left(appName,(@leftindex-1)));
else set ret = appName ;
end case;
else
set ret = appName;
end case;
return (select ret);
end
end $$
调用函数
select fn_cutAppName('无限责任公司');
参考:
https://blog.csdn.net/yuxin6866/article/details/52722913
https://blog.csdn.net/qq_19865749/article/details/68962005
版权声明
本文为[一只努力xx的程序媛]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_23888451/article/details/103963851
边栏推荐
- After idea is successfully connected to H2 database, there are no sub files
- 谷雨
- RT_ Thread ask and answer
- Handwritten memory pool and principle code analysis [C language]
- TypeScript(1)
- 在MySQL Workbench中执行外部的SQL脚本,报错
- 013_ Analysis of SMS verification code login process based on session
- [XJTU计算机网络安全与管理]第二讲 密码技术
- C # import details
- Modification du contenu de la recherche dans la boîte déroulante par PHP + MySQL
猜你喜欢
Devil cold rice 𞓜 078 devil answers the market in Shanghai and Nanjing; Communication and guidance; Winning the country and killing and screening; The purpose of making money; Change other people's op
Fashion MNIST dataset classification training
C语言 171. 最近回文数
Rich intelligent auxiliary functions and exposure of Sihao X6 security configuration: it will be pre sold on April 23
SQL server2019无法下载所需文件,这可能表示安装程序的版本不再受支持,怎么办了
Handwritten memory pool and principle code analysis [C language]
手写内存池以及原理代码分析【C语言】
Fashion MNIST 数据集分类训练
Rhcsa day 1 operation
【无标题】
随机推荐
MySQL JDBC编程
Flink stream processing engine system learning (III)
JDBC JDBC
JSP page nesting
010_ StringRedisTemplate
007_ Redis_ Jedis connection pool
The second day of learning rhcsa
Intelligent agricultural management model
How to recognize products from the perspective of Dialectics
wordpress 调用指定页面内容详解2 get_children()
Develop a chrome plug-in from 0 (2)
Interpretation of the future development of smart agriculture
Day18 -- stack queue
小程序 canvas 画布半圆环
1215_ Hello world used by scons
Consider defining a bean of type 'com netflix. discovery. AbstractDiscoveryClientOptionalArgs‘
Yes, from today on, our fans can participate in Netease data analysis training camp for free!
Looking for a job, writing a resume to an interview, this set of information is enough!
Modification du contenu de la recherche dans la boîte déroulante par PHP + MySQL
一个国产图像分割项目重磅开源!