Querying data sources directly with pass-through

Use pass-through sessions to perform operations that are not possible with the Db2® SQL/API.

About this task

About this task

Pass-through sessions are useful when:
  • Applications must create objects at the data source or perform INSERT, UPDATE, or DELETE operations.
  • The federated database does not support a unique data source operation.

Procedure

To query data sources directly with pass-through:

Procedure

  • Use the SET PASSTHRU statement to start a pass-through session and access a server directly. This statement can be issued dynamically. An example of this statement is:
    SET PASSTHRU ORACLE1
    This SET PASSTHRU statement opens a pass-through session to the data source using the server name ORACLE1. ORACLE1 is the name you registered for the data source server when you created the server definition.
  • When the pass-through session is opened, ensure that you use the true name of the object and not the nickname when you reference objects in a pass-through session. You must use the SQL dialect of the data source, unless the federated database is the data source that is being referenced.
  • If a static statement is submitted in a pass-through session, it is sent to the federated server for processing. If you want to submit an SQL statement to a data source for processing, you must prepare it dynamically in the pass-through session and have it executed while the session is still open. To prepare statements dynamically in a pass-through session:
    • To submit a SELECT statement, use the PREPARE statement with it, and then use the OPEN, FETCH, and CLOSE statements to access the results of your query.
    • For a supported statement other than SELECT, you have two options. You can use the PREPARE statement to prepare the supported statement, and then the EXECUTE statement to execute it. Alternatively, you can use the EXECUTE IMMEDIATE statement to prepare and execute the statement.

What to do next

If you issue the COMMIT or ROLLBACK command during a pass-through session, this command will complete the current unit of work, but does not end the pass-through session.