CREATE PROCEDURE `p_next_id`(kind_name VARCHAR(30), i_length int,currentSeqNo VARCHAR(3),OUT o_result INT) BEGIN SET @a= NULL; SET @b= NULL; SELECT id INTO @a FROM t_seq WHERE number= currentSeqNo and length= i_length ; IF (@a is null ) THEN select min(id) into @a FROM t_seq where length = i_length; select number INTO @b FROM t_seq WHERE id = @a;ELSE select number INTO @b FROM t_seq WHERE id = @a+1; END IF; SELECT @b INTO o_result; END
call p_next_id('t_factory',2,'0',@result); -- 上面的存储过程含有四个参数,所以这里调用的时候,也需要传递4个参数:输入参数填写值,输出参数用变量表示@result select @result; -- 这句话是在控制台显示变量值
2. 窗口点击
直接点击运行时,在弹出输入框输入:'t_factory',2,'0',@result
mysql不像oracle有plsqldevelper工具用来调试存储过程,所以有两简单的方式追踪执行过程:
例如我把上面的存储过程中加一些查询语句(注意下面的红色语句)
CREATE PROCEDURE `p_next_id`(kind_name VARCHAR(30), i_length int,currentSeqNo VARCHAR(3),OUT o_result INT) BEGIN SET @a= NULL; SET @b= NULL; SELECT id INTO @a FROM t_seq WHERE number= currentSeqNo and length= i_length ; SELECT @a; IF (@a is null ) THEN select min(id) into @a FROM t_seq where length = i_length; select number INTO @b FROM t_seq WHERE id = @a; select @b; ELSE select number INTO @b FROM t_seq WHERE id = @a+1; END IF; SELECT @b INTO o_result; END
转自:https://www.cnblogs.com/firebata/p/4585978.html