0% found this document useful (0 votes)
27 views3 pages

Practical No 2 Dbms

The document contains examples of PL/SQL blocks using basic programming constructs. It includes two examples of sequential statements to perform arithmetic operations and generate a table. It also contains two examples of unconstrained loops: one to generate a table of multiples of 20 from 20 to 200, and another to output the numbers between 1000 and 1010. The examples demonstrate how to write PL/SQL code using variables, arithmetic operations, conditional statements, and loops to achieve basic programming tasks.

Uploaded by

movieverse775
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views3 pages

Practical No 2 Dbms

The document contains examples of PL/SQL blocks using basic programming constructs. It includes two examples of sequential statements to perform arithmetic operations and generate a table. It also contains two examples of unconstrained loops: one to generate a table of multiples of 20 from 20 to 200, and another to output the numbers between 1000 and 1010. The examples demonstrate how to write PL/SQL code using variables, arithmetic operations, conditional statements, and loops to achieve basic programming tasks.

Uploaded by

movieverse775
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Practical No 2

Aim:Writing PL/SQL block with basic programming constructs by including following.


a.Sequencial statements.
b.Unconstrained loop
a.Sequential Statement
a.1 Write a pl/sql block to perform arithemetic operation entered by the user.
● Program
SQL> declare
2 a number;
3 b number;
4 add number;sub number;mult number;div number;moddiv number;
5 begin
6 a:=&a;
7 b:=&b;
8 add:=a+b;
9 sub:=a-b;
10 mult:=a*b;
11 div:=a/b;
12 moddiv:=mod(a,2);
13 dbms_output.put_line('The addition is'||add);
14 dbms_output.put_line('The subtraction is'||sub);
15 dbms_output.put_line('The multiplication is'||mult);
16 dbms_output.put_line('The division is'||div);
17 dbms_output.put_line('The modulo division is'||moddiv);
18 end;
19 /
● Output
Enter value for a: 10
old 6: a:=&a;
new 6: a:=10;
Enter value for b: 10
old 7: b:=&b;
new 7: b:=10;
The addition is20
The subtraction is0
The multiplication is100

Sybsc(cs)
Roll No 48
The division is1
The modulo division is0

PL/SQL procedure successfully completed.

b.Unconstrained loop
b.1Write a pl/sql block to generate table of 20.
● Program
SQL> declare
2 a number:=20;
3 c number:=1;
4 res number;
5 begin
6 loop
7 res:=a*c;
8 dbms_output.put_line(res);
9 c:=c+1;
10 exit when c>10;
11 end loop;
12 end;
13 /
● Output
20
40
60
80
100
120
140
160
180
200

PL/SQL procedure successfully completed.

b.2 To show the number between 1000-1010.


● Program
Sybsc(cs)
Roll No 48
SQL> declare
2 num1 number:=1000;
3 num2 number:=1010;
4 begin
5 loop
6 dbms_output.put_line(num1);
7 num1:=num1+1;
8 exit when num1 > num2;
9 end loop;
10 end;
11 /

● Output
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010

PL/SQL procedure successfully completed.

Sybsc(cs)
Roll No 48

You might also like