MySQL 自定义函数_mysql随机时间函数
mysql 函数 时间 自定义 随机
2023-06-13 09:13:44 时间
大家好,又见面了,我是你们的朋友全栈君。
下面的自定义函数 中,
注意delimiter 的使用,如果不懂,请看我的上一篇文章
使用了 group_concat()、find_in_set() 函数,
delimiter $$
use `test`$$
drop function if exists `queryOnePartnerIdById`$$
create function `queryOnePartnerIdById`(_id bigint) returns varchar(4000) charset utf8
begin
if _id is null or _id='' or _id=0 then
return null;
end if ;
select GROUP_CONCAT(id) into @__selectTmpID from lcs_member where del_flag=0 and belong_to_partner>0 and FIND_IN_SET(belong_to_partner,_id)>0;
if (@__selectTmpID!='' and @__selectTmpID is not null ) then
return @__selectTmpID;
else
return null;
end if;
end$$
delimiter ;
delimiter $$
use `test`$$
drop function if exists `queryOnePartnerUuidByUuid`$$
create function `queryOnePartnerUuidByUuid`(_uuid varchar(4000)) returns varchar(4000) charset utf8
begin
set _uuid=TRIM(_uuid);
if _uuid is null or _uuid='' then
return null;
end if ;
select GROUP_CONCAT(id) into @__userID from lcs_member where del_flag=0 and user_uuid=_uuid;
if @__userID is null or @__userID='' then
return null;
end if ;
select GROUP_CONCAT(id),GROUP_CONCAT(user_uuid) into @__selectTmpID,@_user_uuid from lcs_member where del_flag=0 and belong_to_partner>0 and FIND_IN_SET(belong_to_partner,@__userID)>0;
if (@__selectTmpID!='' and @__selectTmpID is not null ) then
return @_user_uuid;
else
return null;
end if;
end$$
delimiter ;
调用:
select queryOnePartnerIdById(318);
select * from lcs_member where FIND_IN_SET(id, queryOnePartnerIdById(318));
select queryOnePartnerUuidByUuid('9974A2EC6DCE8AB0E')
select * from lcs_member where FIND_IN_SET(user_uuid, queryOnePartnerUuidByUuid('9974A2EC6DCE8AB0E'));
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/196015.html原文链接:https://javaforall.cn
相关文章
- 的应用MySQL中函数的使用及其优势(mysql中函数)
- MySQL查询:学习内置函数的使用(mysql查询函数)
- 格式化MySQL日期:从函数中获得有用结果(mysql格式化日期函数)
- MySQL中使用替换函数实现字符串替换(mysql替换函数)
- MySQL中快速写入数据库的技巧(mysql写入数据库)
- MySQL命令行快速输出:把时间节省到最低(mysql命令行输出)
- MySQL数据库:学习如何添加注释(mysql数据库的注释)
- 深入浅出MySQL:常用函数汇总(mysql常用函数汇总)
- MySQL查询函数解析与实践(mysql查询数据库函数)
- MySQL数据库自增长ID解决方案(mysql自增长id)
- MySQL如何创建索引(mysql怎样建立索引)
- 深入了解MySQL数据库函数,助您高效开发(mysql数据库函数详解)
- MySQL语句实现获取当前时间(mysql语句当前时间)
- MySQL中使用size关键字(mysql中size用法)
- 快速实现C语言MySQL环境变量配置(c mysql 环境变量)
- 深入理解MySQL中的Count函数应用及其用途(mysql 中count)
- C语言中MySQL数据操作实现方式(c mysql数据操作类)
- MySQL学习笔记使用ABS函数对数据进行绝对值计算(mysql 中abs函数)
- 天花板ceil函数在MySQL中的应用(ceil函数 mysql)
- MySQL中常用加法函数的使用方法(mysql中加法函数)
- 如何使用MySQL中的函数和事件(mysql中函数,事件)
- MySQL事务保证数据完整性的关键技术(mysql。事务)
- MySQL中的IF函数 – 数据库中条件判断使用技巧(mysql z中的if)
- 使用MySQL,如何压缩zip文件(mysql zip怎么)
- 使用MySQL数据库实现Word文档上传功能(mysql 上传word)
- Mysql中分页查询的两个解决方法比较