Professional Documents
Culture Documents
Declare
Var number(10);
Begin
DBMS_OUTPUT.PUTLINE(Var);
END;
2 Bind variables: This is also like normal variables but it can be declare in anywhere in the host
environment means we can declare the variable outside the declare block.
CONSTANT
Constant: Constant are also place holders like variables except once the value is assigned can’t
be changed during the program execution time.
Conditional Statements
In oracle sql we have three types of Conditional Statements. They are
1 IF-THEN
2 IF-THEN-ELSE
3 IF-THEN-ELSIF-ELSE
1 IF-THEN:
DECLARE
X NUMBER(10);
BEGIN
X:=:X;
IF X<10 THEN
DBMS_OUTPUT.PUT_LINE(' X < 10 ');
END IF;
END;
2 IF-THEN-ELSE:
DECLARE
X NUMBER(10);
BEGIN
X:=:X;
IF X MOD 2 = 0 THEN
DBMS_OUTPUT.PUT_LINE(X||' is prime');
ELSE
DBMS_OUTPUT.PUT_LINE(X||' is not prime');
END IF;
END;
3 IF-THEN-ELSIF-ELSE:
DECLARE
X NUMBER(4);
BEGIN
X:=:X;
IF X>80 THEN
DBMS_OUTPUT.PUT_LINE('O');
ELSIF X<=80 AND X>60 THEN
DBMS_OUTPUT.PUT_LINE('E');
ELSIF X<=60 AND X>40 THEN
DBMS_OUTPUT.PUT_LINE('A');
ELSE
DBMS_OUTPUT.PUT_LINE('F');
END IF;
END;
Iterative Statements
In oracle sql we have three types of loops. They are
1 For Loop
2 While Loop
3 Simple Loop
1 For Loop: In oracle sql we use for loop like this
DECLARE
X NUMBER(10);
BEGIN
X:=:X;
END;
In oracle if we want to use for loop in descending order then we have to use REVERSE key
word like this.
DECLARE
X NUMBER(10):=10;
BEGIN
FOR I IN REVERSE 0..X LOOP
DBMS_OUTPUT.PUT_LINE(I);
END LOOP;
END;
DECLARE
X NUMBER(10);
I NUMBER(10);
BEGIN
X:=:X;
I := 0;
DECLARE
X NUMBER(10):=10;
I NUMBER(10):=0;
BEGIN
LOOP
DBMS_OUTPUT.PUT_LINE(I);
I:=I+1;
IF I>10 THEN
EXIT;
END IF;
END LOOP;
END;
Triggers
In oracle pl/sql we have a concept called Triggers. Actually triggers are nothing but a block of
named block which execute when any event occur like DDL,DML etc…