Decode sql functions


Decode sql functions

Decode is the sql functions for the replacement of If- Then -else logic and case is similar to If-Then-else logic except that we can make logical comparison of columns involved in the case structures.

Ex: select case snum when snum > 10 then 'High' when snum>5 then 'Low' end from sales.

Ex: select decode(snum,10,'high',5,'low') from sales... that is we cannot make logical comparison of columns in Decode() functions.

Ex: SELECT NAME,SAL,DECODE(DEPTNO,10,'ACCOUNTING',20,'RESEARCH',30,'SALES',40,'OPERATIONS','OTHERS') "DEPARTMENTS" FROM EMP;

A DECODE FUNCTION ALWAYS TAKES MINIMUM OF 4 ARGUMENTS
DECODE
IF N1=N2
THEN RETURN N3
ELSE
RETURN N4


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: