1

Does oracle optimize select statement within a select?

for example simple query

SELECT
 test.a as a,
 test.b as b,
 (SELECT id from inner_table WHERE inner_table.code = 'active')
FROM test

lets say table test has 1000 records, what would Oracle do?

Execute select each time, for each record? Cached it?

Or there is a way to use it ones ?

1 Answer 1

3

Yes, Oracle will cache scalar sub-queries. Tom Kyte has a good piece on the subject.

In your case, I would expect that the subquery will be exececuted once and the cached value used for subsequent rows.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, good article. Is there any way to verify that oracle cached it?
Maybe this asktom post will help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.