Subject Using "twice-dynamic" SQL in a stored procedure
Author mizbrodin
I have a set of tables having the same structure like "CREATE TABLE
tables_list1 (tblname VARCHAR(128))" (let's call them "list tables").
These list tables contain the names of some other tables (let's call
them "referenced tables"). I need to implement a stored procedure,
which would accept the name of a list table via an input parameter and
perform some actions on the referenced tables (granting different
permissions on these tables, to be more precise). I would use a query
like "FOR SELECT ... DO", but such a query requires the usage of a
static table name, while in my case the table name is a variable (a
parameter passed to my stored procedure). Is anybody aware of any
solutions or workarounds for this problem?

Note, that I could do it using dynamic SQL generated in the code of my
application without any problems, but for performance reasons I have
to perform these operations using a stored procedure. So, the usage of
a stored procedure is a mandatory requirement. I already implemented
such kind of stored procedures for both SQL Server and Oracle, but
have been stuck with Firebird.

Thanks a lot in advance for any help.

(I'm using Firebird 2.1)