Monday, May 31, 2010

A use of "case when" and useful convert SQLs

My first use of "case when" sql command. I needed to write an alert and the alert needed to be tested. Also test mail server was not working. So i replaced original e-mail addresses with our email addresses via "case when".
Example:
select email_address
case
when email_address = 'aaa' then 'bbb'
else 'ccc'
end

ABS returns absolute value of a number like
select ABS(-1) from dual : "1"

To extract day, month or year from sysdate we can use following:
select extract(day from sysdate) from dual
To select day, month or year from sysdate plus or minus some months we can use following:
select extract(year from add_months (sysdate,24)) from dual

To restrict the SQL with an aggregated condition "where" clause can not be used, "having" can be!
select po_header_id
from po.po_lines_all
where creation_date > sysdate -30
and sum(unit_price) > 1000
group by po_header_id
Generates "ORA-00934: group function is not allowed here" error.

Though following query works:
select po_header_id
from po.po_lines_all
where creation_date > sysdate -30
having sum(unit_price) > 1000
group by po_header_id

What, Why?

Being an Oracle functional consultant requires deep understanding of system analysis, knowledge of technical fundamentals beside Oracle E-Business Suite. This blog mostly consists of tips, information which a functional consultant needs time to time.

With the things we learn we become more overlooking to the job though some of it is forgotten in time. After more than a year in this job i feel a need to materialize my knowledge. So writing the things which attracts my attention will help me to keep track of my learnings. I believe information here will help me in my future projects and being able to see my learning process may inspire me and readers of this blog...