Single-Value JSON Function-Based Index
Use a single-value JSON index when a target path returns at most one scalar value per document.
This index is ideal for stable, well-known query patterns.
Syntax
CREATE JSON SINGLEVALUE INDEX index_name ON table_name [table_alias]
(dot_path [ASC | DESC], [dot_path [ASC | DESC]] ...);
Create a Single-Value JSON Index on Traveler Email
CREATE JSON SINGLEVALUE INDEX email_idx ON bookings b
(b.data.traveler.email.string());
A single-value JSON index targets one scalar value, $.traveler.email, per document. The string() item method fixes the return type to a SQL string, which makes comparisons type-consistent.
Use json_value Syntax
You can create the same index using json_value syntax:
CREATE INDEX email_idx ON bookings b
(json_value(data, '$.traveler.email.string()'
ERROR ON ERROR NULL ON EMPTY));
Note: Oracle recommends using ERROR ON ERROR for single-value JSON indexes. Avoid NULL ON ERROR for indexes. If a field can be missing, use NULL ON EMPTY together with ERROR ON ERROR so the index can be created and maintained while still enforcing a single scalar value when the field is present.
For an index to be used, the query must use the same return type and the same ON ERROR and ON EMPTY handling as the index definition.