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

javascript - ScrollTo Effect (href to div) -

javascript - ng-class not responding to change in model in Angular? -

javascript - document.registerElement extending HTMLInputElement prototype while using custom tag name to avoid implicit browser style -