Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, AB.

Asked: December 18, 2018 - 1:49 pm UTC

Last updated: December 20, 2018 - 7:41 am UTC

Version: Oracle 11g

Viewed 1000+ times

You Asked

Hi all, I have seen many number of times a SQL function nested one another to greater depth

Concat(substring(instring,concat()))... this is just an example

My question is exactly this nesting work and how it is evaluated to ,which function going to evaluated first.

Could you please explain with an example.Thanks

and Connor said...

Functions are evaluated as needed. Typically this would from "inside to out" so in your example it would be the innermost 'instring' and 'concat' first, then we use the output from them for 'substr' and then the output of that for the outer concat.

But we also try to be smart. For example, a function like:

case when substr(x,1,1) = 'A' then lower(y) else upper(y) end

we would execute "substr" first, and if the result came to 'A', then we would execute "lower(y)" and we would *not* execute the "upper" function because it is not needed.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Nice explanation

Samy, December 19, 2018 - 3:42 am UTC

The questions was clearly and nicely explained. I am much obliged.
Connor McDonald
December 20, 2018 - 7:41 am UTC

glad we could help