The purpose of this page is to describe an alternative for Dbms_Sql when you need to execute dynamic PL/SQL within IFS Applications. Execute Immediate is easier to use and sometimes more efficient than using Dbms_Sql. The syntax of Execute Immediate is straight forward, more or less write your piece of PL/SQL and execute it. If possible conditional compilation as described in Dynamic calls to optional components should be used.
If the SQL statement is self-contained, requires no bind variables, then we can use Execute Immediate in its simplest form.
EXECUTE IMMEDIATE statement_;
If you have bind variables you need to use the Using clause.
EXECUTE IMMEDIATE statement_ USING IN variable_;
For more details, please study the Oracle documentation about the subject.
Below we list the benefits for Execute Immediate over Dbms_Sql
Drawbacks
This section tries to describe when you should use Execute Immediate and when to use Dbms_Sql. Of course you may have other reasons to use the other alternative and vice verse.
You can/should use Execute Immediate when
%FOUND
, %ISOPEN
, %NOTFOUND
,
or %ROWCOUNT
after issuing a dynamic SQL statement that
is an INSERT
, UPDATE
, DELETE
,
or single-row SELECT
statement.You must use Dbms_Sql when you don't know
SELECT
list
What placeholders in a SELECT
or
DML statement must be bound