本文实例讲述了Mysql自定义函数原理与用法。分享给大家供大家参考,具体如下: 本文内容: 什么是函数 函数的创建 函数的调用 函数的查看 函数的修改 函数的删除 首发日期:2018-04
本文实例讲述了Mysql自定义函数原理与用法。分享给大家供大家参考,具体如下:
首发日期:2018-04-18
-- 不行的代码:Not allowed to return a result set from a function
create function myf()returns int
begin
select * from student;
return 100;
end;
create function 函数名([参数列表]) returns 数据类型
begin
sql语句;
return 值;
end;
-- 最简单的仅有一条sql的函数
create function myselect2() returns int return 666;
select myselect2(); -- 调用函数
--
create function myselect3() returns int
begin
declare c int;
select id from class where cname="python" into c;
return c;
end;
select myselect3();
-- 带传参的函数
create function myselect5(name varchar(15)) returns int
begin
declare c int;
select id from class where cname=name into c;
return c;
end;
select myselect5("Python");
-- 无参调用
select myselect3();
-- 传参调用
select myselect5("python");
select * from class where id=myselect5("python");
更多关于MySQL相关内容感兴趣的读者可查看本站专题:《MySQL常用函数大汇总》、《MySQL日志操作技巧大全》、《MySQL事务操作技巧汇总》、《MySQL存储过程技巧大全》及《MySQL数据库锁相关技巧汇总》
希望本文所述对大家MySQL数据库计有所帮助。
--结束END--
本文标题: mysql自定义函数原理与用法实例分析
本文链接: https://www.lsjlt.com/news/9546.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-04-30
2024-04-30
2024-04-30
2024-04-30
2024-04-30
2024-04-30
2024-04-30
2024-04-30
2024-04-30
2024-04-30
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0