Stored procedure looping

Ivan Smahin ivan_smahin at paradigmasoft.com
Tue Dec 11 07:06:57 CST 2007


Hello Mr.,

Tuesday, December 11, 2007, 2:51:07 PM, you wrote:

>>>   create or replace procedure cm_spBuildDefaultRatingSystem()
>>>    begin
>>>    DECLARE mylastrecid Long;
>>>    DECLARE counter INT;
>>>    SET counter = 100;
>>>    insert into
>>> tbl_rating_systems(rs_name,rs_description,creation_dt)
>>> values ('cm_spBuildDefaultRatingSystem','score system generated by
>>> CoreManager',NOW());
>>>    set mylastrecid = select Last_RecID();
>>>    REPEAT
>>>    insert into tbl_score_levels
>>> (levelname,leveldescription,objptr_rs,ranking) values
>>> (counter,'--',mylastrecid,(100-counter)+1);
>>>    SET counter = counter -1;
>>>    UNTIL counter < 0
>>>    END repeat
>>>    exception
>>>    when others then
>>>    call cm_CoreErrorHandler('cm_spBuildDefaultRatingSystem');
>>>    end;
>>
>>> This procedure is accepted and when run creates 2 records
>>> 1) 1 record in tbl_rating_systems--> perfect
>>> 2) 1 record in tbl_score_levels--> unexpected result it seems the
>>> loop runs only once. Why ?
>>
>> It should be: UNTIL counter >= 0

> But I want my counter to insert values 100----->0 (inclusive) so it
> is UNTIL counter < 0

> The repeat has to loop until counter is smaller than 0 ;

> The same logic using repeat....until does not work. Something is
> wrong here I think UNLESS repeat...until means repeat....while ?

Yes, it is wrongfully implemented as do{}while();
Report it to Mantis please.


-- 
Best regards,
Ivan Smahin 
Senior Software Engineer
Paradigma Software, Inc
Valentina - The Ultra-Fast Database
http://www.valentina-db.com



More information about the Valentina mailing list