09.10.2014 Views

download pl/sql tutorial (pdf - Tutorials Point

download pl/sql tutorial (pdf - Tutorials Point

download pl/sql tutorial (pdf - Tutorials Point

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Exam<strong>pl</strong>e:<br />

Let us try a com<strong>pl</strong>ete exam<strong>pl</strong>e that would illustrate the concept:<br />

DECLARE<br />

a number(3) := 100;<br />

BEGIN<br />

-- check the boolean condition using if statement<br />

IF( a < 20 ) THEN<br />

-- if condition is true then print the following<br />

dbms_output.put_line('a is less than 20 ' );<br />

ELSE<br />

dbms_output.put_line('a is not less than 20 ' );<br />

END IF;<br />

dbms_output.put_line('value of a is : ' || a);<br />

END;<br />

/<br />

When the above code is executed at SQL prompt, it produces the following result:<br />

a is not less than 20<br />

value of a is : 100<br />

PL/SQL procedure successfully com<strong>pl</strong>eted.<br />

IF-THEN-ELSIF statement<br />

The IF-THEN-ELSIF statement allows you to choose between several alternatives. An IF-<br />

THEN statement can be followed by an optional ELSIF...ELSE statement. The ELSIF clause lets<br />

you add additional conditions.<br />

When using IF-THEN-ELSIF statements, there are few points to keep in mind.<br />

<br />

It's ELSIF, not ELSEIF<br />

TUTORIALSPOINT<br />

Sim<strong>pl</strong>y Easy Learning Page 39

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!