oracle - reuse results from sql functions -


take @ beginning of query:

select    sum(decode(regexp_count(tpdd.domain, 'thedomain.com'), 1, tpdd.size, 0, 0))  sizeclient,    sum(decode(regexp_count(tpdd.domain, 'thedomain.com'), 1, 0, 0, tpdd.size))  sizethirdparty,    ... 

is there way reuse results of "regexp_count(tpdd.domain, 'thedomain.com')" function? should hope oracle server smart enough can't guarantee it, , besides, code better without repeated code.

you can use cte this:

 domain_regex  (     select tpdd.domain, regexp_count(tpdd.domain,'thedomain.com') regex_res     ...  )   select     sum(decode(d.regex_res, 1, tpdd.size, 0, 0))  sizeclient,     sum(decode(d.regex_res, 1, 0, 0, tpdd.size))  sizethirdparty,     ...  join domain_regex d on tpdd.domain = d.domain 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -