Skip to main content

Posts

Showing posts from August, 2014

NVL,NVL2,DECODE,COALESCE functions in Oracle

All the functions mentioned in the above title are mainly used in evaluation of data whether it is null or not. . Lets see in details how these functions work and what are the differences between them NVL Syntax:  NVL ( expr1 , expr2 ) If the expr1 is null then expr2 value is returned, if expr1 value is not null then expr1 value is returned. NVL2 Syntax: NVL2(expr1,expr2,expr3) if the expr1 is null then expr3 value is returned, if expr1 value is not null then expr2 value is returned. COALESCE Syntax: COALESCE(expr1,expr2,expr3...) it returns first non null expression value in the list. DECODE Decode is enhanced version of case statement let me explain you with a sample query select initcap(substr(pub_name,1,20)) publisher_name, decode(book_type,'computer',1,0) media from publisher  Here decode statement works like if the column book_type has computer value then it is returned as 1 else 0  Similar to case statement case when book_type...