存储过程简单Demo

时间:2022-12-24 14:05:12
--创建存储过程
delimiter //
create procedure p1()
begin
end //

--调用存储过程
call p1();

--删除存储过程
drop procedure p1;
drop procedure if exists;

--检查存储过程
show create procedure p1;

--完整的例子
delimiter //
create procedure p1()
begin
--Declare local variables
declare done boolean default 0;
declare o int;

--Declare the cursor
declare emp_cur cursor
for
select empno from EMP;

--Declare continue handler
declare continue handler for sqlstate '02000' set done=1;

--open the cursor
open emp_cur;

--loop through all rows
repeat

--get empno
fetch empno into 0;
--End of loop
until done end repeat;

--close the cursor
close emp_cur;
end //