PL/SQL :
1.Hellow world program
Begin
Dbms_output.put_line(‘Hellow world!!!!!!’);
End;
/
Output:
Hellow world!!!!!
set serveroutput on;
2.Display 2 variables
Declare
X number;
Y number;
Begin
X:=10;
Y:=20;
Dbms_output.put_line(x);
Dbms_output.put_line(y);
End;
/
Output:
10
20
OR
Declare
X number;
Y number;
Begin
X:=10;
Y:=20;
Dbms_output.put_line(‘x=’);
Dbms_output.put_line(x);
Dbms_output.put_line(‘y=’);
Dbms_output.put_line(y);
End;
/
Output:
X=
10
Y=
20
3. Addition of two number
Declare
X int;
Y int;
Z int;
Begin
X:=10;
Y:=20;
Z:=X+Y
Dbms_output.put_line(z);
End;
/
Output:
30
4.Arithm
declare
x int;
y int;
z int;
begin
x:=100;
y:=200;
dbms_output.put_line('addition');
dbms_output.put_line(x+y);
dbms_output.put_line('subtraction');
dbms_output.put_line(x-y);
dbms_output.put_line('multiplication');
dbms_output.put_line(x*y);
dbms_output.put_line('division');
dbms_output.put_line(x/y);
end;
/
Ouput:
addition
300
subtraction
-100
multiplication
20000
division
.5
PL/SQL
Prerequicisio:
Conn
System
Root
Se serveroutput on;
1.Hellow world program
--single line commet using double hyphen
Begin
Dbms_output.put_line(‘Hellow world!!!!!!’);
End;
/
Output:
Hellow world!!!!!
*note :-this may not show you direct output so typeà set serveroutput on;
2.Display 2 variables
Declare
X number;
Y number;
Begin
X:=10;
Y:=20;
Dbms_output.put_line(x);
Dbms_output.put_line(y);
End;
/
Output:
10
20
OR
Declare
X number;
Y number;
Begin
X:=10;
Y:=20;
Dbms_output.put_line(‘x=’);
Dbms_output.put_line(x);
Dbms_output.put_line(‘y=’);
Dbms_output.put_line(y);
End;
/
Output:
X=
10
Y=
20
3. Addition of two number
Declare
X int;
Y int;
Z int;
Begin
X:=10;
Y:=20;
Z:=X+Y
Dbms_output.put_line(z);
End;
/
Output:
30
4.Arithmetic operation
declare
x int;
y int;
z int;
begin
x:=100;
y:=200;
dbms_output.put_line('addition');
dbms_output.put_line(x+y);
dbms_output.put_line('subtraction');
dbms_output.put_line(x-y);
dbms_output.put_line('multiplication');
dbms_output.put_line(x*y);
dbms_output.put_line('division');
dbms_output.put_line(x/y);
end;
/
Ouput:
addition
300
subtraction
-100
multiplication
20000
division
.5
PL/SQL procedure successfully completed.
5. Program for
initializing variables in declaration section
Declare
A int:=10;
Begin
Dbms_output.put_line(‘value of a is=’||A);
End;
/
Output:
6.Table based recors:
declare
2 cust
customers%rowtype;
3
begin
4
select * into cust
5 from
customers where cust_id=1;
6
dbms_output.put_line('cust id='||cust.cust_id);
7
dbms_output.put_line('cust name='||cust.cust_nm);
8
dbms_output.put_line('cust address='||cust.cust_add);
9
dbms_output.put_line('cust slary='||cust.salary);
10 end;
11 /
Output:
cust id=1
cust name=vishakha
umale
cust address=akola
cust slary=50000
7.Cursor based record:
SQL> declare
2
cursor cur1 is
3
select cust_id,cust_nm,cust_add
4 from
customers;
5 cust
cur1%rowtype;
6
begin
7 open
cur1; --cursor is opened here
8 loop
9
fetch cur1 into cust;
10 exit
when cur1%notfound;
11
dbms_output.put_line(cust.cust_id||' '||cust.cust_nm||'
'||cust.cust_add);
12 end
loop;
13 end;
14 /
Comments
Post a Comment