0% found this document useful (0 votes)
152 views

Rdbms Practical

The document describes a PL/SQL block to calculate student status based on exam marks. It includes: 1. A procedure to calculate total marks and assign a status (pass, fail, distinction etc.) based on marks in each subject and overall percentage. 2. The definition for a table called STUDENT2 to store student details like enrollment number, name, marks in different subjects, total marks and status. 3. Sample data is inserted into the STUDENT2 table for a student with marks in different subjects. The procedure uses a cursor to iterate through records, calculates total marks and percentage, checks for failures in individual subjects, and sets the status based on defined rules for passing,

Uploaded by

Free Fire
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
152 views

Rdbms Practical

The document describes a PL/SQL block to calculate student status based on exam marks. It includes: 1. A procedure to calculate total marks and assign a status (pass, fail, distinction etc.) based on marks in each subject and overall percentage. 2. The definition for a table called STUDENT2 to store student details like enrollment number, name, marks in different subjects, total marks and status. 3. Sample data is inserted into the STUDENT2 table for a student with marks in different subjects. The procedure uses a cursor to iterate through records, calculates total marks and percentage, checks for failures in individual subjects, and sets the status based on defined rules for passing,

Uploaded by

Free Fire
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

SRCMBMM SANCHALIT

SMT K.S.KAPASHI BCA COLLEGE PALITANA


ORACLE USING RDBMS-II PRACTICAL

Create Table for customer Create Table for items


Create table customers create table items
( (
custid varchar2(5), itemid varchar2(5),
custname varchar2(10), itemname varchar2(10),
itemid varchar2(5), custuid varchar2(5),
qty number(5)); qty number(5));

Insert values in customer table Insert values in item table


