delimiter $
create function getname (id int)
returns varchar(30)
begin
declare name varchar(30);
select sname into name from student where sid=id;
return name;
end
$

delimiter ;
;

delimiter 关键字:把原有以分号结尾语句的标识改成自定义的,我这里改成了$ ,作用是为了在详细语句中不会直接提交操作
getname :函数名
(id int):参数列表
returns varchar(30):返回值类型

begin....end:语句块

$:结束标识,我们上面已经把结束标识定义为这个了

delimiter ;:把结束标识重新定义为分号

MYSQL数据库学习(五)如何自定义函数

 

删除函数:DROP FUNCTION IF EXISTS function_name;

查看所有自定义函数, 自定义函数只能在本数据库使用: show function status [like 'pattern'];

查看函数创建语句:show create function 函数名;  

 

相关文章:

  • 2021-12-16
  • 2021-10-18
  • 2021-09-30
  • 2020-02-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
猜你喜欢
  • 2021-10-19
  • 2021-05-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2020-10-23
相关资源
相似解决方案