您的位置:首页 > 数据库 > MySQL

mysql 自定义函数(2)操作sql语句

2017-12-31 14:00 465 查看
1、操作select 语句:

drop function if exists hello;
create function hello(a int) returns varchar (255)
begin
declare x varchar(255);
select `name` into x from gl_dept where id = a;
return x;
end;


其中“select
name
into x from gl_dept where id = a;”里面的“into x“,只是一个给字段添加别名的方式,必须添加,而且别名必须是声明过的。

调用方式:

select hello (5);


结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  函数 mysql