Mysql 存储过程、临时变量定义、IF、Case

来源:互联网 发布:用java写一个登陆界面 编辑:程序博客网 时间:2024/05/01 20:34
-- Mysql 存储过程/*set @result = 0;create procedure login(-- 定义参数,有in、out、inout三种类型in user varchar(10),in pass varchar(10),out result int)begin declare passd varchar(10);-- declare 声明临时变量、类型,然后用set 进行赋值,declare 临时变量只能放在begin end 区域中,而其作用域也只是在begin end 中, 而 set @ 定义的变量是全局变量select password into passd from login where username=user;if passd like pass then--  If 语句,后面要加上 End IF,就像是case 后也要加 End Case  一样select 'Login Success' as Massage;set result = 1;elseselect 'Login Failed' as Message;set result =0;end if;end;*/-- 调用存储过程  call login('root','root',@result);-- 删除存储过程  drop procedure logincreate procedure translate(id int)begincase idwhen 1 then   select 'one' as trans;when 2 thenselect 'two' as trans;when 3 then select 'three' as trans;elseselect 'no trans' as trans;end case;end;/*case 用法有两种:1. 条件变量在when 中select name, casewhen age>10 then xxxxxelsexxxxxxend case2. 条件变量在case 中select name,case agewhen >10 then xxx else xxxxxsend case*/

原创粉丝点击