I am working on an old SQL written for Oracle. There is a part of the select clause that I do not understand, even after googling and checking the questions related to the + sign with the key words Oracle and SQL.
I have checked the answer for a similar question for the where clause here and I found an Oracle docs for the join as well, but it does not make sense for the select clause.
Given an SQL below what is the purpose of the plus sign.
select '01,'|| lpad( (select nvl(count(*), 0) from table1) + (select nvl(count(*), 0) from table2) + (select nvl(count(*), 0) from table3) ,9,'0') from DUAL
The sample output
01,000011111
From a sample sql output, it seems that it is for concatenating a result, but I want to be sure.
Advertisement
Answer
The +
is not for string concatenation. It is for addition. Plus, count()
does not return NULL
values so nvl()
is not needed.
This should be equivalent:
select ('01,' || lpad( ((select count(*) from table1) + (select count(*) from table2) + (select count(*) from table3) ), 9, '0' ) ) from DUAL