create procedure stats()
begin
declare k char(32);
declare tbl char(1);
declare done int default 0;
declare cur cursor for select `key`,`table` from `index`;
declare continue handler for sqlstate '02000' set done=1;
open cur;
repeat
fetch cur into k,tbl;
set @total = 0;
set @inqueue = 0;
set @sql = concat('select count(dk) into @total from `',tbl);
set @sql = concat(@sql,'` where `k`=\'');
set @sql = concat(@sql,k);
set @sql = concat(@sql,'\'');
prepare st from @sql;
execute st;
set @sql = concat('select count(dk) into @inqueue from `',tbl);
set @sql = concat(@sql,'` where `k`=\'');
set @sql = concat(@sql,k);
set @sql = concat(@sql,'\' and f=0');
prepare st from @sql;
execute st;
select k as `key`,@total as total,@inqueue as inqueue;
until done end repeat;
close cur;
end
mysql儲存過程中使用事件
create definer root localhost procedure createbusiness parameter1 int begin routine body goes here.declare flag int default parameter1 宣告變數flag,將引數值賦給...
mysql儲存過程中使用事務
mysql儲存過程中使用事務 1 drop procedure ifexists test sp1 2create procedure test sp1 3begin 4declare t error integer default 0 5declare continue handler for s...
mysql儲存過程中變數的使用
在mysql儲存過程中,宣告乙個變數可以使用declare vi num 變數名 int 資料型別 的方式。還可以直接使用 變數名的方式,直接使用乙個變數。請看以下儲存過程 drop procedure if exists pro2 create procedure pro2 begin decla...