mysql创建函数和存储过程

查询出的一张表里只有用户的id,想获取出姓名,关联表又觉得麻烦,所以想用存储过程或者函数来解决:
创建存储过程:

drop procedure if exists hello;
--/
create  procedure hello(t_id int) 
begin
    
    declare x varchar(10) default 'x';  
    select  username into x from sys_user where user_id=t_id;
   
    select  x;
end;/

–/ / 是DbVisualizer中需要加这个,别的工具可忽略

创建函数:

drop function if exists hello
--/
create function  hello(t_id int ) returns varchar(10)
begin
        declare x varchar(10) default 'x'; 
         select  username into x from sys_user where user_id=t_id;
        return x;
end
/

执行:
存储过程:call hello(1);
函数:select hello(1);

可以这么 将函数使用,mysql不如informix灵活,只能写函数,不能这样写存储过程,mysql*必须紧跟select ????,函数存储过程也不能类似与java的重载????;
select hello(1),username from sys_user

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值