william.david.anderson@gmail.com wrote:
> Thanks much for your reply. Is there a benefit to using PREPARE
> statements in an SQL stored procedure?
There can be.
Dynamic SQL is beneficial when you compose SQL statements within the
stored procedure (beware of SQL Injection!) or you want to execute DDL
statements not directly supported by the syntax.
For DDL statements folks typically use EXECUTE IMMEDIATE though since
the statement is executed only once.
One example to use PREPARE is to perform recursive CALLs to the
procedure you are just creating. It is the only way how a procedure can
call itself.
Other examples are cursors for which the exact WHERE clause is not known
in advance.
Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab