SQL Tutorial : DRL / DQL - IF THEN ELSE LOGIC
Let's learn about next topic: IF THEN ELSE LOGIC
IF THEN ELSE LOGIC:
********************
CASE:
- SELECT LAST_NAME,JOB_ID,
CASE JOB_ID WHEN 'SA_REP' THEN 'SALES REPS'
WHEN 'SA_MAN' THEN 'SALES MANAGERS'
ELSE 'SOME OTHER DESIGNATIONS' END
FROM EMPLOYEES
DECODE
- SELECT LAST_NAME,JOB_ID,
DECODE( JOB_ID ,'SA_REP' ,'SALES REPS',
'SA_MAN' ,'SALES MANAGERS',
'SOME OTHER DESIGNATIONS' ) "EMP DETAILS"
FROM EMPLOYEES
Point to Note:
CASE:
- ANSI SQL
- STATEMENT
- CANNOT USE NULL COMPARISONS
- CAN USE RELATIONAL OPERATORS
- CAN BE USED AS A PART OF PLSQL EXPRESSIONS
DECODE :
- FUNCTION
- CAN USE NULL COMPARISONS
- CANNOT USE RELATIONAL OPERATORS
+
- CANNOT BE USED AS A PART OF PLSQL EXPRESSIONS
- MULTIPLE I/P THEN MULTIPLE ROW FUNCTIONS OR
AGGREGATE FUNCTIONS
No comments:
Post a Comment