Skip to main content
← PL/SQL Topics

Advanced & Performance

Explain the NOCOPY parameter hint

The NOCOPY Parameter Hint

ExplanationOracle Fusion / EBS · Technical · PL/SQLHigh confidenceGenerated

NOCOPY asks the compiler to pass an OUT / IN OUT parameter by reference instead of copying it in and out.

How it works

By default OUT and IN OUT parameters are passed by value: the actual argument is copied into the formal on entry and back on exit. For a large collection or record that copy is expensive. NOCOPY requests pass-by-reference, avoiding both copies. Caveats: it is only a hint (ignored in some cases), and on an exception the actual may be left partially modified because there is no 'copy back only on success'. Use it for big IN OUT collections in hot paths, and keep such routines exception-safe.

How it works
DECLARE
  TYPE big_tab IS TABLE OF VARCHAR2(4000);
  l_data big_tab := big_tab();

  PROCEDURE transform(p IN OUT NOCOPY big_tab) IS
  BEGIN
    FOR i IN 1 .. p.COUNT LOOP
      p(i) := UPPER(p(i));
    END LOOP;
  END;
BEGIN
  l_data.EXTEND(100000);
  FOR i IN 1 .. l_data.COUNT LOOP l_data(i) := 'row ' || i; END LOOP;
  transform(l_data);                    -- no 100k-element copy each way
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