Can someone explain to me the syntax of the For loop in Firebird?
Here is the code I have so far:
As
Declare variable Var1 integer;
begin
Insert into table1
-- Select query to insert some enteries in table 1 - Done successfully.
FOR SELECT table1.Column1 from table1 into :Var1
Do
Begin
Update tableabc.column1 = (select tablexyz. column1 from tablexyz where tablexyz.ID = :Var1) where tableabc.ID = :Var1
End
Update : Thanks for giving it a try but i dont see any major difference between the query that i wrote and query included in answers. Although above query runs successfully at my end but when i see data in table there occurs no update.
Actually i was making a v.dumb mistake, i was executing alter stored procedure query – which runs successfully and i was assuming this would make the necessary changes. later i executed the stored procedure and it worked pefectly . Thanks all for sparing your time 🙂 ..
For operator in Firebird is not like For, say, in Pascal where it increments loop variable and executes a block of code until finish value will be met.
In Firebird For operator takes a set of records (result of execution of a query) and loops through them. For every record a block of code will be executed. Optionally values of some fields from the record could be put into local variables enlisted in INTO section. Values of such variables could be used inside a block of code.
In your example a query:
Will be executed and for every record in result set will be executed operator:
For it variable :Var will contain value of table1.Column1 of current record.