DROP FUNCTION IF EXISTS myf1;
CREATE FUNCTION myf1() RETURNS INT
BEGIN

    DECLARE p INT DEFAULT 0;
    DECLARE c INT DEFAULT 0;#定义局部变量
    DECLARE d INT DEFAULT 0;#定义局部变量
    while c = 0 do
    		select min(id) into p from all_port where status = '0';
    		update all_port set status = '1' where id = p and status = '0';
    		set c = row_count();
    		
    		select sleep(1) into d;
    end while;
    
    RETURN p;
END;


select myf1();
select * from all_port;

 

 

本站所有内容均为原创,本站保留所有权利。在保留原始来源链接的情况下,允许非商业用途的转载。拒绝一切商业性转载。

picture loss