Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.0 » SQL Anywhere Server - SQL Usage » Stored Procedures and Triggers » Debugging procedures, functions, triggers, and events » Tutorial: Getting started with the debugger » Lesson 2: Debug a stored procedure

 

Confirm the diagnosis and fix the bug

You can test the hypothesis that the problem is the lack of initialization for top_value right in the debugger, without changing the procedure code.

To test the hypothesis

  1. In the Debugger Details window, click the Local tab.

  2. Click the Top_Value variable and type 3000 in the Value field.

  3. Press F11 repeatedly until the Value field of the This_Value variable is greater than 3000.

  4. Click the breakpoint so that it turns gray.

  5. Press F5 to execute the procedure.

    The Interactive SQL window appears again. It shows the correct results.

    top_company top_value
    Chadwicks 8076

The hypothesis is confirmed. The problem is that the top_value is not initialized.

To fix the bug

  1. Choose Mode » Design.

  2. In the right pane, locate the following statement:

    OPEN cursor_this_customer;
  3. Type a new line that initializes the top_value variable:

    SET top_value = 0;
  4. Choose File » Save.

  5. Execute the procedure again, and confirm that Interactive SQL displays the correct results.

You have now completed the lesson. Close any open Interactive SQL windows.