Subject Re: [firebird-support] FOR SELECT... CURSOR?
Author Martijn Tonies
Hi,

> I have just a little question...
> Is there a considerable difference between these two ways to update a
table
> in a stored proc?
>
> 1)
> FOR
> SELECT APrimaryKeyField
> FROM ATable
> WHERE SomeCondition
> INTO :AVariable
> DO
> BEGIN
> /* Some Stuff... */
> UPDATE ATable
> SET SomeField = SomeValue
> WHERE APrimaryKeyField = :AVariable;
> END
>
> 2)
> FOR
> SELECT Whatever
> FROM ATable
> WHERE SomeCondition
> INTO :SomeDummyVar
> AS CURSOR SomeCursor
> DO
> BEGIN
> /* Some Stuff... */
> UPDATE ATable
> SET SomeField = SomeValue
> WHERE CURRENT OF SomeCursor
> END
>
> At first glance I'd have thought the second way is the best, but I wonder
> what the group's opinion is...

The second one will be slightly faster.

IMO, choose what you will be able to maintain and read.

Martijn Tonies
Database Workbench - tool for InterBase, Firebird, MySQL, Oracle & MS SQL
Server
Upscene Productions
http://www.upscene.com
My thoughts:
http://blog.upscene.com/martijn/
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com