MySQL語法複習 儲存過程與儲存函式

2021-07-23 22:27:53 字數 1829 閱讀 8514

1.建立儲存過程

use mysql_test;

drop procedure if exsits sp_update_***;

delimiter $$

create procedure sp_update_***(in cid int,in *** char(1))

begin

update customers set cust_*** = c*** where cust_id = cid;

end $$​

​2.儲存函式

use mysql_test;

delimiter $$

create function f_up***(fid int)

returns char(1)

deterministic

begin

declare *** char(1);

select cust_*** into *** from customers where fid=​cust.id;

if *** is null then

return(select'沒有該使用者');

else if *** ='f' then

return (select'女');

else

return(select'男')

end if;

end $$​

​3.游標

宣告----declare cur_employee cursor for select age,name ​from employee;

開啟----open cursor_name;

使用----fetch cur_name into varname;

關閉----close cursor_name;​

1.建立儲存過程

use mysql_test;

drop procedure if exsits sp_update_***;

delimiter $$

create procedure sp_update_***(in cid int,in *** char(1))

begin

update customers set cust_*** = c*** where cust_id = cid;

end $$​

​2.儲存函式

use mysql_test;

delimiter $$

create function f_up***(fid int)

returns char(1)

deterministic

begin

declare *** char(1);

select cust_*** into *** from customers where fid=​cust.id;

if *** is null then

return(select'沒有該使用者');

else if *** ='f' then

return (select'女');

else

return(select'男')

end if;

end $$​

​3.游標

宣告----declare cur_employee cursor for select age,name ​from employee;

開啟----open cursor_name;

使用----fetch cur_name into varname;

關閉----close cursor_name;​

mysql語法例項 mysql 儲存過程語法及例項

1 下面為乙個儲存過程的定義過程 create procedure proc name in parameter integer begin declare variable varchar 20 if parameter 1 then set variable mysql else set var...

mysql的儲存過程初識 初識MySQL儲存過程

儲存過程 stored procedure 是一組為了完成特定功能的sql語句集,經編譯後儲存在資料庫中,使用者通過指定儲存過程的名字並給定引數 如果該儲存過程帶有引數 來呼叫執行它。mysql 儲存過程是從mysql 5.0開始增加的新功能。大大提高資料庫的處理速度,同時也可以提高資料庫程式設計的...

mysql儲存過程基本語法

1變數 declare宣告變數 set賦值 變數型別 int,integer bigint float double decimal precision,scale numeric precision,scale date datetime char length varchar length bl...