I am developing a C++ program using OCI to query some result set from a Oracle database. I found that the result set is cached even I’ve manually update rows with ‘update table set col=xxx where xxx‘. The OCI calls are still getting old data. How does this caching happen? Is there a way to disable it? How can I check if the caching really happens? By checking execution plan?
I am developing a C++ program using OCI to query some result set from
Share
When you make changes in a separate session (your SQL*Plus session), those changes only become visible to your current session (your OCI application) when you
committhe changes. Until youcommitthe transaction in SQL*Plus, you will continue to see the current version of the row, not the version that you changed in your SQL*Plus session. Your OCI application is using the default transaction isolation ofREAD COMMITTEDso you can only read committed data.One thing to be aware of is that if you open a cursor from your OCI application, the data that is fetched from the cursor handle is the data as it existed at the point in time that the cursor was opened. So if you open a cursor in OCI, commit changes in SQL*Plus, and then fetch the data from OCI, your OCI application will not see the changes that were committed in SQL*Plus. You would have to re-open the cursor in order to see the newly committed rows.
Technically, this is not caching. Instead, this is how Oracle’s multi-version read consistency works. Assuming the default transaction isolation level, each time a cursor is opened, the current SCN (system change number) is captured and the data that is retrieved is as of that SCN. If a block has changed (whether committed or not) since that SCN, Oracle applies the UNDO vector for that change to the block before returning it to your session.