• mysql——使用——存储函数——示例


    前期数据准备:

    create
    table employee ( num int(50), d_id int(50), name varchar(50), age int(50), sex varchar(50), homeadd varchar(50) ); insert into employee values(1,1001,'zhangsan',26,'nan','beijing'); insert into employee values(2,1001,'lisi',24,'nv','hunan'); insert into employee values(3,1002,'wangwu',25,'nan','jiangsu'); insert into employee values(4,1004,'aric',15,'nan','yingguo'); select * from employee; create table department ( d_id int(50), d_name varchar(50), functione varchar(50), address varchar(50) ); insert into department values(1001,'keyanbu','yanfachanpin','3lou5hao'); insert into department values(1002,'shengchanbu','shengchanchanp','5louyiceng'); insert into department values(1003,'xiaoshoubu','cehuaxiaoshou','1louxiaoshoudating'); select * from employee; select * from department;

    定义一个存储函数:

    delimiter &&
    
    create function name_from_employee ( emp_id INT )
    
    returns varchar(20)
    
    begin
    
         return ( select name from employee where num = emp_id );
    
    end &&
    
    delimiter;

    查看此存储函数的状态:

    show function status like 'name_from_employee';

    查看此函数的定义:

    show create function name_from_employee;

    调用此函数:

    select name_from_employee(3);

    删除此函数:

    drop function name_from_employee;

  • 相关阅读:
    LeetCode-1-two-sum
    LeetCode-14-longest-common-prefix
    动态规划--矩阵链乘法
    动态规划--装配线调度算法
    LeetCode-9-palindrome-number
    LeetCode-8-string-to-integer-atoi
    LeetCode-7-Reverse Integer
    SElinux用户管理操作
    Minix3信号处理分析
    面对困难
  • 原文地址:https://www.cnblogs.com/xiaobaibailongma/p/12097925.html
Copyright © 2020-2023  润新知