Subject | Re: [firebird-support] I need help-Syntax error - ; |
---|---|
Author | Paul Vinkenoog |
Post date | 2012-08-21T00:18:14Z |
Hi Farshid,
Because of the endless loop, the code below will never be reached:
Not sure if this is all that's wrong, but it's a start! ;-)
HTH,
Paul Vinkenoog
> What is the problem with the following code?Without examining it very closely, I see several problems:
> CREATE PROCEDURE SPTRYou don't specify any output parameters. But the SUSPEND later on suggests that you want to return something to the caller. So you need a RETURNS clause.
> ASThe WHILE loop will never end, because there is no LEAVE statement and 1=1 will remain true forever. You probably want something like "if (row_count = 0) then leave;" after the fetch. BTW, what if the first fetch (before loop entry) returns no data? Your code doesn't seem prepared for that.
> DECLARE VARIABLE price INTEGER;
> DECLARE VARIABLE price1 INTEGER;
> DECLARE VARIABLE eid SMALLINT;
> DECLARE VARIABLE bsum INTEGER DEFAULT 0;
> DECLARE VARIABLE SCTN CURSOR FOR (
> Select ID,DBR,CDR
> From TBL_Transactions
> ORDER BY SDate);
> BEGIN
> OPEN SCTN;
> FETCH SCTN INTO eid, price,price1;
> WHILE (1=1) DO
> BEGIN
> bsum = bsum + (price-price1);
> update TBL_TRANSACTIONS set CBALANCE = bsum where Id = eId;
> FETCH SCTN INTO eid, price,price1;
> END
Because of the endless loop, the code below will never be reached:
> CLOSE SCTN;You have to select those values INTO local variables and/or output parameters.
> --DEALLOCATE SCTN;
>
> SELECT ID,DBR,CDR FROM TBL_TRANSACTIONS ORDER BY SDate;
> SUSPEND;SUSPEND gives the caller the opportunity to fetch the current row of output parameters. But as said before, you haven't declared any.
Not sure if this is all that's wrong, but it's a start! ;-)
HTH,
Paul Vinkenoog