3.4. Code Table Caching
3.4.1. Code Table Caching
lookup('ISOCountryCodes', 'CountryCode', 'CountryName', 'United States')
- The use of the lookup function automatically performs caching; there is no option to use the lookup function and not perform caching.
- No mechanism is provided to refresh code tables
- Only a single key/return column is cached - values will not be session/user specific.
SELECT (SELECT CountryCode From MatISOCountryCodes WHERE CountryName = tbl.CountryName) as cc FROM tbl
- More control of the possible return columns. Code tables will create a materialized view for each key/value pair. If there are multiple return columns it would be better to have a single materialized view.
- Proper materialized views have built-in system procedure/table support.
- More control via the cache hint.
- The ability to use OPTION NOCACHE.
- There is almost no performance difference.
3.4.2. Create a Materialized View for Code Table Caching
Procedure 3.4. Create a Materialized View for Code Table Caching
- Create a view selecting the appropriate columns from the desired table. In general, this view may have an arbitrarily complicated transformation query.
- Designate the appropriate column(s) as the primary key. Additional indexes can be added if needed.
- Set the materialized property to true.
- Add a cache hint to the transformation query. To mimic the behavior of the implicit internal materialized view created by the lookup function, use the Hints and Options /*+ cache(pref_mem) */ to indicate that the table data pages should prefer to remain in memory.
Just as with the lookup function, the materialized view table will be created on first use and reused subsequently.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.