The simplest way to debug the stored procedure in Mysql is to debug the stored procedure in mysql.
My colleague told me to use a temporary table to Insert variable data for viewing, but this method is too troublesome, and Mysql does not have a good tool for debugging stored procedures. Today, google found that you can use the select + variable name Method for debugging... It makes me feel ashamed.
Specific Method:
Add the following statement to your stored procedure:
SELECT variable 1, variable 2;
Use the cmd program that comes with mysql to enter mysql>.
Call your stored procedure name (input parameter 1, @ output parameter); (Note: to help new students, if your stored procedure has output variables, here, you only need to add @ and then use any variable name );
You can see that your variable value is printed to cmd. Is that simple? I hope this will help you.
==================================
- Like the next Stored Procedure
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 the stored procedure in navicat
Call p_next_id ('t _ factory ', 2, '0', @ result); -- the preceding Stored Procedure contains four parameters, four parameters must also be passed: Enter the value of the input parameter, and use the variable to represent @ resultselect @ result; -- the variable value is displayed on the console.
2. click in the window
Directly click "run". In the displayed input box, enter: 't_factory ', 2, '0', @ result
Unlike oracle's plsqldevelper tool, mysql has two simple ways to trace the execution process:
For example, I add some query statements to the above Stored Procedure (note the red statements below)
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