The simplest way to debug the stored procedure in Mysql is to debug the stored procedure in mysql.

Source: Internet
Author: User

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

  • Procedure

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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.