dbms_sql
Implements a subset of Oracle’s DBMS_SQL package API to ease application migration to PostgreSQL.
dbms_sql · Implements a subset of Oracle’s DBMS_SQL package API to ease application migration to PostgreSQL.
Overview
PostgreSQL · 11, 12, 13, 14, 15, 16, 17, 18
Usage
Sources:
dbms_sql implements a PostgreSQL-oriented subset of Oracle’s DBMS_SQL cursor API. It helps migrate PL/SQL that parses dynamic statements, binds scalar or array values, executes them, describes result columns, and fetches rows; it does not promise full Oracle compatibility.
Core Workflow
Open a cursor, parse a statement with named binds, bind values, execute, and close the cursor:
For query results, call define_column or define_array, execute, loop over fetch_rows, retrieve values with column_value, and always close the cursor in normal and exception paths.
Main Interface
open_cursor,is_open, andclose_cursormanage extension cursor handles.parseprepares dynamic SQL;bind_variableandbind_arraysupply named parameters.execute,execute_and_fetch,fetch_rows, andlast_row_countdrive execution and fetching.define_column,define_array, andcolumn_valuedescribe destination buffers and copy fetched values.describe_columnsanddescribe_columns_freturndbms_sql.desc_recmetadata. Thecol_typenumbers are PostgreSQL type OIDs, not Oracle type codes.
Migration Boundaries
- Audit every migrated call against the implemented signatures and PostgreSQL transaction/error semantics. Unsupported Oracle overloads, type conversions, privilege behavior, and cursor lifetime must be rewritten explicitly.
- The install SQL creates an unqualified
varchar2domain as a temporary compatibility object. Upstream instructs users who combine this extension with Orafce to remove that statement from the install script, because Orafce supplies its ownvarchar2. - Cursor handles are backend-local execution state. They do not cross sessions, pool checkouts, failover, or transaction-retry boundaries; close them deterministically to avoid leaking state in long-lived sessions.
- Dynamic SQL still requires normal injection discipline. Bind data values, validate any identifiers or SQL fragments that cannot be bound, and run with the least-privileged caller.
- The repository is archived. Pin the reviewed commit and test its direct use of PostgreSQL internals against the exact server major version before migration or upgrade.