Professional Documents
Culture Documents
2017-18
Certificate
Index
Create table Employee containing rows EmpNo, EName, Job, Mgr,Hire Date,
Sal, Comm, DeptNo and insert atleast 10 records.
Create table Department containing rows DeptNo, DName, Location and
insert atleast 5 records.
Create table Programmer containing rows Name,Dob,Gender,Prof1,Prof2,
Salary and insert atleast 10 records.
Create table Software containing rows Name,Title,Dev_In,Scost,Dcost,Sold and
insert atleast 10 records.
Create table Studies containing rows Name,Splace,Course,Cost and insert
atleast 10 records.
Solution 1:
Employee Table
Code:-
Create Table syemp
(
empno number(4) NOT NULL ,
ename varchar2(10),
job varchar2(9),
mgr number(4),
hiredate date,
sal number(7,2),
comm number(7,2),
deptno number(2)
)
Output:
10 rows selected.
Solution 2:
Department Table
Code:-
Create Table sydept
(
deptno number(2) NOT NULL,
dname varchar2(14),
loc varchar2(13)
)
Output:-
Solution 3:
Programmer Table
Code:-
Create Table syprogrammer
(
name varchar2(8) primary key NOT NULL ,
dob date NOT NULL ,
doj date NOT NULL ,
sex varchar2(1) NOT NULL ,
prof1 varchar2(8),
prof2 varchar2(8),
salary number(4) NOT NULL
)
Output:-
Studies Table
Code:-
Solution 5:
Software Table
Code:-
Create Table sysoftware
(
name varchar2(8) Not Null,
title varchar2(20) Not Null,
dev_in varchar2(8) Not Null,
scost number(7,2),
dcost number(5),
sold number(3)
)
Output:-
Practical No: 02
Solution
Ans1:
declare
a number;
b number;
c number;
begin
a:=&a;
b:=&b;
c:=a+b;
end;
Output:
Ans3:
declare
l number;
b number;
area number;
begin
l:=&l;
b:=&b;
area:=0.5*l*b;
end;
output:
Ans4:
declare
r number:=5;
area number(5,2);
peri number(5,2);
begin
area:=3.14*r*r;
peri:=2*3.14*r;
end;
output:
declare
n number := 1;
begin
while n<=30
loop
dbms_output.put_line(n);
n := n+2;
end loop;
end;
/
Practical No:03
Aim: Write Pl/SQl block which displays the use of conditional construct and
the use of GOTO statements
Enter a number from Key board. If it is not zero print 'natural number',
else print 'enter wrong number.
Calculate the net salary where DA is 30% of basic, HRA is 10% of basic
and PF IS 7% of basic salary if salary is less than 8000 ,PF is 10% if
basic sal between 8000 to 160000.
Find the greatest among three numbers.
Print the numbers from 1-20 using GOTO statements
Solution
Ans1:
Code:-
DECLARE
num number;
BEGIN
dbms_output.put_line(‘Enter number’);
num:=#
If(num>0) THEN
dbms_output.put_line(num || ' Natural Number ');
ELSE
dbms_output.put_line(num|| ' Not A Natural Number ');
END If;
END;
OUTPUT:-
Ans2:
Code:-
DECLARE
ename varchar2(15);
basic number;
da number;
hra number;
pf number;
netsalary number;
BEGIN
ename:='GAURAV';
basic:=9000;
da:=basic*(30/100);
hra:=basic*(10/100);
if(basic<8000)
then
pf:=basic*(8/100);
elsif(basic>=8000 and basic <= 16000)
then
pf:=basic*(10/100);
end if;
netsalary:=basic+da+hra-pf;
Ans: 3
Code:-
DECLARE
a number;
b number;
c number;
BEGIN
a:=3;
dbms_output.put_line('Enter a: ' || a);
b:=6;
dbms_output.put_line('Enter b: ' || b);
c:=9;
dbms_output.put_line('Enter c: ' || c);
if(a>b and a>c)
then
dbms_output.put_line(a || ' is a greater number ');
elsif(b>a and b>c)
then
dbms_output.put_line(b || ' is a greater number ');
else
dbms_output.put_line(c || ' is a greater number ');
end if;
END;
OUTPUT:-
9 is a greater number
Ans 4
SQL> DECLARE
2 counter NUMBER := 1;
3 BEGIN
4 WHILE (counter < 5) LOOP
5 IF counter = 2 THEN
6 GOTO cp;
7 ELSE
8 dbms_output.put_line(‘counter’ ['||counter||'].');
9 END IF;
10.<<cp>>
11 IF counter >= 1 THEN
12 counter := counter + 1;
13 END IF;
14 END LOOP;
15 END;
Practical No:04
Ans1:
Ans3:
Ans4:
Practical No.05
Solution
Ans1:
Ans2:
Ans3:
Ans4:
Practical No.:-06 Stored Procedure
Create table dept and then create a procedure to add a new record
into the dept table. The appropriate columns belonging to the table
are:
dno number
name varchar2
location varchar2
Write a proc that returns the salary of the employee given his name as
IN parameter.
Create three procedures and call them one by one to determine and
conclude about the scope of each procedure
Write a proc that returns the salary of the employee given his name as IN
parameter.
Swap two numbers
Accept 3 different numbers from the user and create a function to display them in
descending order.
Table created.
5 rows selected.
2 is
3 a number;
4 begin
6 return a;
7* end count469;
SQL> /
Function created.
1 begin
2 :x:=count469;
3* end;
b. BK_NAME VARCHAR2(10)
c. AUTHOR VARCHAR2(20)
d. PUBLSHR VARCHAR2(20)
e. EDITION VARCHAR2(20)
Table created.
2 is
3 a number;
4 begin
6 return a;
7* end count483;
SQL> /
Function created.
SQL> begin
2 :y:=count483;
3 end;
4 /
----------
Create a function which will compute the square and cube of a number.
Write a pl/SQL block which acts as a recursive function which
computes factorial of a number.
1 create or replace function fact(n in number) return number
2 is
3 begin
4 if n=1 then
5 return 1;
6 else
7 return n*fact (n-1);
8 end if;
9 end fact;
10 /
Function created.
SQL> variable a number;
SQL> begin
2 :a:=fact(4);
3 end;
4/
SQL> print :a
A
----------
24
Practical No.:-08 Transaction Locks And Sequence
Questions:-
1. Create a table ticket with following fields ticket id, name, source and destination
address. Insert atleast 5 records in it. Create a savepoint and now insert single
record in it. See all the records and now rollback to savepoint.
2. Create two tables EMP and Customer. EMP table should have the following fields
–EMP id, name, salary and bonus whereas Customer table must have cid, name,
and purchase as fields. Insert atleast 5 records in each table and perform the
following transaction.
i. Update EMP by increasing the salary of all employees by 5000.
ii. Increase the bonus of specified employee by 1000.
iii. Commit the EMP transaction.
iv. Update Customer table by increasing the purchase by 1000 for specified
customer.
v. Rollback the Customer Transaction.
3. Create a sequence with default values. Insert atleast 2 records in the Customer
table by using sequence.
4. Alter the sequence increment by 2 and cache as 2. Insert record in Customer table
and see the result.
5. Alter the maximum value of sequence to 10, cache 2 and cycle option to start
again from the starting value. Insert record in Customer table to see the changes.
6. Create sequence with maximum value 4 and no cycle option. Insert 5 records in
EMP table to see working of sequence.
Solution:-
DECLARE
BEGIN
SAVEPOINT S1;
END;
Output:-
ROLLBACK COMPLETED
Output:-
);
);
1 NIDHI 5
2 SADHANA 10
3 TEJASHREE 15
4 RUTUJA 20
5 GAURI 25
SAVEPOINT S2;
Output:-
Output:-
iii. COMMIT;
Output:-
COMMIT COMPLETED;
iv.
begin
WHERE C_ID=101;
End;
Output:-
Output:-
ROLLBACK COMPLETED.
1 NIDHI 5
2 SADHANA 10
3 TEJASHREE 15
4 RUTUJA 20
5 GAURI 25
SEQUENCE CREATED.
Output:-
1 NIDHI 5
2 SADHANA 10
3 TEJASHREE 15
4 RUTUJA 20
5 GAURI 25
6 PRIYANKA 15000
7 TRUPTI 20000
4. ALTER SEQUENCE S2
INCREMENT BY 2
CACHE 2;
SEQUENCE ALTERED.
Output:-
1 NIDHI 5
2 SADHANA 10
3 TEJASHREE 15
4 RUTUJA 20
5 GAURI 25
6 PRIYANKA 15000
7 TRUPTI 20000
9 APARNA 25000
11 RUCHIRA 35000
13 ASMI 40000
5. ALTER SEQUENCE S2
MAXVALUE 10
CACHE 2
CYCLE;
Output:-
1 NIDHI 5
2 SADHANA 10
3 TEJASHREE 15
4 RUTUJA 20
5 GAURI 25
6 PRIYANKA 15000
7 TRUPTI 20000
9 APARNA 25000
9 APARNA 25000
11 RUCHIRA 35000
1 SHRADDHA 45000
6. CREATE SEQUENCE S3
MAXVALUE 4
NOCYCLE;
Output:-
SEQUENCE CREATED.