Capturing values from rows affected by an INSERT, UPDATE, or DELETE into a variable or result set within the same statement.
SQL Server and Sybase equivalent of RETURNING, capturing values from modified rows. Useful for getting identity values, computed columns, or deleted row data immediately after an INSERT/UPDATE/DELETE operation.
| Database System | Support Status | Since Version | Notes |
|---|---|---|---|
| MySQL | ✓ Supported | 5.0 | No OUTPUT/RETURNING clause. Use LAST_INSERT_ID() after INSERT to retrieve the auto-increment key. Multi-row capture requires triggers or application logic. |
| PostgreSQL | ✓ Supported | 8.2 | RETURNING clause on INSERT, UPDATE, and DELETE returns a full result set. Works in plain SQL and inside PL/pgSQL with SELECT INTO or FOR loop. |
| SQL Server | ✓ Supported | 2005 | OUTPUT clause on INSERT, UPDATE, DELETE, and MERGE. Can write to a table variable (OUTPUT INTO @tbl) or return rows to the client. Exposes inserted and deleted virtual tables. |
| Oracle | ✓ Supported | 8i | RETURNING...INTO in PL/SQL captures scalar or collection values from INSERT/UPDATE/DELETE. For bulk operations use RETURNING BULK COLLECT INTO. |
| SQLite | ✓ Supported | 3.35.0 | RETURNING clause on INSERT, UPDATE, and DELETE added in 3.35.0 (2021). Returns a result set; no direct INTO variable support in SQL. |
Capturing DML output inline is invaluable for audit logging, chained operations, and avoiding a second SELECT round-trip. PostgreSQL and SQLite share the RETURNING syntax and semantics. SQL Server's OUTPUT clause is the most powerful: it can route output to a table variable via OUTPUT INTO, enabling buffered multi-step operations, and it exposes both the pre-change (deleted) and post-change (inserted) images in a single UPDATE statement. Oracle's RETURNING INTO is PL/SQL only — it doesn't work in plain SQL scripts. MySQL has no equivalent clause at all; LAST_INSERT_ID() covers only the auto-increment key case, not arbitrary column values or UPDATE/DELETE captures. SQLite's RETURNING is recent (2021); target SQLite version carefully if deploying to embedded contexts.
No OUTPUT/RETURNING clause. Use LAST_INSERT_ID() after INSERT to retrieve the auto-increment key. Multi-row capture requires triggers or application logic.
RETURNING clause on INSERT, UPDATE, and DELETE returns a full result set. Works in plain SQL and inside PL/pgSQL with SELECT INTO or FOR loop.
OUTPUT clause on INSERT, UPDATE, DELETE, and MERGE. Can write to a table variable (OUTPUT INTO @tbl) or return rows to the client. Exposes inserted and deleted virtual tables.
RETURNING...INTO in PL/SQL captures scalar or collection values from INSERT/UPDATE/DELETE. For bulk operations use RETURNING BULK COLLECT INTO.
RETURNING clause on INSERT, UPDATE, and DELETE added in 3.35.0 (2021). Returns a result set; no direct INTO variable support in SQL.