PL-SQL DIFFERENT PROGRAMS

725 views 21 slides Nov 23, 2016
Slide 1
Slide 1 of 21
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21

About This Presentation

Database Management System,PL-SQL DIFFERENT PROGRAMS. Simple basic programs that can give you idea about implement that in SQL.how to use if statement,different types of loops and etc in PL/SQL.


Slide Content

Database Management System Name:- Raj Upadhyay :- Dhruvan Bhalara

PL-SQL

PL / SQL  (procedural language extension to Structured Query Language) definition. In Oracle database management,  PL / SQL  is a procedural language extension to Structured Query Language ( SQL ). The purpose of  PL / SQL  is to combine database language and procedural programming language.

PL-SQL DIFFERENT PROGRAMERS

The 'Hello World' Example: 1) DECLARE message varchar2(20):= 'Hello, World!'; BEGIN dbms_output.put_line(message); END; /

2) BEGIN dbms_output.put_line( 'Hello, World!' ); END; /

1) Syntax: If statement. i f(condition)then s tatement e lse s tatement e nd if IF STATEMENT

2) IF THEN ELSIF Statement if condition_1 then statements_1 elsif condition_2 then statements_2 [ elsif condition_3 then statements_3 ]... [ else else statements ] End if;

declare i number(5); begin i:=&i; if(mod(i,2)=0)then dbms_output.put_line('I is Even'); else dbms_output.put_line('I is Odd'); end if; end; / Given number is Odd or Even :

Greater among 3 number set serveroutput on; declare i number(2); j number(2); k number(2); begin i:=&i; j:=&j; k:=&k; if( i >j and i >k)then dbms_output.put_line('I is Greater'); elsif(j> i and j>k)then dbms_output.put_line('J is Greater'); else dbms_output.put_line('K is Greater'); end if; end;

set serveroutput on; declare i number(5); j number(2); k number(2); begin i:=&i; j:=((i/30)); k:=(mod(i,30)); dbms_output.put_line(j||' Months '||k||' Days'); end; Convert Days into Months and Remaining days

Compare two number using function set serveroutput on; declare i number(2); j number(2); k number(2); max1 number(2); Function findmax (x in number, y in number, z in number) return number is w number; begin if(x>y and x>z)then w:=x; elsif(y>x and y>z)then w:=y; else w:=z; end if; return w; end; begin i:=&i; j:=&j; k:=&k; max1:= findmax ( i , j, k); dbms_output.put_line(max1); end;

DECLARE a number; b number; c number; FUNCTION findMax1(x IN number, y IN number) RETURN NUMBER IS W NUMBER; BEGIN IF (x > y) THEN dbms_output.put_line(x ); ELSIF(y>x)THEN dbms_output.put_line(y); ElSIF (y=x)THEN dbms_output.put_line('x=y'); ELSE dbms_output.put_line(' '); END IF; RETURN W; END; BEGIN a:= &a; b:= &b; c:=findMax1(a, b); END; / Compare two number using function

Print 1 to 10 Using Simple Loop set serveroutput on; declare a number(2); begin a:=1; loop dbms_output.put_line(a); a:=a+1; if(a>10) then exit; end if; end loop; end;

Print 1 to 10 Using FOR Loop set serveroutput on; declare a number(2); begin a:=1; for a in 1..10 loop dbms_output.put_line(a); end loop; end;

Print 1 to 10 Using While Loop set serveroutput on; declare a number(2); begin a:=1; while(a<11) loop dbms_output.put_line(a); a:=a+1; end loop; end;

Print 1 to 10 Using Nested FOR Loop set serveroutput on; declare a number(2); b number(2); begin a:=1; b:=1; <<outer>> for a in 1..10 loop dbms_output.put_line(a); <<inner1>> for b in 1..10 loop dbms_output.put_line(b); end loop inner1; end loop outer; end;

Sum of numbers from 1 to 50 (Using FOR Loop) set serveroutput on; declare a number(5); b number(5); begin a:=1; b:=0; for a in 1..50 loop b:=a+b; end loop; dbms_output.put_line(b); end;

Sum of numbers from 1 to 50 (Using Simple Loop) set serveroutput on; declare a number(5); b number(5); begin a:=0; b:=0; loop a:=a+1; b:=a+b; if(a>49) then exit; end if; end loop; dbms_output.put_line(b); end;

Sum of numbers from 1 to 50 (Using While Loop) set serveroutput on; declare a number(5); b number(5); begin a:=1; b:=a; while(a<50) loop a:=a+1; b:=a+b; end loop; dbms_output.put_line(b); end;

Thank You