mysql中的存儲過程和遊標
阿新 • • 發佈:2018-07-09
out when success gin int tran if 語句 arc username
-- 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;
else
select ‘Login Failed‘ as Message;
set result =0;
end if;
end;
*/
-- 調用存儲過程 call login(‘root‘,‘root‘,@result);
-- 刪除存儲過程 drop procedure login
create procedure translate(
id int
)
begin
case id
when 1 then
select ‘one‘ as trans;
when 2 then
select ‘two‘ as trans;
when 3 then
select ‘three‘ as trans;
else
select ‘no trans‘ as trans;
end case;
end;
/*
case 用法有兩種:
1. 條件變量在when 中
select name, case
when age>10 then xxxxx
else
xxxxxx
end case
2. 條件變量在case 中
select name,case age
when >10 then xxx
else xxxxxs
end case
*/
mysql中的存儲過程和遊標