Stop Oracle from caching select query - Running query from Perl
Not sure if this is a Perl or Oracle issue. I'm new to both.
I have 1 row in a table. Its value is a number. This number is updated very often.
开发者_如何学GoWhen I run a select query from Perl to get this value... it is not always the latest value. It is usually an old value. I'll run the same query through SQLPLUS and I'll see the correct value... Perl only shows the correct value if I delete the data in the table and insert it again.
So, I'm wondering - is this query somehow being cached?
This is how I'm running the query in Perl:
my $sql_latest_jobID = "SELECT /*+ NOCACHE */ job_number FROM example_table WHERE ID = 1";
my $sth = $dbh->prepare($sql_latest_jobID)
or die "Couldn't prepare statement: " . $dbh->errstr;
$sth->execute();
my @data = $sth->fetchrow_array();
$jobID = $data[0];
I also tried the Query without NOCACHE. Had the same result.
I don't know Perl, but it seems you are not committing the data and thus Perl does not see the updated value.
Another possibility could be that Perl changes the isolation level to repeatable read. If that was the case, you will need to end the current transaction in Perl (even a SELECT is a transaction!) by issuing a commit or rollback (from within Perl) in order to see the updated value.
Oracle does not cache results in this way. You allways will see what is in the table(what is commited).
So, or Before oracle(in perl) you use some cache. or you make an banal error, for example query-ing another table :)
精彩评论