oracle - With clause execution -
i've thought with
clause working one-time execute statement, behaves normal table - can sql operations on over regular table.
but turned out in several databases(oracle, netezza, sybase, teradata) with
clause executed each time used.
test as( select random() --pseudo code ) select '1st select', * test union select '2nd select', * form test
instead of 2 identical numbers, query above returns 2 different numbers, executed each of selects.
if have complex query within with
clause , use 5 times in rest of query, execute 5 times seems ineffective me.
so can give me logical reason working way?
at least in teradata
it's working expected, random value calculated once:
with test as( select random(1,1000000) x --pseudo code ) select '1st select', x test union select '2nd select', x test ; *** query completed. 2 rows found. 2 columns returned. *** total elapsed time 1 second. '1st select' x ------------ ----------- 1st select 422654 2nd select 422654
Comments
Post a Comment