MySQL Stored procedure debugging method

Source: Internet
Author: User

    • Like the next stored procedure
CREATE PROCEDURE' P_next_id ' (kind_nameVARCHAR( -), I_lengthint, currentseqnoVARCHAR(3), Out O_resultINT)BEGIN      SET @a= NULL; SET @b= NULL; SELECTId into @a  fromT_seqWHERE  Number=Currentseqno andLength=I_length;
IF(@a is NULL) Then Select min(ID) into @a fromT_seqwhereLength=i_length; Select Number into @b fromT_seqWHEREId= @a;ELSE Select Number into @b fromT_seqWHEREId= @a+1; END IF; SELECT @b intoO_result; END
    • Calling a stored procedure in Navicat  
    1. Write statement invocation
Call p_next_id ('t_factory',2,'0',@result ); -The above stored procedure contains four parameters, so when called here, it is also necessary to pass 4 parameters: input parameters to fill in the value, the output parameter is represented by a variable @resultselect@result; -This is the value of the variable displayed on the console

2. Window click

Directly click Run, enter in the popup input box: ' T_factory ', 2, ' 0 ', @result

    • Track stored procedure execution steps

MySQL does not have plsqldevelper tools for debugging stored procedures like Oracle, so there are two simple ways to track the execution process:

    1. Record the debugging process with a temporary table
    2. Directly in the stored procedure, add the Select @xxx and view the results in the console:

For example, I add some query statements to the stored procedure above (note the red statement below)

CREATE PROCEDURE' P_next_id ' (kind_nameVARCHAR( -), I_lengthint, currentseqnoVARCHAR(3), Out O_resultINT)BEGIN      SET @a= NULL; SET @b= NULL; SELECTId into @a  fromT_seqWHERE  Number=Currentseqno andLength=i_length;
  SELECT @a; IF(@a is NULL) Then Select min(ID) into @a fromT_seqwhereLength=i_length; Select Number into @b fromT_seqWHEREId= @a;
     Select @b; ELSE Select Number into @b fromT_seqWHEREId= @a+1; END IF; SELECT @b intoO_result; END

MySQL Stored procedure debugging method

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.