mysql存储过程,有输入输出的

DELIMITER //;

CREATE  PROCEDURE queryTotalNum(OUT totalNum INT , IN tableName varchar(40), IN conditions varchar(300))
begin    
    declare stmt varchar(2000);   
    declare num int;
    if LENGTH(conditions)>1 then  
	begin
		set @sqlstr=concat('SELECT COUNT(*) INTO @num from ',tableName,' where ',conditions);
	end;
	else
	begin
		 set @sqlstr=concat('SELECT COUNT(*) INTO @num from ',tableName);
	end;
    end if;  
    prepare stmt from @sqlstr;    
    execute stmt;  
    deallocate prepare stmt;
    set totalNum = @num;

    end;

 

你可能感兴趣的:(mysql,数据库,procedure)