Unit 18.4. Use Dynamic SQL

What is Dynamic SQL?

Dynamic SQL allows you to construct a string and then run it as an SQL statement at runtime. It is useful when you do not know exactly what your SQL statement is going to look like. This might happen on the Web because you will run a different SQL depending on what a user submits in a FORM.

You can construct queries that have different conditions or different ORDER BY clauses. You can even decide to query completely different tables. You could also add optimizer hints to your query at runtime.

Along with SELECT queries, Dynamic SQL can be used to execute DDL within PL/SQL. Normally, you are not permitted to execute DDL such as a GRANT or CREATE TABLE or DROP SYNONYM statement. However, you can ...

Get Oracle® Web Application Programming for PL/SQL® Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.