Skip to main content
← PL/SQL Topics

Advanced & Performance

Explain the PL/SQL function RESULT_CACHE

The PL/SQL Function Result Cache

ExplanationOracle Fusion / EBS · Technical · PL/SQLHigh confidenceGenerated

RESULT_CACHE stores a function's return value per argument set in the SGA and reuses it until a dependent table changes.

How it works

Add RESULT_CACHE to a function's declaration and Oracle caches (arguments -> result) in a shared area across sessions. A later call with the same arguments returns instantly without running the body. The cache is automatically invalidated when any table the function queries is modified. It fits small, frequently-called, read-mostly lookups (reference data, configuration). Avoid it for functions with session-dependent results, side effects, or that depend on SYSDATE / NLS settings. Monitor with V$RESULT_CACHE_STATISTICS.

How it works
CREATE OR REPLACE FUNCTION dept_name(p_id NUMBER)
  RETURN VARCHAR2
  RESULT_CACHE
IS
  v_name departments.department_name%TYPE;
BEGIN
  SELECT department_name INTO v_name
    FROM departments WHERE department_id = p_id;
  RETURN v_name;
EXCEPTION
  WHEN NO_DATA_FOUND THEN RETURN NULL;
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