DECODE Function:
Ø Decode functions decodes the expression in a similar way of using IF-THEN-ELSE conditional expression.
Syntax:
Explanation:
Ø Decode
function decodes the expression by search value.
Ø If
the expression is same as the search then, result is returned.
Ø If
the expression is does not same to the search then, Default value is returned.
Ø If default is omitted, a null value is returned where a search value does not match any of the result values.
Example:
Output:
ENAME |
SAL |
INCREMENT |
Tae |
10000 |
15000 |
Malavika |
5000 |
5000 |
Jk |
30000 |
45000 |
COALESCE() Function:
Ø COALESCE()
function returns the first non-null expression in the expression list.
Ø User must specify at least two expressions in the expression
list.
Ø If all occurrences of expression evaluate to null, then the
function returns null.
Syntax:
Is equivalent to:
Example:1
Output:
|
A |
Example:2
Output:
|
B |
Example:3
Output:
|
Null |
For
Our clear clarification:
Table:
Books
Book_Name |
Pages |
Price |
Discount |
SQL |
500 |
500 |
200 |
PL/SQL |
600 |
|
300 |
DBMS |
800 |
1000 |
|
Output:
|
|
CASE function:
Ø Evaluates
a list of conditions and returns results (like
IF-THEN-ELSE).
Ø If
the condition gets true Case stop the evaluation and shows the result.
Ø If
all the condition gets false it executes the Else statement. There is no Else
then return null.
Syntax:
Table:
Customers
Customer_id |
Customer_Name |
Gender |
20000 |
Steven |
M |
20001 |
Markov |
M |
20002 |
Lisa |
F |
20003 |
Riya |
F |
20004 |
Vena |
F |
Example:
Output:
Customer_name |
Gender |
Steven |
Male |
Markov |
Male |
Lisa |
Female |
Riya |
Female |
Vena |
Female |
No comments:
Post a Comment