The DETERMINISTIC Clause
DETERMINISTIC promises the same inputs always yield the same output, letting Oracle skip repeat calls.
How it works
Marking a function DETERMINISTIC tells the optimiser it may reuse a prior result for the same arguments within a single SQL statement, and it is required for a function used in a function-based index or a materialised view. The promise must actually hold — no dependence on table data that can change, session settings, SYSDATE, sequences or package state — or you get wrong results and stale indexes. Pure computational transforms (formatting, hashing, math) are the right candidates.
CREATE OR REPLACE FUNCTION full_name(p_first VARCHAR2, p_last VARCHAR2) RETURN VARCHAR2 DETERMINISTIC IS BEGIN RETURN TRIM(p_last || ', ' || p_first); END; / -- enables a function-based index: CREATE INDEX emp_full_name_ix ON employees (full_name(first_name, last_name));
Related questions
Model-generated, grounded against the curated knowledge layer. Check specifics against your instance.