You are here:

Oracle/ABOUT DECODE AND SIGN in a single query.

Advertisement


Question
Please explain me what does this query do exactly:

SUM( DECODE(SIGN(ic.f_i_soh_rglr_qty
                       +ic.f_i_soh_clrc_qty
                       +ic.f_i_soh_prmtn_qty),-1,1,0,1,1,0))   Oos_count


Answer
Good day Raghav

SIGN function returns three values.  They are -1, 0, and 1.  

If number < 0, then sign returns -1.
If number = 0, then sign returns 0.
If number > 0, then sign returns 1.

Therefore, if ic.f_i_soh_rglr_qty+ic.f_i_soh_clrc_qty+ic.f_i_soh_prmtn_qty is a negative number,then it will set to 1.  If it is a zero, then it will set to 1, and if it is a positive number, it will set to 0.  

Then it will sum up the results and return a value.  

Hope it helps.  If you have additional question, please let me know

Cheers
Elliot

Oracle

All Answers


Answers by Expert:


Ask Experts

Volunteer


Elliot Mak

Expertise

I can answer questions with regarding to Oracle DB (8i, 9i, 10g, 11g) installation, configuration, administration, Data Guard, SQL, and PL/SQL (Procedures, triggers, functions).

Experience

I am an Oracle DBA, Senior PA, Project Manager, and Data Architect with 10 years of experience.

Education/Credentials
Bachelor of Science in Management System

©2012 About.com, a part of The New York Times Company. All rights reserved.