zoukankan      html  css  js  c++  java
  • 数据库函数

    #定义函数:

    delimiter //   #定义结束符
    create function myadd(a int , b int)
    returns int
    begin
    declare c int default 0;
    set c = a + b;
    return c;
    end
    //
    delimiter ;  #将结束符定义回来
    select myadd(3,4);

    #会话变量
    set @b = myadd(3,4);
    select @b;

    #if的使用

    delimiter //
    create function myfunc(a int )
    returns varchar(10)
    begin
    declare c varchar(10) default '';
    if(a>0) then set c = '大于0';
    elseif(a=0) then set c = '等于0';
    else set c = '等于0';
    end if;
    return c;
    end
    //
    delimiter ;
    select myfunc(3);

    #删除函数

    drop function if exists myfunc;

    #case

    1.    delimiter //
      create function myfun(a int)
      returns varchar(10)
      begin
        declare c varchar(10) default '';
        case when a >0 then set c = 'dayu0';
        when a =0 then set c = 'dengyu0';
        else set c = 'xiaoyu0';
        end case;
        return c;
      end //
      delimiter ;
    drop function if exists myfun;
    2. delimiter //
      create function myfun(a int)
      returns varchar(10)
      begin
        declare c varchar(10) default '';
        case a when 1 then set c = 'dayu0';
        when 2 then set c = 'dengyu0';
        else set c = 'xiaoyu0';
        end case;
        return c;
      end //
      delimiter ;

    #while do

    delimiter //
    create function myfun(a int)
    returns int
    begin
      declare c int default 0;
      declare i int default 1;
      out_label :BEGIN
      while 1=1 do
      set c= c+i;
      set i = i+1;
      if(i>=a) then leave out_label;
      end if;
      end while;

      END out_label;
      return c;
    end //
    delimiter ;

  • 相关阅读:
    Struts2笔记——ONGL表达式语言
    Struts2笔记——自定义拦截器
    Struts2笔记——Action校验器
    Struts2笔记——文件上传
    Struts2笔记——与ServletAPI解耦
    Struts2笔记——通配符和动态方法调用
    Struts2笔记——类型转换
    Struts2笔记——result结果类型
    MongoDB相关资料
    公开数据集
  • 原文地址:https://www.cnblogs.com/Lune-Qiu/p/8666163.html
Copyright © 2011-2022 走看看