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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -