When Oracle receives a SQL statement to execute, it first looks to see ifthe execution plan already exists in its cache. If the statement does existin the cache, the previous execution plan is retrieved and used. Thisreduces the cost of recreating the execution plan, thus saving executiontime. The cache can be viewed via the V$SQL table. Looking at the V$SQLtable’s SQL_TEXT column shows what statements are currently in cache.
One thing to note about how the cache works is that the SQL statements itplaces in the cache are case-sensitive. Therefore, the following twostatements perform the same query, but are seen as two different queries:
- SELECT * FROM V$SQL
- SELECT * FROM v$sql
They are considered different because the first query references theV$SQL table in all uppercase letters, whereas the second uses all lowercaseletters. To prove this, run the following query (note that two entriesare returned):
SELECT * FROM V$SQL WHERE SQL_TEXT =
'select * from V$SQL'
SQL_TEXT = 'select * from v$sql'
This can flood the cache with the same query, thus making the cache lessuseful. To prevent this, always ensure that applications that issue the samequery use the same letter case in the syntax.