insert into customers
values('&custid','&custname','&ite insert into items
mid','&qty'); values('&itemid','&itemname','&cus
tid','&qty');

1. Write a PL/SQL block to display the data of the table customer.

declare

cursor cust_data is select * from customers;


cust_row customers%rowtype;

begin
dbms_output.put_line('---------------------------------');
dbms_output.put_line('Cust_Id Cust_Name Item_Id Qty ');
dbms_output.put_line('---------------------------------');

open cust_data;
fetch cust_data into cust_row;
loop
exit when cust_data%notfound;
fetch cust_data into cust_row;
dbms_output.put_line(cust_row.custid || ' - - ' || cust_row.custname ||
' - - ' || cust_row.itemid || ' - - ' || cust_row.qty);
end loop;
close cust_data;
dbms_output.put_line('---------------------------------');
end;

PREPARED BY: DR.HETTAL H BARAD PAGE 1


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

OUTPUT
--------------------------------------
Cust_Id Cust_Name Item_Id Qty
---------------------------------------
c06 - - alpa - - i03 - - 8
c07 - - Hettal - - i03 - - 12
c08 - - krupa - - i04 - - 6
c03 - -jagruti - - i09 - - 6
c03 - - vipul- - i09 - - 6
---------------------------------------

2. Write PL/SQL block that select the row in which the qty is 3
and handle no data found exception.

declare
cursor c_qty(vqty number) is select * from customers where
qty=vqty;
vcust customers%rowtype;
begin
open c_qty(&vqty);
fetch c_qty into vcust;
if c_qty%notfound then
raise no_data_found;
else
dbms_output.put_line('There Are Records with Entered Qty.');
end if;
exception
when no_data_found then
dbms_output.put_line('No Records Found With Specified
Quantity.');
when others then
dbms_output.put_line('Unknown Error.');
end;

OUTPUT
No Records Found With Specified Quantity

PREPARED BY: DR.HETTAL H BARAD PAGE 2


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

3. Write procedure to accept cust_id as input and display the item


that to purchased.

create or replace procedure Accept_Customer(cust_id varchar2) is


item items%rowtype;
cursor c1 is select * from items where custuid=lower(cust_id);
begin
open c1;
dbms_output.put_line(' -----------------');
dbms_output.put_line(' Name Of Item ');
dbms_output.put_line(' -----------------');
fetch c1 into item;
loop
exit when c1%notfound;
fetch c1 into item;
dbms_output.put_line(item.itemname);
end loop;
end;

declare
custid varchar2(5);
begin
custid:='&custid';
Accept_customer(custid);
end;

OUTPUT
Enter value for custid: c21

old 4: custid:='&custid';
new 4: custid:='c21';
-----------------
Name Of Item
-----------------
soap

PREPARED BY: DR.HETTAL H BARAD PAGE 3


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

4. Write a database trigger before delete for each row on table


customer not allowing to delete.

create or replace trigger Cust_delete


before delete on Customers
for each row
begin
raise_application_error(-20021,'Can Not Delete Records From
Customers Table.');
end;

delete from customers where qty=12;

ERROR at line 1:
ORA-20021: Can Not Delete Records From Customers Table.
ORA-06512: at "EXAM21.CUST_DELETE", line 2
ORA-04088: error during execution of trigger
'EXAM21.CUST_DELETE'
5. Write a function to display the name of customer who
purchased dish.

create or replace function display_customer(iname varchar2)


return Boolean is n boolean;
cust customers%rowtype;
cursor c1 is select c.* from customers c,items i where
c.custid=i.custuid and i.itemname=iname;
begin
open c1;
dbms_output.put_line(' -----------------');
dbms_output.put_line(' Name Of Customers ');
dbms_output.put_line(' -----------------');
fetch c1 into cust;
loop
exit when c1%notfound;
fetch c1 into cust;
dbms_output.put_line(cust.custname);
end loop;
close c1;
return n;
end;

PREPARED BY: DR.HETTAL H BARAD PAGE 4


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

declare
n boolean;
iname varchar2(10);
begin
iname:='&iname';
n:=display_customer(iname);
end;

6. Write a database trigger to handle the exception if occur in the


table customer before delete if customer does not exists.

create or replace trigger Cust_check


before delete on customers
for each row
begin
if :old.custname is null then
raise_application_error(-20002,'Customer Does Not Exists.');
end if;
end;

delete from customers;

ERROR at line 1:
ORA-20021: Can Not Delete Records From Customers Table.
ORA-06512: at "EXAM21.CUST_DELETE", line 2
ORA-04088: error during execution of trigger
'EXAM21.CUST_DELETE'

create table cust_item


(
cust_id varchar2(5),
cust_name varchar2(20),
pq number(4),
sq number(4)
);

insert into cust_item


values('&cust_id','&cust_name','&pq','&sq');

PREPARED BY: DR.HETTAL H BARAD PAGE 5


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

 PL/SQL BLOCK

Consider the table :

student (enroll no, name, bdate, English, Maths, Science, Social Sc.,
Hindi, total, status)

Consider the following rules :


Passing marks in each subject = 40 %
If fail in one subject status = GRACE
If fail in two subjects status = ATKT
If fail in three subjects status = FAIL
If pass in all subjects + total above 80 % status =
DISTINCTION
If pass in all subjects + total above 60 % status = FIRST
DIVISION
If pass in all subjects + total below 60 % status = SECOND
DIVISION

(i) Write a PL/SQL procedure to find out the status.


(ii) Write the table definition with all applicable constraints

CREATE TABLE STUDENT2


(ENROLL_NO NUMBER(3) PRIMARY KEY,
NAME VARCHAR2(15),
BDATE DATE,
MARKS_ENG NUMBER(3),
MARKS_MATHS NUMBER(3),
MARKS_SS NUMBER(3),
MARKS_HINDI NUMBER(3),
TOTAL NUMBER(4),
STATUS VARCHAR2(15));
-------------------------------------------------------------------------
INSERT INTO
STUDENT2(ENROLL_NO,NAME,MARKS_ENG,MARKS_MATHS,
MARKS_SS,MARKS_HINDI)
VALUES(1,'PARESH',100,96,57,49);

PREPARED BY: DR.HETTAL H BARAD PAGE 6


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

1. 1) PL/SQL BLOCK TO FIND TOTAL MARKS AND STATUS


OF STUDENT :-
-------------------------------------------------------------------------
DECLARE

E_NO STUDENT2.ENROLL_NO%TYPE;
ENG STUDENT2.MARKS_ENG%TYPE;
MATH STUDENT2.MARKS_MATHS%TYPE;
SS STUDENT2.MARKS_SS%TYPE;
HINDI STUDENT2.MARKS_HINDI%TYPE;
TOT NUMBER(4);
PER NUMBER(5,2);
STAT VARCHAR2(15);

SUB_FAIL NUMBER(2) := 0;

CURSOR C1 IS SELECT
ENROLL_NO,MARKS_ENG,MARKS_MATHS,MARKS_SS,MA
RKS_HINDI
FROM STUDENT2;

BEGIN
OPEN C1;
LOOP
FETCH C1 INTO E_NO,ENG,MATH,SS,HINDI;
EXIT WHEN C1%NOTFOUND;

TOT := ENG + MATH + SS + HINDI;


PER := TOT / 4;

IF ENG < 40 THEN SUB_FAIL := SUB_FAIL + 1;


END IF;
IF MATH < 40 THEN SUB_FAIL := SUB_FAIL + 1;
END IF;
IF SS < 40 THEN SUB_FAIL := SUB_FAIL + 1;
END IF;
IF HINDI < 40 THEN SUB_FAIL := SUB_FAIL + 1;
END IF;

IF SUB_FAIL = 1 THEN STAT := 'GRADE';


ELSIF SUB_FAIL = 2 THEN STAT := 'ATKT';

PREPARED BY: DR.HETTAL H BARAD PAGE 7


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

ELSIF SUB_FAIL > 2 THEN STAT := 'FAIL';


ELSIF SUB_FAIL = 0 AND PER > 80 THEN STAT :=
'DISTINCTION';
ELSIF SUB_FAIL = 0 AND PER > 60 THEN STAT :=
'FIRST DIVISION';
ELSE STAT := 'SECOND DIVISION';
END IF;

UPDATE STUDENT2 SET TOTAL = TOT , STATUS =


STAT WHERE ENROLL_NO = E_NO;
END LOOP;
END;

OUT PUT :: ->

SQL> SELECT * FROM STUDENT2;

ENROLL_NO NAME BDATE MARKS_ENG


MARKS_MATHS MARKS_SS MARKS_HINDI TOTAL
--------- --------------- --------- --------- ----------- --------- ----------- ----
-----
STATUS
---------------
1 PARESH 100 96 57 49
302
FIRST DIVISION
2. Write a PL/SQL block to display the details of Cust-id = d21

declare
cursor disp is select cust_id ,cust_name ,pq,sq from cust_item
where cust_id ='d21';
v_cust_id cust_item.cust_id%type ;
v_cust_name cust_item.cust_name%type ;
v_pq cust_item.pq%type ;
v_sq cust_item.sq%type ;
begin
open disp;
dbms_output.put_line ('v_cust_id' ||' '||'v_cust_name' ||' '||'v_pq' ||'
'||'v_sq');
loop

PREPARED BY: DR.HETTAL H BARAD PAGE 8


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

fetch disp into v_cust_id , v_cust_name ,v_pq ,v_sq;


dbms_output.put_line (v_cust_id ||' '||v_cust_name ||' '||v_pq ||'
'||v_sq);
exit when disp%notfound ;
end loop ;
close disp ;
end;

3. Write function to output purchased qty for the cust-id = 03.

declare

v_cust_id cust_item.cust_id%type ;
v_cust_name cust_item.cust_name%type ;
v_pq cust_item.pq%type ;
v_sq cust_item.sq%type ;
begin
select cust_id ,pq into v_cust_id ,v_pq from cust_item where
cust_id = 'd03';
dbms_output.put_line ('purchase quantity');
dbms_output.put_line ('-----------------');
dbms_output.put_line (v_pq);
end;

output

purchase quantity
-----------------
50

4. Write a procedure to display the details of input cust-id.

create or replace procedure disp1 cust1_id in varchar2(20)


is
declare
v_cust_id cust_item.cust_id%type ;
v_cust_name cust_item.cust_name%type ;
v_pq cust_item.pq%type ;
v_sq cust_item.sq%type ;

PREPARED BY: DR.HETTAL H BARAD PAGE 9


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

begin

select cust_id ,pq into v_cust_id ,v_pq from cust_item where


cust_id=cust1_id;
dbms_output.put_line ('Details of customer_item table');
dbms_output.put_line ('---------------------------------------');
dbms_output.put_line ('v_cust_id' ||' '||'v_cust_name' ||' '||'v_pq' ||'
'||'v_sq');
dbms_output.put_line ('---------------------------------------');
end;

output
custid = d21

CUST_ID CUST_NAME PQ SQ
--------- ---------- ---------------------
d21 Hettal 10
d21 Hettal 20
d21 Hettal 3
5. Write a PL/SQL block to display the details of Cust-item.

declare
cursor disp is select cust_id ,cust_name ,pq,sq from cust_item;
v_cust_id cust_item.cust_id%type ;
v_cust_name cust_item.cust_name%type ;
v_pq cust_item.pq%type ;
v_sq cust_item.sq%type ;
begin
open disp;
dbms_output.put_line ('Details of customer_item table');
dbms_output.put_line ('---------------------------------------');
dbms_output.put_line ('v_cust_id' ||' '||'v_cust_name' ||' '||'v_pq' ||'
'||'v_sq');
dbms_output.put_line ('---------------------------------------');
loop
fetch disp into v_cust_id , v_cust_name ,v_pq ,v_sq;
dbms_output.put_line (v_cust_id ||' '||v_cust_name ||' '||v_pq ||'
'||v_sq);

exit when disp%notfound ;


end loop ;

PREPARED BY: DR.HETTAL H BARAD PAGE 10


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

close disp ;
end;
Output

Details of customer_item table


CUST_ CUST_NAME PQ SQ
----------------------------------
d21 Hettal 10
d02 nilu 20
d03 pappu 50
d21 Hettal 20
d02 nilu 23
d02 nilu 23
d02 nilu 3
d21 Hettal 3
d02 nilu 21
d02 nilu 30
d02 nilu 30

6. Write a PL/SQL block to display details of cust-id if purchased


quantity is null.

declare
cursor disp is select cust_id ,cust_name ,pq,sq from cust_item ;
v_cust_id cust_item.cust_id%type ;
v_cust_name cust_item.cust_name%type ;
v_pq cust_item.pq%type ;
v_sq cust_item.sq%type ;
begin
open disp;
dbms_output.put_line ('customer detal with null purchase id ');
dbms_output.put_line ('-------------------------------------');
dbms_output.put_line (‘cust_id');
dbms_output.put_line ('-------------------------------------');
loop
fetch disp into v_cust_id , v_cust_name ,v_pq ,v_sq;
if v_pq is null then
dbms_output.put_line (v_cust_id );
exit when disp%notfound ;
end if ;
end loop ;

PREPARED BY: DR.HETTAL H BARAD PAGE 11


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

close disp;
end;
output
customer detal with null purchase id
-------------------------------------
cust_id
-------------------------------------
d02
d21
d02
d02
d02

 CURSOR
1. 1. Write a cursor to update first name = Dipali where it is
„Drashti.

DECLARE
cursor c_student is
select f_name from student;
name student.f_name%type := 'Drashti;
v_first_name student.f_name%type;
flag number(1) := 0;
BEGIN
open c_student;
loop
fetch c_student into v_first_name;
if v_first_name = name then
update student set f_name = Dipali where f_name =
'Drashti;
flag := 1;
end if;
exit when c_student%notfound;
end loop;
if flag = 0 then
dbms_output.put_line('Record not found');
end if;
commit;
close c_student;
END;
/

PREPARED BY: DR.HETTAL H BARAD PAGE 12


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

2. Write a cursor to declare a record and display the same.

DECLARE
TYPE t_EmployeeRecord IS RECORD
(
emp_no employee.eno%type;
emp_name employee.ename%type;
emp_add employee.eadd%type;
);
TYPE v_EmployeeRecord employee%ROWTYPE;
cursor c_Employee in select eno,ename,eadd from employee;
v_emp_no employee.eno%type;
v_emp_name employee.enname%type;
v_emp_add employee.eadd%type;
/* DECLARE A VARIABLE OF TYPE RECORD */
v_EmployeeInfo t_EmployeeRecord;
BEGIN
open c_Employee;
loop
fetch c_Employee into v_emp_no,v_emp_name,v_emp_add;
v.EmployeeRecord.emp_no := v_emp_no;
v.EmployeeRecord.emp_name := v_emp_name;
v.EmployeeRecord.emp_add := v_emp_add;
dbms_output.put_line('Emp Number' || ' ' || 'Emp Name' || '
' || 'Emp Add');
dbms_output.put_line(v_emp_no || ' ' || v_emp_name || ' '
|| v_emp_add);
exit when c_Employee%notfound;
end loop;
close c_Employee;
END;
/

3. Example of row-type cursor.

DECLARE
CURSOR c_student is
select * from student;
v_cursorrec c_student%ROWTYPE;
BEGIN

PREPARED BY: DR.HETTAL H BARAD PAGE 13


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

OPEN c_student;
LOOP

FETCH c_student into v_cursorrec;


EXIT WHEN c_student % NOTFOUND;
DBMS_OUTPUT.PUT_LINE(v_cursorrec.FName || ' ' ||
v_cursorrec.LName);
END LOOP;
CLOSE c_student;
END;
/

4. Example of simple cursor.

DECLARE
vFName student.fname%type;
vLName student.lname%type;
CURSOR c_student is
SELECT FName,LName
from student;
BEGIN
OPEN c_student;
DBMS_OUTPUT.PUT_LINE('First Name'|| ' ' || 'Last Name');
LOOP
FETCH c_student INTO vFName,vLName;
EXIT WHEN c_student % NOTFOUND;
DBMS_OUTPUT.PUT_LINE(vFName || ' ' || vLName);
END LOOP;
CLOSE c_student;
END;
/
5. Example of update through cursor.

DECLARE
CURSOR c_student is
select * from student;
v_cursorrec c_student%ROWTYPE;
BEGIN
OPEN c_student;
LOOP
FETCH c_student into v_cursorrec;

PREPARED BY: DR.HETTAL H BARAD PAGE 14


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

EXIT WHEN c_student % NOTFOUND;


if(v_cursorrec.LName='Hi') then
update student set LName='Bye'
where Fname='Anand';
end if;
DBMS_OUTPUT.PUT_LINE(v_cursorrec.FName || ' ' ||
v_cursorrec.LName);
END LOOP;
commit;
CLOSE c_student;
DBMS_OUTPUT.PUT_LINE('Updated Database');
open c_student;
LOOP
FETCH c_student into v_cursorrec;
EXIT WHEN c_student % NOTFOUND;
DBMS_OUTPUT.PUT_LINE(v_cursorrec.FName || ' ' ||
v_cursorrec.LName);
END LOOP;
CLOSE c_student;
END;
/

6. Creates a pl/sql table using cursor.

DECLARE
TYPE t_student IS TABLE OF student.stud_id%type INDEX
BY BINARY_INTEGER;
CURSOR c_student IS SELECT stud_id FROM student;
v_student c_student%ROWTYPE;
v_stud t_student;
v_counter number(3) := 1;
BEGIN
open c_student;
loop
fetch c_student into v_stud(v_counter);
exit when c_student%notfound;
v_counter := v_counter + 1;
end loop;
close c_student;
v_counter := v_stud.first;
dbms_output.put_line('Roll Number');

PREPARED BY: DR.HETTAL H BARAD PAGE 15


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

dbms_output.put_line('===========');
loop
dbms_output.put_line(v_stud(v_counter));
exit when v_counter = v_stud.last;
v_counter := v_stud.next(v_counter);
end loop;
end;
/

7. Example of creating a table using cursor.

DECLARE
TYPE t_student IS TABLE OF student.stud_id%type INDEX BY
BINARY_INTEGER;
CURSOR c_student IS SELECT stud_id FROM student;
v_student c_student%ROWTYPE;
v_stud t_student;
v_counter number(3) := 1;
BEGIN
open c_student;
loop
fetch c_student into v_stud(v_counter);
exit when c_student%notfound;
v_counter := v_counter + 1;
end loop;
close c_student;
v_counter := v_stud.first;
dbms_output.put_line('Roll Number');
dbms_output.put_line('===========');
loop
exit when v_counter = v_stud.last;
v_counter := v_stud.next(v_counter);
end loop;
dbms_output.put_line('The Number of Records in Table are : ' ||
v_counter);
end;
/

PREPARED BY: DR.HETTAL H BARAD PAGE 16


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

 PL/SQL PROCEDURE

1. Consider the following tables:


Emp (emp_no, name, rate_per_hour)
Work (emp_no, date, hours_worked)
Holidays (date)
Salary (emp_no, month, year, amount)

Holidays: At the beginning of the year, list of holidays is already


inserted.

Do the following:
At the end of each month, process records of table Work to calculate
the salary amount and insert a record in Salary table for each
employee in table Work.

Calculate monthly salary for an employee as follows:


working hours limit: 10 hours on working day,
08 hours on holiday.
Discard the hours worked above working hours limit.
If working hours < 2, consider it as zero working hours.
If working hours is between 2 to 4, pay at 60% of the rate.
If working hours is between 4 to 6, pay at 80% of the rate.
If working hours is =6 and =8, pay at 100% of the rate.
If working hours > 8, pay at 120% of the rate.
If an employee has worked on holiday, pay 30% extra.

Note: Use PL/SQL table to store holidays of given month with DD as


index and use proper table attribute to check whether a given day is
holiday or not.

SOLUATION
SQL> create table emp(emp_no number(3) primary key,name
varchar2(20),
2 rate_hr number(5,2));

Table created.

SQL> create table work(emp_no number(3) references emp,dt date,


2 hr_worked number(4,2),primary key(emp_no));

PREPARED BY: DR.HETTAL H BARAD PAGE 17


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

Table created.

SQL> create table holidays(dt date);

Table created.

SQL> create table salary(emp_no number(3) references emp,month


number(4,2),
2 year number(2),amt number(7,2),
3 primary key(emp_no,month,year));

SQL> select * from holidays;

DT
---------
21-SEP-21
08-SEP-21
15-SEP-21
20-SEP-21
22-SEP-21
29-SEP-21
02-OCT-21
06-OCT-21
13-OCT-21
15-OCT-21
20-OCT-21
27-OCT-21

SQL> select * from emp;

EMP_NO NAME RATE_HR


--------- -------------------- ---------
121 Chirag 21
102 Parshad 21.7
103 Harshad 17
104 Satya 14

SQL> select * from work;

EMP_NO DT HR_WORKED
--------- --------- ---------

PREPARED BY: DR.HETTAL H BARAD PAGE 18


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

121 21-SEP-21 7
121 08-SEP-21 9
103 15-SEP-21 2
103 30-SEP-21 4
121 02-OCT-21 1.5
121 14-OCT-21 11
103 25-OCT-21 8
103 31-OCT-21 6
102 15-SEP-21 1
102 30-SEP-21 12
102 15-OCT-21 6
102 31-OCT-21 10
104 21-SEP-21 5
104 17-SEP-21 10
104 30-SEP-21 5
104 31-OCT-21 8

16 rows selected.
SQL> ed
Wrote file afiedt.buf

1. CREATE OR REPLACE PROCEDURE pr_cal_sal(month


NUMBER) AS
CURSOR csr_rec IS
SELECT emp_no,dt,hr_worked FROM work
WHERE TO_CHAR(dt,'mm') = month
GROUP BY emp_no,dt,hr_worked;
CURSOR csr_rate IS SELECT emp_no,rate_hr FROM
emp;
CURSOR csr_hol IS
SELECT * FROM holidays
WHERE TO_CHAR(dt,'mm') = month;
TYPE t_sal_tab IS TABLE OF salary.amt%TYPE
INDEX BY BINARY_INTEGER;
TYPE t_holiday_tab IS TABLE OF NUMBER(2)
INDEX BY BINARY_INTEGER;
TYPE t_rate_tab IS TABLE OF emp.rate_hr%TYPE
INDEX BY BINARY_INTEGER;
tab_hol t_holiday_tab;

PREPARED BY: DR.HETTAL H BARAD PAGE 19


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

tab_rate t_rate_tab;
tab_sal t_sal_tab;
sal NUMBER(6,2) := 0;
v_yr NUMBER(4);
cur_dd INTEGER;
v_hr work.hr_worked%TYPE;
v_no work.emp_no%TYPE;
BEGIN
FOR loop_var IN csr_hol LOOP
v_yr := TO_CHAR(loop_var.dt,'yy');
tab_hol(TO_CHAR(loop_var.dt,'dd')) :=
TO_CHAR(loop_var.dt,'dd');
END LOOP;
FOR loop_var IN csr_rate LOOP
tab_rate(loop_var.emp_no) := loop_var.rate_hr;
tab_sal(loop_var.emp_no) := 0;
END LOOP;
FOR loop_var IN csr_rec LOOP
cur_dd := TO_CHAR(loop_var.dt,'dd');
v_no := loop_var.emp_no;
v_hr := loop_var.hr_worked;
IF (tab_hol.exists(cur_dd)) THEN
IF (v_hr <= 2) THEN
sal := 0;
ELSIF (v_hr <= 4) THEN
sal := (v_hr * tab_rate(v_no))*0.60;
ELSIF (v_hr <= 6) THEN
sal := (v_hr * tab_rate(v_no))*0.80;
ELSE
sal := (v_hr * tab_rate(v_no));
sal := sal*1.30;
END IF;
ELSE
IF(v_hr <= 2) THEN
sal := 0;
ELSIF(v_hr <= 4) THEN
sal := (tab_rate(v_no)*v_hr)*0.60;
ELSIF(v_hr <= 6) THEN
sal := (v_hr * tab_rate(v_no))*0.80;
ELSIF (v_hr <= 8) THEN
sal := (v_hr * tab_rate(v_no));

PREPARED BY: DR.HETTAL H BARAD PAGE 20


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

ELSE
sal := (v_hr * tab_rate(v_no))*1.20;
END IF;
END IF;
tab_sal(v_no) := tab_sal(v_no) + sal;
END LOOP;
FOR loop_var IN csr_rate LOOP
INSERT INTO salary
VALUES(loop_var.emp_no,month,v_yr,
tab_sal(loop_var.emp_no));
END LOOP;
* END pr_cal_sal;
SQL> /

Procedure created.

SQL> call pr_cal_sal(09);

Call completed.

SQL> select * from salary;

EMP_NO MONTH YEAR AMT


--------- --------- --------- ---------
121 9 1 436.8
102 9 1 283.68
103 9 1 40.8
104 9 1 280
2. Write a Pl/Sql Procedure to withdraw amount from the
account specified and if withdrawl is more than currenct
balance then raise error.

create or replace procedure pAcctWithdrawl


(
pAcc_id acct.ac_id%type,
pAmt acct.bal%type
) is
withdrawl_amt acct.bal%type;
amt_val acct.bal%type;
Invalid_Withdrawl Exception;

PREPARED BY: DR.HETTAL H BARAD PAGE 21


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

BEGIN
select bal into amt_val from acct where pAcc_id = ac_id;
withdrawl_amt := amt_val - pAmt;
if (withdrawl_amt < 0 ) then
raise Invalid_Withdrawl;
else
update acct set bal = withdrawl_amt where ac_id = pAcc_id;
end if;
EXCEPTION
when Invalid_Withdrawl then
dbms_output.put_line ('Invalid Withdrawl');
END pAcctWithdrawl;
/
Table :
AC_ID BAL
---------- ----------
1 700
2 2000
3 5000

Output :

SQL> exec pAcctWithdrawl ('1',1200);


Invalid Withdrawl

PL/SQL procedure successfully completed.


3. Write a procedure to check the difference of two entered
dates

create or replace procedure pDates


(
p_to_date date,
p_from_date date
) as
v_diff_date number(5);
e_DateException EXCEPTION;
BEGIN
if p_from_date > p_to_date then
raise e_DateException;
else
v_diff_date := p_to_date - p_from_date;

PREPARED BY: DR.HETTAL H BARAD PAGE 22


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

dbms_output.put_line('Total Number of Days between 2


dates is : ' || v_diff_date);
end if;
EXCEPTION
when e_DateException then
dbms_output.put_line ('Invalid Dates Entered');
when others then
dbms_output.put_line ('Other exception');
END pDates;
/

Ouput :

SQL> exec pDates ('3-NOV-2003','23-OCT-2003');


Total Number of Days between 2 dates is : 11

PL/SQL procedure successfully completed.

4. Write a procedure to find maximum of three numbers.

create or replace procedure pmax


(
pno1 number,
pno2 number,
pno3 number
) as
BEGIN
if ((pno1 > pno2) and (pno1 > pno3)) then
dbms_output.put_line (pno1 || 'is the greatest of three
number');
else
if ((pno2 > pno1) and (pno2 > pno3)) then
dbms_output.put_line (pno2 || ' is the greatest of three
numbers');
else
dbms_output.put_line (pno3 || ' is the greatest of three
numbers');
end if;
end if;
EXCEPTION
when others then

PREPARED BY: DR.HETTAL H BARAD PAGE 23


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

dbms_output.put_line ('sqlcode' || ' sqlerrm');


END pmax;
/

Output :

SQL> exec pmax(4,2,9);


9 is the greatest of three numbers

PL/SQL procedure successfully completed


5. Write a procedure to convert number to characters.

create or replace procedure pnumchar


(
p_number varchar2
) as
v_len number(20);
v_temp number(1);
e_InvalidNumber EXCEPTION;
v_char varchar2(70);
BEGIN
v_len := length(p_number);
for i in 1..v_len
loop
v_temp := substr(p_number,i,1);
if v_temp = '1' then
v_char := v_char || ' One';
elsif v_temp = '2' then
v_char := v_char || ' Two';
elsif v_temp = '3' then
v_char := v_char || ' Three';
elsif v_temp = '4' then
v_char := v_char || ' Four';
elsif v_temp = '5' then
v_char := v_char || ' Five';
elsif v_temp = '6' then
v_char := v_char || ' Six';
elsif v_temp = '7' then
v_char := v_char || ' Seven';
elsif v_temp = '8' then
v_char := v_char || ' Eight';

PREPARED BY: DR.HETTAL H BARAD PAGE 24


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

elsif v_temp = '9' then


v_char := v_char || ' Nine';
elsif v_temp = '0' then
v_char := v_char || ' Zero';
else
raise e_InvalidNumber;
end if;
end loop;
dbms_output.put_line('Character conversion is ' || v_char);
EXCEPTION
when e_InvalidNumber then
dbms_output.put_line ('Invalid Number Entered');
when others then
dbms_output.put_line ('Other error genereted');
END pnumchar
;
/
Ouput :

SQL> exec pnumchar ('068946');


Character conversion is Zero Six Eight Nine Four Six
PL/SQL procedure successfully completed.

 FUNCTIONS
1. Write a function block which checks if the strength of the
department is greater then 80 percent then give a message
that “Dept is full” else “Dept is vacant”.

create or replace function f_dept


(
f_deptid number,
f_course varchar2
)return boolean as
v_currstud dept.currstud%type;
v_maxstud dept.maxstud%type;

BEGIN
select currstud,maxstud into v_currstud,v_maxstud from dept
where f_deptid = deptid and f_course = course;
if ((v_currstud/v_maxstud)*100 >= 80) then

PREPARED BY: DR.HETTAL H BARAD PAGE 25


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

RETURN true;
else
RETURN false;
end if;

END f_dept;
/

Table:

SQL> select * from dept;

DEPTID COURSE CURRSTUD MAXSTUD


---------- ---------- ---------- ----------
1 MCA 53 60
2 MCA 58 60
3 EC 48 70
Call of Function:

DECLARE
v_deptid dept.deptid%type;
v_course dept.course%type;
cursor c_dept is select deptid,course from dept;
BEGIN
open c_dept;
loop
FETCH c_dept into v_deptid,v_course;
exit when c_dept%notfound;
if f_dept(v_deptid,v_course) then
dbms_output.put_line('Dept ' || v_deptid || ' is

almost full');

else
dbms_output.put_line('Dept ' || v_deptid || ' is
vacant');
end if;
end loop;
END;
/

PREPARED BY: DR.HETTAL H BARAD PAGE 26


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

Output:

Dept 1 is almost full


Dept 2 is almost full
Dept 3 is vacant

2. Write a function that converts numbers to characters.


Eg. 21235. Output : Zero One Two Three Five

create or replace function f_numtochar


(
f_char varchar2
)
return varchar2 as
v_int number(3);
v_len number(3);
v_temp varchar2(1);
v_char varchar2(50) := '';
BEGIN
v_len := length(f_char);
for v_int in 1..v_len
loop
v_temp := substr(f_char,v_int,1);
if v_temp = '1' then
v_char := v_char || ' One';
elsif v_temp = '2' then
v_char := v_char || ' Two';
elsif v_temp = '3' then
v_char := v_char || ' Three';
elsif v_temp = '4' then
v_char := v_char || ' Four';
elsif v_temp = '5' then
v_char := v_char || ' Five';
elsif v_temp = '6' then
v_char := v_char || ' Six';
elsif v_temp = '7' then
v_char := v_char || ' Seven';
elsif v_temp = '8' then
v_char := v_char || ' Eight';
elsif v_temp = '9' then

PREPARED BY: DR.HETTAL H BARAD PAGE 27


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

v_char := v_char || ' Nine';


elsif v_temp = '0' then
v_char := v_char || ' Zero';
else
raise invalid_number;
end if;
end loop;
if (v_char = NULL) then
RETURN null;
else
RETURN v_char;
end if;
END f_numtochar;

Function Call:

DECLARE
v_charnum varchar2(10);
BEGIN
v_charnum := '&v_charnum';
if f_numtochar(v_charnum) <> NULL then
dbms_output.put_line (f_numtochar(v_charnum));
else
dbms_output.put_line ('NULL');
end if;
END;
/

Output:

Enter value for v_charnum: 5067


old 4: v_charnum := '&v_charnum';
new 4: v_charnum := '5067';
------------------------------------------------
Output : Five Zero Six Seven
------------------------------------------------

Enter value for v_charnum: 0987


old 4: v_charnum := '&v_charnum';
new 4: v_charnum := '0987';

PREPARED BY: DR.HETTAL H BARAD PAGE 28


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

------------------------------------------------
Output : Zero Nine Eight Seven

3. Write a Pl/Sql function to convert Decimal number to


Hexadecimal number.
create or replace function DecToHex
( f_num number
) return varchar2 as
v_dec varchar2(20);
v_rem number(2);
v_in number(5);
v_int number(3);
v_len number(3);
v_fdec varchar2(20);
BEGIN
v_in := f_num;
while (v_in > 0)
loop
v_rem := v_in mod 16;
v_in := floor(v_in / 16);
dbms_output.put_line('Remainder..' || v_rem);
if (v_rem >= 10) then
if (v_rem = 10) then
v_dec := v_dec || 'A';
elsif (v_rem = 11) then
v_dec := v_dec || 'B';
elsif (v_rem = 12) then
v_dec := v_dec || 'C';
elsif (v_rem = 13) then
v_dec := v_dec || 'D';
elsif (v_rem = 14) then
v_dec := v_dec || 'E';
elsif (v_rem = 15) then
v_dec := v_dec || 'F';
end if;
else
v_dec := v_dec || v_rem;
end if;
end loop;
v_len := length(v_dec);
for v_int in reverse 1..v_len
PREPARED BY: DR.HETTAL H BARAD PAGE 29
SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

loop
v_fdec := v_fdec || substr(v_dec,v_int,1);
end loop;
return v_fdec;
END DecToHex;
/
Output:
SQL> select dectohex(104) from dual;
DECTOHEX(104)
68
4. Write a Function to find whether the enterd number is a
prime number or not.
create or replace function IsPrime
(
f_num number
) return varchar2 as
v_ans varchar2(20);
v_int number(3);
v_temp number (3) := 0;
BEGIN
for v_int in 1..f_num
loop
if (f_num mod v_int = 0) then
v_temp := v_temp + 1;
end if;
end loop;
if v_temp = 2 then
return ('Number ' || f_num || ' is a prime number');
else
return ('Number ' || f_num || ' is not a prime number');
end if;
v_temp := 0;
END IsPrime;
/
Output:

SQL> select IsPrime(7) from dual;


ISPRIME(7)
Number 7 is a prime number

PREPARED BY: DR.HETTAL H BARAD PAGE 30


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

SQL> select IsPrime(6) from dual;


ISPRIME(6)
Number 6 is not a prime number

 EXCEPTION
1. Write a Exception to check the current credits of the
students.

DECLARE
e_ExcessCredits EXCEPTION;
v_CurCredits student.current_credits%type;
BEGIN
select current_credits into v_CurCredits from student
where stud_id = 'mca21';
if v_CurCredits > 20 then
e_ExcessCredits;
end if;
EXCEPTION
when e_ExcessCredits then
dbms_output.put_line ('Error Raised');
when others then
dbms_output.put_line('Other Error Raised');
end;
/
2. Write a Exception to check if current students a greater
than permitted maximum students.
DECLARE
e_ExcessStudents EXCEPTION;
v_CurrentStudent student.current_students%type;
v_MaxStudent student.max_students%type;
BEGIN
select current_students,max_students into
v_CurrentStudent,v_MaxStudent from student where
stud_id = 'mca21';
if (v_CurrentStudent > v_MaxStudent) then
raise e_ExcessStudents;
end if;
EXCEPTION
when e_ExcessStudents then

PREPARED BY: DR.HETTAL H BARAD PAGE 31


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

dbms_output.put_line ('Max Students');


END;
/

 TRIGGER

Consider a whole seller.

Table: Item_master (Ino, Iname, Unit, Per Unit Rate, Stock)

Ino I021 I002 I003


Iname Egg Oil Rice
Unit Dozens Litres K.G.
Per unit rate 20 50 33
Stock 50 Dozens 100 Litres 500 K.G.

Table: Item Transaction (date, Ino, DB_CR, transaction_unit, amount,


processed)Consider the following conditions:
 If Ino = 021 and db_cr = D then Transaction Unit should be in
multiples of 12
 If Ino = 002 and db_cr = D then Transaction Unit should be in
multiples of 5 Litres.
 If Ino = 003 and db_cr = D then Transaction Unit should be in
multiples of 50 k.g.

create table itemmaster( create table itemtranc(


ino varchar2(6) primary key, date1 date,
iname varchar2(20), ino varchar2(6) references
unit varchar2 (10), itemmaster,
perunitrate number(6), db_cr varchar2(1),
stock number(9)) transaction_unit number(10),
amount varchar2(20),
processed varchar2(1))

insert into itemmaster values ('i002','oil','litters',50,1000)


insert into itemmaster values ('i002','rice','k.g.',33,500)
insert into itemmaster values ('i003','rice','k.g.',33,500)

PREPARED BY: DR.HETTAL H BARAD PAGE 32


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

SQL> select * from itemmaster;

INO INAME UNIT PERUNITRATE STOCK


------ -------------------- ---------- ----------- ---------
i021 egg dozzen 20 50
i002 oil litters 50 1000
i003 rice k.g. 33 500

(i) Write a trigger for insertion of data according to the


above rules.

create or replace trigger insertitemtranc


before insert on itemtranc
for each row
declare
amt itemtranc.amount%type;
v_stock itemmaster.stock%type;
begin
calamount(:new.ino,:new.transaction_unit,amt);
select stock into v_stock from itemmaster where ino =
:new.ino;
if v_stock - :new.transaction_unit >=0 then
if :new.ino='i021' and :new.db_cr ='d' then
:new.amount:=amt;
:new.processed:='y';
elsif :new.ino='i002' and :new.db_cr ='d' then
:new.amount:=amt;
:new.processed:='y';
else
:new.amount:=amt;
:new.processed:='y';
end if;
update itemmaster set stock = stock-:new.transaction_unit
where ino = :n
ew.ino;
end if;
* end;
SQL> /

Trigger created.
(iii)Write a trigger to see that the item_code starts with I

PREPARED BY: DR.HETTAL H BARAD PAGE 33


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

create or replace trigger checkitemcode


before insert on itemmaster
for each row
declare
str varchar2(10);
begin
str:=SUBSTR(:new.ino,1,1);
if str='i' or str ='I' then
dbms_output.put_line('success...');
else
raise_application_error(-20021,'Invalid item number');
end if;
end checkitemcode;

Trigger created.

1* insert into itemmaster(ino) values('a004')


SQL> /
insert into itemmaster(ino) values('a004')
*
ERROR at line 1:
ORA-20021: Invalid item number
ORA-06512: at "MCA247.CHECKITEMCODE", line 10
ORA-04088: error during execution of trigger
'MCA247.CHECKITEMCODE'
MCA247->

PREPARED BY: DR.HETTAL H BARAD PAGE 34


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

PRACTICAL ASSIGNMENT WORK


INSTRUCTIONS:
1. Prepare one FOOLSCAP RECORD BOOK to write all this programs.
2. Write it in proper manner that is first program definition, then program
source code, Output and errors if any.
3. Submission of programs in Record book as well as in Lab PC is
compulsory and should be submitted on due date only.
4. The program should follow a good programming practice:
1. Proper naming conventions for identifiers and program name
2. Proper indentation.

A GENERAL PL/SQL BLOCKS


1) WAP to input two numbers and find out what is the output of all
arithmetic operations.(Addition, Subtraction, Multiplication, Division
etc.)
2) WAP to input rollno and three subject marks. Find out total,
percentage, result and grade for the student from the entered data.
3) WAP to print first 10 odd numbers using for loop.
4) WAP to print prime numbers upto 10 using while loop.
5) WAP to input three nos and find out maximum and minimum from
it.
6) WAP to input empno from keybord. Check whether inputted
empno exist in emp tableor not. If not give error message otherwise
display name and salary of that employee.
7) WAP to insert record in Customer table
Customer(cust_id,cust_name,address,city);
B CURSORS:
1) Create a cursor for the emp table. Produce the output in following
format:
{empname} employee working in department {deptno} earns Rs.
{salary}.
EMP(empno, empname, salary, deptno);
2) Create a cursor for updating the salary of emp working in deptno
10 by 20%.
If any rows are affected than display the no of rows affected. Use
implicit cursor.
3) Create a cursor for updating the salary of emp working in deptno
10 by 20%.
Use explicit cursor.
EMP(empno, empname, salary, deptno);
4) WAP that will display the name, department and salary of the first

PREPARED BY: DR.HETTAL H BARAD PAGE 35


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

10 employees
getting the highest salary.
5) WAP using parameterized cursor to display all the information of
employee living in specified city. Ask the city from user.
6) WAP which display the sum of salary department wise.
7) Create a cursor to generate different two tables from one master
table.
Student(Rno, Name, Std, B_date, Sex);
Girl_Table(Rno, Name, Std, B_date);
Boy_Table(Rno, Name, Std, B_date);
First fetch the row from Student table. If sex is ‘M’ then insert that
row in Boy_Table
and if ‘F’ then insert that row in Girl_Table.
In both table Rollno entry must be in Sequence(Using create sequence
command).
C FUNCTIONS :
1)WAF which accepts the name from user and returns the length of
that name.
2) WAF which accepts one number and return TRUE if no is prime
and return FALSE if no is not prime.
3) Write a function which accept the department no and returns
maximum salary of that
department. Handle the error if deptno does not exist or select
statement return more than one row.
EMP(Empno, deptno, salary).
4) Write a function to display whether the inputed employee no is
exists or not.
5) WAF which accepts one no and returns that no+100. Use INOUT
mode.
6) WAF which accepts the empno. If salary<10000 than give raise by
30%. If salary<20000 and salary>=10000 than give raise by 20%. If
salary>20000 than give raise by 10%. Handle the error if any.
7) WAF which accepts the empno and returns the experience in years.
Handle the error if empno does not exist.EMP(Empno, Empname,
DOJ);

