Oracle: EXECUTE IMMEDIATE is the replacement for DBMS_SQL package from Oracle 8i onwards. It parses and immediately executes a dynamic SQL statement or a PL/SQL block created on the fly. Dynamically created and executed SQL statements are performance overhead, EXECUTE IMMEDIATE aims at reducing the overhead and give better performance. It is also easier to code as compared to earlier means. The error messages generated when using this feature are more user friendly. Though DBMS_SQL is still available, it is advisable to use EXECUTE IMMEDIATE calls because of its benefits over the package.
Note: EXECUTE IMMEDIATE will not commit a DML transaction carried out and an explicit commit should be done.
Last Wiki Answer Submitted: June 3, 2004 1:50 pm by Galvtx0 pts.
If you live outside the United States, by submitting your email address you consent to having your personal data transferred to and processed in the United States.
Some additional info:
You have to use refcursor fetches for multirow queries.
Execute immediate is for single row queries or multirow dml.
Native dynamic sql cannot be used for statements more than 32K in length (varchar2 limitation), the dbms_sql can parse statements assembled in dbms_sql’s varchar2s array type. If you are into huge sql statements you still have to use dbms_sql. I use dbms_sql.varchar2s to create some complex views that may excedd 32K in length.
Some additional info:
You have to use refcursor fetches for multirow queries.
Execute immediate is for single row queries or multirow dml.
Native dynamic sql cannot be used for statements more than 32K in length (varchar2 limitation), the dbms_sql can parse statements assembled in dbms_sql’s varchar2s array type. If you are into huge sql statements you still have to use dbms_sql. I use dbms_sql.varchar2s to create some complex views that may excedd 32K in length.