-- 如果存在hello这个名称的函数则删除hello drop FUNCTioN if exists hello; -- 创建一个叫hello的函数返回值为int类型,参数为varchar类型 参数名称为username CRE
-- 如果存在hello这个名称的函数则删除hello
drop FUNCTioN if exists hello;
-- 创建一个叫hello的函数返回值为int类型,参数为varchar类型 参数名称为username
CREATE FUNCTION hello(username VARCHAR(50)) RETURNS INT
-- 开始
begin
-- 声明一个变量c为int类型
declare c int;
-- 查询名称为username的用户id并保存进变量c
select id from `user` where name=username INTO c;
-- 返回变量c
return c;
-- 结束
END;
-- 执行查询函数
select hello("张");
--结束END--
本文标题: mysql 自定义函数
本文链接: https://www.lsjlt.com/news/2854.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-04-28
2024-04-28
2024-04-28
2024-04-28
2024-04-28
2024-04-28
2024-04-28
2024-04-28
2024-04-28
2024-04-28
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0