Skip to main content
← PL/SQL Topics

SQL Integration

Explain the RETURNING INTO clause on DML

RETURNING INTO

ExplanationOracle Fusion / EBS · Technical · PL/SQLHigh confidenceGenerated

RETURNING INTO gives back column values from the rows an INSERT, UPDATE or DELETE just affected — no extra SELECT.

How it works

Append RETURNING col_list INTO var_list to a single-row DML to capture generated or changed values (an identity/sequence key after INSERT, the pre-image is not available — you get the post-DML values; for DELETE you get the deleted row's values). For multi-row DML use RETURNING ... BULK COLLECT INTO collections. It saves a round trip and avoids a race between the DML and a follow-up query.

How it works
DECLARE
  v_new_id departments.department_id%TYPE;
BEGIN
  INSERT INTO departments (department_name, location_id)
  VALUES ('Analytics', 1700)
  RETURNING department_id INTO v_new_id;

  DBMS_OUTPUT.PUT_LINE('created department ' || v_new_id);
END;
/

Related questions

GroundingGenerated

Model-generated, grounded against the curated knowledge layer. Check specifics against your instance.

Have a follow-up, or a different question?

Continue in Ask Oracle AI