Principles of Dynamic SQL
Dynamic SQL enables you to execute SQL statements placed in a string variable instead of explicitly writing the statements inside a program. This allows SQL statements to be constructed within an application program. These facilities are typically used in interactive environments, where SQL statements are submitted to the application program from the terminal.
An example of when dynamic SQL is needed would be a program for interactive SQL, where any correct SQL statement may be entered at the terminal and processed by the application. Limited dynamic facilities may however be provided by relatively simple application programs.
SQL Statements and Dynamic SQL
The following classes of SQL statements may be submitted to programs using dynamic SQL. Statements excluded from dynamic applications are declarations, diagnostic statements and dynamic SQL statements themselves.
- Access control statements:
- Data definition statements:
- Security control statements:
- Transaction control statements:
- Data manipulation statements:
- System administration statements:
Statements may be submitted to dynamic SQL applications in two forms:
- Fully defined statements, written exactly as they would be submitted to interactive SQL. For example:GRANT SELECT ON mimer_store_book.details TO mimer_admin_group SELECT code, country FROM mimer_store.countries SELECT price INTO :PRICE FROM mimer_store.items WHERE item_id = :ITEM_ID
- Statements with parameter markers, which identify positions where the value of a host variable will be inserted when the statement is executed or the cursor is opened. A parameter marker is represented by a question mark ?. For example:UPDATE mimer_store.currencies SET exchange_rate = ? WHERE code = ? DELETE FROM countries WHERE code = ? SELECT currency, exchange_rate * ? FROM mimer_store.currencies WHERE code IN (SELECT currency_code FROM mimer_store.countries WHERE code like ? || '%')
Statements submitted with parameter markers are equivalent to normal embedded statements using host variables, except that the statements are defined at run-time.
Upright Database Technology AB
Voice: +46 18 780 92 00
Fax: +46 18 780 92 40