Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Wednesday 6 August 2014

Conditional Statement in Oracle

Conditional Statements:-

Scenario:-

You want to perform a conditional operation to show that a student secures first class if he scores above 60% and secures second class if he scores above 45% but below 60 %, then you can use IF..THEN..ELSE clause.

 

What is conditional statement?

As the name implies, PL/SQL supports programming language features like conditional statements, iterative statements.

Conditional operator is:

IF THEN ELSE STATEMENT or IF THEN ELSIF ELSE.

Syntax for conditional statement is:-

·         CONDITION 1 (IF THEN ELSE)
 
IF CONDITION
       THEN
       STATEMENT 1; 
       ELSE
       STATEMENT 2;
        END IF;
 
NOTE:
When you are writing IF it means you have started a condition hence you must close it by using END IF.
 
 
 
·         CONDITION 2 (IF THEN ELSIF ELSE)
 
IF CONDITION 1 
THEN 
 STATEMENT 1; 
 STATEMENT 2; 
ELSIF CONDTION2 THEN 
 STATEMENT 3; 
ELSE 
 STATEMENT 4; 
END IF
 
Below is the example with conditional statement which shows the maximum number in the given set of numbers:-
 

 
 
 
 
Let’s see another example which will calculate your net salary:-
 

 

p> 

Once you click on save button, the connection will be saved in the connection tab so you can use it again and again. You can see below the name CONNECTION_TO_SCOTT is present in the connection tab.


If you want to add more connection then just click on  and put all the required information. After you saved it, it will be listed in connection tab.



Read Also:- 

No comments:

Post a Comment

Please provide your feedback in the comments section above. Please don't forget to follow.