D PROCEDURES:
1) Write a procedure which accepts the empno and returns the
associated empname. If empno does not exist than give proper error
message.
EMP(Empno, Empname).
PREPARED BY: DR.HETTAL H BARAD PAGE 36
SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

2) WAP which accepts the student rollno and returns the name,city
and marks of all the subjects of that student.
STUDENT(Stud_ID,Stud_name,m1,m2,m3).
3) WAP which accepts the name from the user. Return UPPER if
name is in uppercase,
LOWER if name is in lowercase, MIXCASE if name is entered using
both the case.
4) WAP which accepts the student rollno and returns the highest
percent and name of that
student to the calling block.
STUDENT(Stud_ID,Stud_name,percent);
5) WAP which accepts the date of joining for specific employee and
returns the years of experience along with its name. Accept the
Employee no from user.
EMP(empno, empname, DOJ);
6) WAP which accepts the student rollno and returns the result (in the
form of class: first class, second class, third class or fail).
STUDENT(Stud_ID,Stud_name,m1,m2,m3).

E TRIGGERS:
1) Write a Trigger that stores the old data table of student table in
student_backup while updating the student table.
Student_backup (Stud_ID, Stud_name, Address, Contact_no, Branch,
Operation_date)
Student (Stud_ID, Stud_name, Address, Contact_no, Branch)
2) Write a trigger, that ensures the empno of emp table is in a format
‘E00021’ (empno must start with ‘E’ and must be 6 characters long).
If not than complete empno with this format before inserting into the
employee table.
3) Write a trigger which checks the age of employee while inserting
the record in emp table. If it is negative than generate the error and
display proper message.
4) Write a trigger which converts the employee name in upper case if
it is inserted in any other case. Change should be done before the
insertion only.
5) WAT that stores the data of emp table in emp_backup table for
every delete operation and store the old data for every update
operation.
EMP(Empno, Empname, salary);
Emp_Backup(Empno,Empname,Date_of_operation,Type_of_operatio
n(i.e.update or delete));

PREPARED BY: DR.HETTAL H BARAD PAGE 37


SRCMBMM SANCHALIT
SMT K.S.KAPASHI BCA COLLEGE PALITANA
ORACLE USING RDBMS-II PRACTICAL

6) WAT which display the message ‘Updating’,’Deleting’ or


’Inserting’ when Update,Delete or Insert operation is performed on
the emp table respectively.
7) WAT which generate an error if any user try to delete from
product_master table on weekends (i.e. Saturday and Sunday).
8) WAT which inserts the value of client_no in the client_master table
whenever user triesto insert data in the emp table. Generate primary
key using sequence and enter the client_no using that sequence.
Client_Master(client_no,client_name,address,city);
9) WAT to calculate the Income Tax amount and insert it in emp
table..
EMP(emp_no,emp_name, emp_income, income_tax);
If emp_income <100000 and >=50000 then incometax = 10%
If emp_income <200000 and >=100000 then incometax = 15%
If emp_income <300000 and >=200000 then incometax = 20%
F EXCEPTION
1)write a PL/SQL block to perform division of two number, manage
appropriate exception
2)write a PL/SQL block to perform use of NO_DATA_FOUND
exception

PREPARED BY: DR.HETTAL H BARAD PAGE 38

You might also like