Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8570393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:32:52+00:00 2026-06-11T18:32:52+00:00

Create procedure count_loop( p_start int, p_stop int, p_step int unsigned, p_delim varchar(5)) begin declare

  • 0
Create procedure count_loop( p_start int, 
                               p_stop int,
                               p_step int unsigned, 
                               p_delim varchar(5))
begin
declare v_start int ;
declare v_stop int ;
declare v_step int ;
declare v_sign int;
declare v_sum int;

-- check p_start
case p_start
when null then
    set v_start := 1;
else
    set v_start := p_start;
end case;

-- check p_stop
case p_stop
when null then
    set v_stop := 10;
else
    set v_stop := p_stop;
end case;

-- check p_stop
case p_step
when null then
    set v_step := 1;
when 0 then
    set v_step := 1;
else
    set v_step := p_step;
end case;

-- set v_sign as v_stop - v_start 
set v_sign := (v_stop - v_start) ;


case
-- if v_sign and v_step are negative, 
-- then run while loop
when v_sign < 0 and v_step < 0 then
    while v_start > v_stop then
        set v_start = v_start + v_step ; 
        select v_start as 'The Loop Output';
        set v_step = v_step - 1;
    end while;
-- if both v_sign and v_step are positive 
-- then run loop
when v_sign > 0 and v_step > 0 then
    while v_start > v_stop then
        set v_start := v_start + v_step ; 
        select v_start as 'The Loop Output';
        set v_step := v_step + 1;
    end while; 
-- if v_sign and v_step are different signs
-- terminate loop
when v_sign > 0 and v_step < 0 then
    select 'Loop collapsed' as 'The Loop Output' ; 
when v_sign < 0 and v_step > 0 then
    select 'Loop collapsed' as 'The Loop Output' ;
end case ;

end;
#

I’m looping through a series of arithmetic sequences. This code should either add or subtract, depending on the first what the first two parameters are. Then we check if the step value is positive or negative.
I’m getting an error that says to check the syntax at:

set v_start = v_start + v_step ; 
        select v_start as 'The Loop Output';
        set v_step = v_step - 1;

So then I deleted the two when statements that contain that and ran my code through. There were no errors. But now I’m not sure what to do next.
I don’t see what needs to be corrected. Any suggestions? Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:32:53+00:00Added an answer on June 11, 2026 at 6:32 pm

    Your error is in the while v_start > v_stop then right above the snippet you posted. It should read while v_start > v_stop do instead. (Actually, you have it in a couple of places; check every while statement.)

    See the MySQL documentation here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this SQL now: CREATE PROCEDURE dbo.sel_Track_HitsLast30Days( @projectID int ) AS BEGIN DECLARE
Create procedure a06_generate_data( p_loop_count int, p_min int, p_max int, p_status char(1)) begin declare v_max
Given this : delimiter // create procedure setup() begin declare d datetime; set d
I have following stored procedure: CREATE PROCEDURE testProc(IN p_idProject INTEGER) BEGIN DECLARE nowTime DATETIME;
CREATE PROCEDURE [test].[proc] @ConfiguredContentId int, @NumberOfGames int AS BEGIN SET NOCOUNT ON RETURN @WunNumbers
delimiter // create procedure sp_AttendReportCountWorkouts(OUT cnt INT) begin select count(*) into cnt from workout_details;
My current code is : DELIMITER \\ CREATE PROCEDURE sample (IN _car VARCHAR(15)) BEGIN
I have a stored procedure :- CREATE procedure St_Proc_GetTimeEntryID @userID int, @timeEntryID int output
I have the fallowing stored procedure: CREATE PROCEDURE `get`(IN tb VARCHAR(50), IN id INTEGER)
I have a T-SQL stored procedure with the signature CREATE PROCEDURE MyProc @recordCount INT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.