ORDBMSConceptsandOracle8i LabExercisesandSolutions
ORDBMSConceptsandOracle8i LabExercisesandSolutions
ORDBMSConceptsandOracle8i LabExercisesandSolutions
Lab 1
Student_id varchar2(20)
Last_name varchar2(25)
First_name varchar2(20)
Dob varchar2(20)
Address varchar2(300)
City varchar2(20)
State varchar2(2)
ZipCode varchar2(9)
Telephone varchar2(10)
Fax varchar2(10)
Email varchar2(100)
Course_Id varchar2(5)
Department_Id varchar2(20) foreignkey department(department_id)
Title char(60)
Description varchar2(200)
Additional_fees number primarykey (course_id, department_id)
Schedule_Id varchar2(20)
Schedule_Description varchar2(200)
Schedule_Id varchar2(20)
Day number
Starting_Time date
Duration number
Class_Building varchar2(25)
Class_Room varchar2(25)
Seating_Capacity varchar2(2)
Student_Id varchar2(20)
Class_Id varchar2(20)
Grade varchar2(2)Check
Grade in ('A','A+','A-','B','B+','B-',
'C','C+',C-','D','D+','D-','F','F+','F-')
Date_Grade_Assigned date
Lab 2
(4) Alter the new column Position which datatype varchar2 and size 25 with a check constraint which
checks for
(6) Alter the Schedule Type Details to make the following changes:
(7) Alter the Class Location Table to make the following Changes:
Add a foreign key for the column Schdule_Id which refers schedule(Schedule_Id)
Add a foreign key for the column Department_Id which refers Department(Department_Id)
Add a foreign key for the column Course_Id which refers Course(Course_Id).
(10) Add the new column hod the data type is varchar2(25) into depart_info.
Lab 3
(1) Insert Records into the following tables. (Hint: insert minimum 10 records in each table).
Lab 4
Lab 5
(1) Display all information from the Student table whose lastname is null.
(2) Display the Student Id and the Firstname from the Student table who doesn't have a telephone and
an email.
(4) Display Students Lastname whose state starts with the letter "T".
(5) Display Students Id, LastName whose state ends with the letter 'A'.
(6) Display Students Firstname, Dob whose Firstname contains 'A' in the Fourth position.
(8) Display all information from the Student table where the Students Firstname is of only ten
characters.
Lab 6
(3) Display the Students Firstname, Address whose birthday falls in the month of January.
(4) Display the eldest male Student's Firstname from the Student table.
(5) Display all information of the youngest female student from the Student table.
(6) Display the Students Id whose age is greater than 26 as on current date.
(8) Display the Instructors Firstname, lastname concatenated together and the first character in
capitals.
Lab 7
(1) Display the last day of the current month.
(5) Display the next date of the given day that immediately follows the sysdate.
(7) Display the students date of birth rounded to the nearest month.
Lab 8
(1) Display Students Id from the Student table whose Lastnames are unique.
(2) Display Students Id, Firstname from the Student table whose Zipcode Contains two zeros.
(3) Display Course Id, Department Id from the Course table where the additional fees is the least.
(4) Display the Course Id, Additional fees from the course table with the additional fees in the format
'$999.99'.
(5) Display the Average additional fees for the courses from the Course table.
(6) Display Additional fees from the course table rounded off to the nearest integer.
(7) Display minimum additional fees, maximum additional fees and difference between the minimum
and the maximum fees from the course table.
(8) Display Scheduled Id from the Schedule Type table for which the starting time is next month and
duration is less than three.
(9) Display Scheduled Id from the Schedule Type for which the starting time is current day.
(10) Display all from Schedule Type table where the starting time is between ten days prior the current
date and ten days after the current date.
(11) Display Schedule Type, Duration, days past since their starting date from Schedule Type table.
(12) Display all from Schedule Type table with the month of starting time spelled out.
(13) Display all from Schedule Type table where the starting date falls in the current week of this month.
(14) Display all from the Class location table substitute the Seating capacity to 'Not Applicable" if its
null.
(15) Display all from the Class table where the classrooms are unique and have the same instructor.
Lab 9
(1) Update all informations from the Student table whose lastname is null to a last name of 'Nil'.
(2) Update the Firstname from the Student table who doesn't have a telephone and an email to a value
of 'Radiant'.
(4) Update Students Last Name whose state starts with the letter 'T' to a value of 'TTT'.
(5) Update LastName whose state ends with the letter 'A' to a value of 'AAA'.
(6) Update Students Firstname to 'XXX', Dob to current date whose Firstname contains 'A' in the
Fourth position.
(7) Update Students last name to 'YOUTH' whose age is less than 20.
(9) Update the eldest male Student's Last name from the Student table to 'SENIOR'.
(10) Update students last name to 'JAN' whose birthday falls on January.
Lab 10
(1) Delete all informations from the Student table whose lastname is null.
(2) Delete the information from Student table that doesn't have a telephone and an email.
(4) Delete Students information whose state starts with the letter 'T'
(5) Delete Students information whose state ends with the letter 'A'
(6) Delete Students information whose Firstname contains 'A' in the Fourth position.
(7) Delete all information from the Student table where the Students Firstname is of only ten
characters.
(10) Delete the Students information whose birthday falls in the month of October.
(11) Delete the eldest male Student's information from the Student table.
Lab 11
(2) Grant the alter, update, insert privileges to your friend on the table student.
(13) Alter the table employee to add a primary key constraint on the new column age datatype raw. Is it
possible to have a primary key on a column having datatype as raw? Can a table have more than
one primary key?
(2) Concatenate and display the instructors first and last name using built in function
(7) Using employee table display the Empid whose basic is equal to 3000.
(8) Display all the details of employees whose basic is not equal to 4000.
(9) Display all the details of employees whose HRA is greater than 750.
(11) Display the employees record whos PF is lies between 500 to 1000 ranges.
(12) Display the employees details whose id is either e101 or e103 or e104.
(13) Display the absolute value of the given number using built-in functions.
(14) Display the largest integer equal to or less than the given value using built-in functions.
(15) Display the smallest integer greater than or equal to given value using built-in functions.
(4) Find the instructor first name of the given department id.
(9) Determine the minimum and maximum basic of employee; rename the title as max_basic and
min_basic respectively.
(10) Count the number of employee having basic greater than or equal to 2000.
(12) Count the number of student whose state is TN and august month babies.
(14) Translate the first name of the student information table s first character a as b.
Lab 14
(1) Create a view named student from student information and department information tables that
contains only the following columns student_id, first name, last name and department_id.
(2) Update the column of newly created view student. Observe the changes in the base tables.
(3) Create a synonym for course information table with name cours.
(4) Create a sequence instseq with the following specifications minimum value 1, maximum value 20,
increment by 1, start with 0, with cycle and cache 10.
(5) Alter the sequence such that the maximum value is only 15.
(6) Create a local index named stud on first name of student information table.
(7) Create a unique index named stud1 on student_id column of the student information table.
(8) Create a view course_view from the course table with the following fields.
a. Course id.
b. Department id
c. Title
d. Description
e. Additional fees
f. Total fees (i.e. units *250 + additional fees)
(9) Create a view class_summary with the following fields and requirements.
Class.department id = course.department id
Class.course id = course.course id
Class.instructor id = instructor.instructor id
(10) Create a view dummy_view with columns (name, id) from the table(Dummy) which does not exist
in the database.
(12) Create a view from the class table by substituting the column names with relevant names.
(13) Replace the view class_summary by removing the column title from the class table.
(15) Delete the rows from the course_view where deparment id is null and additional fees > 100 and
total fees less than 500.
Lab 15
(1) Create an index stud_last on the student table (Lastname).
(8) Create table dept using the dept_cluster with the following columns.
a. Deptno number(2)
b. Dname varchar2(30)
c. Loc varchar2(20)
(9) Create table emp using the dept_cluster with the following columns.
a. Empno number(3)
b. Ename varchar2(30)
c. Doj date
d. Desig varchar2(10)
e. Sex char(1)
f. Deptno number(2)
g. Salary number(7,2)
h. Comm number(7,2)
(10) Create a sequence named deptno_sequence; with starting value 1 and incrementing by 1, maximum
value is 99, with cycle and cache.
(11) Create a sequence named empno_sequence. With starting value 100 and incrementing by 5,
maximum value is 999, with no cycle and cache.
Lab 16
(1) Create a type address that would contain the following columns:
Add3 varchar2(5)
Add4 number(7)
(2) Create another type emp which will have the above defined user type and the following columns:
(3) Insert into the object emp values for the columns eno as 100 and eadd as 100, first st, Chennai,
600078.
(4) Insert into the object emp values for columns eno as 101 and eadd as 102, iii phases, bgl, 576897.
(5) Write a query to display the eno and add1 from the emp object where add1 has a value of 11.
(6) Write a query to update the eadd column to be 10, ii st, mds,35567 where the eno is 100.
(7) Write a query to delete from the emp table that row whose add1 has a value of 10.
(13) Create a table person_details_table_ty which is based on the type created above.
(14) Create another table other_info_person, has a structure as shown below. It should also contain a
stored table named as person_store_table.
(15) Create a varying array which will contain a maximum of 3 rows and will be of data type
varchar2(8)
(18) Create a table emp which will hold a reference to the above created table and also have a structure
as given below:
Lab 17
(1) Write PL/SQL block to increase the salary by 10% if the salary is > 2500 and > 3000.
(2) Write PL/SQL block to decrease the salary by 13% if the salary is >3000 and < 5000.
(3) Write PL/SQL block to increase the salary by 15% if the salary is > 5000.
While Loops.
(Hint: use basic loops, while loops, numeric for loops, cursor for loops.)
(4) Write PL/SQL block to insert student details into student table until the user wishes to stop.
(5) Write PL/SQL block to insert department details into Department table until the user wishes to
stop.
(6) Write PL/SQL block to display the names of those employees getting salary > 3000.
(8) Write PL/SQL block to display the total salary (I,e.Salary +Comm) of each employee whose comm
Is not null.
(9) Write PL/SQL block to insert the instructor details from the instructor table with the record count
until record count is > 20.
(10) Write PL/SQL block to display the total salary (I,e .Salary + Comm.) of each employee whose
comm. Is not null until sum of total salary exceeds 25,000.
(11) Write PL/SQL block to display the employee details from the employee table, and get the users
choice and delete the record if the user wishes to delete.
(12) Write PL/SQL block to insert only the odd numbers from 1 to 20 into department table as
department id and get the department name from the user.
Lab 18
Cursors.
(1) Write PL/SQL block to increase the salary by 15 % for all employees in emp table.
(2) Write PL/SQL block to decrease the additional _fees in the Course table to 5%.
(3) Write PL/SQL block to increase the additional fees by 10% and if the additional fees exceeds 100
then decrease the additional fees by 20%.
(4) Write PL/SQL block to display the employee details, and the number of employees joined in each
month.
(5) Write a PL/SQL block to get a class_room from the user and display the Starting_time, Duration
from the schedule_type table for that room.
(6) Write a PL/SQL block to get a instuctor first_name and class_room from the user and display the
instructor details, schedule_type details. From the class, schedule_type instructor tables.
(7) Write a PL/SQL block to display the schedule_id, schedule_description, day, starting_time, and
duration from the schedule_type header, schedule_type details tables.
(8) Create a Pl/SQL tables containing the instructor_id, first_name, last_name of the instructor table
and insert values into the table.
(10) Create a PL/SQL tables containing class_id, course_id, department_id, instructor_id, instructor
first_name of the class, instructor tables and insert values into the tables.
Lab 19
Exceptions
(1) Write PL/SQL block to handle the exception no_data_found for the question 5,6 given above.
(2) Write PL/SQL block to handle the exception dup_val_on_index by inserting a duplicate row in the
course table.
(3) Write PL/SQL block to handle the exception value_error by inserting a value of width greater than
20 into the department table.
(3) Write PL/SQL block with a user defined exception and raise the exception, and handle the
exception.
(4) Write PL/SQL block to handle exception, which are not handled by, using others and display a
message.
(1) Create a procedure that takes an argument (description) and deletes the row from the course table.
(2) Create a procedure that displays the instructor details, class details and the student details of a
particular student which the user inputs.
(3) Write a function that takes two arguments viz. student_id, class_id from the user and checks
whether any conflict occurs with any others class with the current class schedule. If occurs give an
alert message that a conflict occurs with the corresponding class else display no conflict.
(4) Write a function that will get the value from the user and insert rows into the class table without
any violation of the integrity constraints.
(5) Write a function that will display the constraint details in the given table.
Check if the instructor is associated with the department that offers the class.
v. Function to calculate the average grade point for the given student.
Arguments (student_id)
Lab 20
Database Triggers.
(1) Write a database trigger before insert for each row on the course table not allowing transactions on
Sundays and Saturdays.
(2) Write a database trigger after update for each row giving the date and the day on which the update
is performed on the class table.
(3) Write a database trigger before delete for each row not allowing deletion and giving message on the
department table.
(4) Write a database trigger after delete for each row on instructor table, which creates a new table
named dump for the first delete, and inserts the deleted row into that table.
(5) Write a database trigger before insert/delete/update for each row not allowing any of these
operations on the table student on Mondays. Wednesdays, Sundays.
(6) Write a database trigger before insert/delete/update for each row not allowing any of these
operations on the table instructor between 6.p.m to 10 a.m
Lab 21
(1) Create a PL/SQL function compute with two parameters eno and bonus. Using this function create
a java program and call this function.
(2) Create a java program using sql query. Select the salary of given employee number.
(3) Create a java program using #sql command retrieves the employees details. Import the sqlj tool.
Lab 22
(1) Create a java program insert the records into the student table. Import the sqlj tool.
(2) Create a java program insert the records into the depart table using PL/SQL commands. Import the
sqlj tool.
(3) Create a java program select the record from emp table and display the records.
Lab 23
(1) Create a new form module for student information table. Create a new block by using the data
block wizard.
Run your form module. Execute a query. Exit run time and return to form builder.
(2) Create new form department information using data block wizard. And modify layout wizard and
run the form module. Execute a query. Exit run time and return to form builder.
(3) Create new form for instructor and course table using tab canvas.
Lab 24
(1) Create new form for schedule using stacked canvas, run the form, execute query, and exit the form.
(2) Create a form for schedule type. Using data block wizard.
(4) Create a form for class table. Run the form and execute the query insert one new record and save it.
(5) Create a form for student grade details. Run a form and delete one record and change the student
grade details.
Lab 25
(1) Create master detail relations for student and student grade table. Student information table is the
master table and student grade table is the detail table it gives the grade detail of the course.
(2) Create a new block by using the data block wizard. Base the block on the course table and include
all columns. Create a relationship and select the master block as department id. Display all items
except department id on the course table. Display the record in this detail block on the same canvas
as the master block. Use a tabular style layout and include a scroll bar.
(3) Create a master detail form for department and instructor tables.
(4) Create a master detail relation for schedule header and schedule type tables.
Lab 26
(1) In this lab session, you will create two LOVs and an editor. Using the LOV wizard, create an LOV
in the student information form to display student id. Attach the LOV to the student_id item in the
data block. Save and run the form.
(2) Using the LOV wizard, create an LOV in the class form. Attach the LOV to the class_id in the data
block. Save and run the form.
(3) Using the LOV wizard, create an LOV in the course form. Attach the LOV to the course_id in the
data block. Save and run the form.
Lab 27
(1) Create a form to calculate the bonus details for the employees with the following fields ecode,
ename, designation, salary and bonus. Using radio group control checks the designation of the
employee (like manager 40%, analyst 30%, programmer 20%, clerk 10%, technical writer 5%). When
we click one button it will calculate the bonus of the employee for the selection of designation.
(2) Create a form for telephone bill calculation with the following fields cname, phno, address, loccall,
stdcall, stdcharge and totalch. Calculate the stdcharge and total charge.
(3) Create a railway ticket reservation form for using reservation table trno, date_of_journey, class,
no.of_seats, berth/seat, start_place, destination_place and train_fare. Calculate the total amount for
reserved seats per classes and display it in display item. Insert the new instance using add button.
Include the modify for update the records, cancel for delete the records, calculate for total train_fare
calculation (no.of_seats * train_fare). And include the navigation button also for moving records.
Lab 28
(1) Create a form for maintaining the stock details. Using the following records pid, pname, unit_price,
qty, costprice and sellingprice. Calculate the total price for purchasing products and display it in
one display item.
(2) Create a form for calculate the charge of patient details. Calculate both in-patient and out-patient
details. Using patient table in this table the columns are pat_id, name, age, pat_cat, diseases,
consult_fees, inject_fees, operation_fees, rent, medicine and ECG scan. In this details calculate
patient total charge using patient category manner the patient category is in and out. If the
patient is out category then calculate the total charge using consult_fees, inject_fees and medicine
but the patient is in then calculate the total charge using consult_fees, inject_fees, rent, medicine if
there is ECG scan or operation_fees then include these fees also and calculate the total charge for in-
patient. Create menu for this form in this menu include add, save, edit, delete, view, navigation
menu (first, next, previous, last) and exit.
Lab 29
(1) Create a tabular report for student information table.
(2) Create a tabular form report for employee table and calculate the total employees salary and their
commission.
(3) Create a report for display the information technology department instructors only.
(4) Create a report for group the course table in department wise and find the maximum fees for each
department.
Lab 30
(1) Create a graph for employees salary details grouping it with manager wise.
YZ
Lab 1
Table created.
Table created.
Table created.
Table created.
Table created.
Table created.
Table created.
Table created.
Table created.
CLASS_ROOM VARCHAR2(25)
COURSE_ID VARCHAR2(5)
DEPARTMENT_ID VARCHAR2(20)
INSTRUCTOR_ID VARCHAR2(20)
SEMESTER VARCHAR2(6)
SCHOOL_YEAR DATE
Lab 2
Table altered.
Table altered.
Table altered.
Table altered.
Table altered.
Table altered.
4. alter table inst add(position varchar2(25)check(position in('ASSISTANT
PROFESSOR','ASSOCIATE PROFESSOR','PROFESSOR')));
Table altered.
Table altered.
Table altered.
Table altered.
Table altered.
Table altered.
Table altered.
Table altered.
Table altered.
Table altered.
9. alter table stud_sche add primary key (student_id, class_id);
Table altered.
Table altered.
Table altered.
Table altered.
Lab 3
1 row created.
2. insert into depart_info values('&department_id',
'&department_name','&hod');
1 row created.
old 2: '&FIRST_NAME','&TELEPHONE','&FAX','&EMAIL','&SEX',
new 2: 'madhu','271 584','001-462-371 584','bala@yahoo.com','m',
Enter value for position: PROFESSOR
old 3: '&POSITION')
new 3: 'PROFESSOR')
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
'&CLASS_BUILDING','&CLASS_ROOM','&COURSE_ID','&DEPARTMENT_ID',
'&INSTRUCTOR_ID','&SEMESTER','&SCHOOL_YEAR');
'&CLASS_BUILDING','&CLASS_ROOM','&COURSE_ID','&DEPARTMENT_ID',
new 2: 'nandhavanam','mca','c02','d01',
Enter value for instructor_id: i01
Enter value for semester: second
Enter value for school_year: 12-apr-00
old 3: '&INSTRUCTOR_ID','&SEMESTER','&SCHOOL_YEAR')
new 3: 'i01','second','12-apr-00')
1 row created.
1 row created.
10 rows selected.
3. savepoint s1;
4. rollback;
5. savepoint upd;
7. savepoint del;
9. savepoint ins;
11. rollback;
Lab 4
Lab 6
5. Select * from stud_info where dob =(select Max(dob) from stud_info) and
sex='female';
Lab 7
Lab 8
Lab 9
6. Update stud_info set first_name = XXX and dob =sysdate where first_name
like ___a%;
Lab 10
Lab 11
3. Revoke msit;
4. savepoint s1;
6. Rollback;
7. Commit;
Lab 12
1. Select MSU techno wing &|| CIT@MSU &|| RADIANT|| ray of hope from
dual;
Lab 13
10. Select count (*) from employee where basic >= 2000;
12. Select count (*) from stud_info where state =TN and
to_char(dob,month)=August;
Lab 14
15. Delete from class_view where department_id is null and additional_fees >
100 and total_fees < 500;
Lab 15
6. Update emp set eadd = address(10, ii st, mds,35567) where eno = 100;
Lab 17
1. begin
if salary > 2500 and salary < 3000 then
salary = salary + 10 /100;
end if;
end;
2. begin
if salary > 3000 and salary < 5000 then
salary = salary + 13 / 100;
end if;
end;
3. begin
if salary > 5000 then
salary = salary + 15 / 100;
end if;
end;
while loops
4. declare
y Boolean = true;
begin
while(y = true)
loop
insert into stud_info values('&Student_id','&Last_name',
'&First_name','&Dob', '&Address', '&city', '&State', '&ZipCode',
'&Telephone', '&Fax', '&Email',&sex);
dbms_output.put_line(do you want to continue);
y := &y;
end loop;
end;
5. declare
y Boolean = true;
begin
while(y = true)
loop
insert into depart_info values('&department_id',
'&department_name','&hod');
dbms_output.put_line(do you want to continue);
y := &y;
end loop;
end;
6. declare
s first_name%type;
begin
select first_name into s from emp where salary > 3000;
dbms_output.put_line(s);
end;
7. declare
s emp%rowtype;
begin
select * into s from emp where sex =male;
dbms_output.put_line(s);
end;
8. declare
t number(9,2);
begin
select (salary + comm) as total_salary from emp where comm is not null;
end;
9. begin
loop
insert into inst values ('&INSTRUCTOR_ID', '&DEPARTMENT_ID', '&LAST_NAME',
'&FIRST_NAME', '&TELEPHONE', '&FAX','&EMAIL','&SEX','&POSITION');
exit when (INSTRUCTOR_ID %rowcount > 20);
end loop;
end;
10. declare
t number(9,2);
begin
loop
select (salary + comm) as total_salary from emp where comm is not null;
exit when total_salary > 25000;
end loop;
end;
11. declare
s emp.eno%type;
begin
dbms_output.put_line(enter the empno);
s := &s;
delete from emp where eno = s;
end;
12. declare
d dept.department_id%type;
d1 dept.department_name%type;
begin
select department_id,department_name into d,d1 from depart_info where
mod(department_id,2)<>0;
dbms_output.put_line(d,d1);
end;
Lab 18
1. Declare cursor c1 is
Select sql from emp;
S emp.sal % type;
Begin
Open c1;
Loop
Fetch c1 into s;
Exit when c1%notfound;
Update emp set sal=sal+s*15/100;
End loop;
Close c1;
End;
2.
declare cursor c2 is
select additional_fees from course;
a course additional_fees%type;
begin
open c2;
loop
fetch c2 into a;
exit when c2%notfound;
update course set additional_fees = a-a * .05;
end loop;
close c2;
End;
3.
declare cursor c3 is
select additional_fees from course;
a course additional_fees % type;
begin
open c3;
loop
fetch c3 into a;
exit when c3%notfound;
if (a+(a*10/100)> 100) then
end if;
end loop
end;
4.
declare cursor c4 is
select * from emp;
j emp.%rowtype;
begin
open c4;
loop
fetch c4 into j;
exit when c4%notfound;
select to_char(doj, month) from emp;
end loop;
end;
5.
declare
s sche_type.shedule_id % type;
st sche_type.starting_time % type;
d sche_type.duration % type;
c class.class_room % type;
begin
c := &c;
select starting_time, duration into st, d from sche_type
where schedule_id = (select schedule_id from class where class_room = c);
dbms_output.put_line(st,d);
end;
6.
declare
f inst.first_name%type;
c class.class_room%type;
begin
f := &f;
c := &c;
select i.instructor_id,i.Department_id,
i.last_name,c1.day,c1.duration,c1.starting_time,
c1.schedule_id, c1.class_room from class a, inst i,
sche_type c1 where inst.first_name = &f and
class.class_room = &c;
end;
7.
begin
select schedule_description, s.schedule_id, s.day,
8. begin
create table ins as select instructor_id, first_name, last_name from inst;
insert into ins values(&instructor_id,&first_name, &last_name);
end;
9. begin
delete from ins;
end;
9. begin
select c.class_id,c.course_id,c.department_id, i.instructor_id,
i.first_name from class c, inst I;
end;
Lab 19
1. declare
s sche_type.shedule_id % type;
st sche_type.starting_time % type;
d sche_type.duration % type;
c class.class_room % type;
begin
c := &c;
select starting_time, duration into st, d from sche_type
where schedule_id = (select schedule_id from class where class_room =
c);
dbms_output.put_line(st,d);
exception
when no_data_found then
dbms_output.put_line(no record found);
end;
2.
declare
f inst.first_name%type;
c class.class_room%type;
begin
f := &f;
c := &c;
select i.instructor_id,i.Department_id,
i.last_name,c1.day,c1.duration,c1.starting_time,
c1.schedule_id, c1.class_room from class a, inst i,
sche_type c1 where inst.first_name = &f and
class.class_room = &c;
exception
when no_data_found then
dbms_output.put_line(no record found);
end;
2.
begin
insert into course values('&course_id','&DEPARTMENT_ID',
'&TITLE','&DESCRIPTION',&ADDITIONAL_FEES,&UNITS);
exception
when dup_val_on_index then
dbms_output.put_line(duplicate record);
end;
3.
begin
insert into depart_info values('&department_id',
'&department_name','&hod');
exception
when value_error then
dbms_output.put_line(value error);
end;
4.
declare
ex1 exception;
n number(5) := &x;
begin
if n > 20000 then
raise ex1;
end if;
exception
when ex1 then
dbms_output.put_line(value must not exceed 20000);
end;
5. declare
err_num number;
err_msg varchar2(100);
begin
insert into temp(empno) values (null);
exception
when others then
err_num := sqlcode;
err_msg := substr(sqlERRm,1,100);
insert into errors values(err_num, err_msg);
end;
begin
delete from class where description = d;
end;
exec dele(Information Technology);
begin
select c.class_id,c.class_building,c.class_room,
s.student_id,s.first_name,s.dob, i.instructor_id, i.first_name from class
c,stud_info s,inst i;
end;
begin
insert into class values('&CLASS_ID','&SCHEDULE_ID',
'&CLASS_BUILDING','&CLASS_ROOM','&COURSE_ID','&DEPARTMENT_ID',
'&INSTRUCTOR_ID','&SEMESTER','&SCHOOL_YEAR');
exception
dbms_output.put_line(duplicate occur);
return (inserted);
end;
begin
n := n+n1+n2+n3+n4;
dbms_output.put_line(the value of ||n);
end;
procedure sub(n interger,n1 integer)is
begin
n := n n1;
dbms_output.put_line(the value of ||n);
end;
procedure mult(n integer,n1 integer,n2 integer)is
begin
n := n * n1 * n2;
dbms_output.put_line(the value of ||n);
end;
end;
begin
select class_id into c from stud_sche where student_id = (select student_id
from stud_info where student_id = sid);
if c = cid then
message registered;
else
message not registered ;
end;
begin
select class_id into c from stud_sche where student_id = (select
student_id from stud_info where student_id = sid);
if c = cid then
return no conflict;
else
return conflict;
endif;
end;
message assigned;
else
message not assigned;
end if;
end;
Lab 20
begin
if not(to_char(sysdate,month)=sunday or
to_char(sysdate,month)=saturday) then
dbms_output.put_line(inserting operation);
else
dbms_output.put_line(insertion not allowed);
end if;
end;
2. create or replace trigger t2 after update of date on class for each row
begin
dbms_output.put_line(updating operation);
end;
begin
dbms_output.put_line(do you want to delete);
end;
begin
insert into temp values('&INSTRUCTOR_ID', '&DEPARTMENT_ID',
'&LAST_NAME', '&FIRST_NAME','&TELEPHONE','&FAX','&EMAIL','&SEX',
'&POSITION');
end;
begin
if (to_char(sysdate,month)=monday or
to_char(sysdate,month)=wednesday or to_char(sysdate,month)=sunday)
then
dbms_output.put_line(trigger operation);
else
dbms_output.put_line(insertion not allowed);
end if;
end;
6. Create or replace trigger t6 before insert/update/delete on inst for each
row
Begin
If not(to_char(sysdate,hh)>=6 p.m or to_char(sysdate,hh)<=10
p.m) then
dbms_output.put_line(trigger operation);
else
dbms_output.put_line(insertion not allowed);
end if;
end;
Lab 21
1.
import java.sql.*;
import java.io.*;
import oracle.jdbc.driver.*;
cstmt.registerOutParameter (1.Types.FLOAT);
cstmt.setInt(2,en);
cstmt.setInt(3,ri);
cstmt.executeUpdate( );
int ot = cstmt.getInt(1);
return ot;
}
}
create or replace function compute (eno number, rise number) return number
as
rt number;
s1 number;
begin
select sal into s1 from emp where empno = eno;
rt := s1 + s1 * (rise/100)return rt;
end;
2.
import java.sql.*;
import java.io.*;
import oracle.jdbc.driver.*;
While (rset.next())
{
s1 = rset.getInt (1);
}
rset.close();
psmt.close();
return s1;
}
}
3.
import java.sql.SQLException;
import oracle.sqlj.runtime.Oracle;
class Ts1
{
public static void main (String args[]) throws SQLException
{
try {
oracle.connect (Ts1.class, connect.properties);
Ts1 ti = new Ts1();
Ti.runExample ();
} catch (SQLException e) {
System.err.println (Error running the example: here only + e);
}
} // End of method main
int dp = 20;
MyIterl iter;
#sql iter = { SELECT ENAME, SAL FROM EMP WHERE DEPTNO = :dp };
while (iter.next()) {
System.out.println(iter.ENAME() + + iter.SAL());
}
}
}
Lab 22
1.
import java.sql.SQLException;
import Oracle.sqlj.runtime.Oracle;
class Ts2
{
public static void main (string args[]) throws SQLException
{
try {
Oracle.connect(Ts2.class, connect.properties);
Ts2 ti = new Ts2();
ti.runExample ();
} catch (SQLExeception e) {
System.err.println(Error running the example: here only + e);
}
} // End of method main
2.
import java.sql.SQLException;
import oracle.sqlj.runtime.Oracle;
class Ts
{
public static void main (String args[]) throws SQLException
{
try {
Oracle.connect (Ts.class, connect.properties);
Ts ti = new Ts();
ti.runExample ();
}catch (SQLException e) {
System.err.println (Error running the example: here only + e);
}
} //End of method main
{
// Issue SQL command to clear the SALES table
while (iter.next()) {
System.out.println(iter.ITEM_NAME());
}
}
3.
import java.sql.SQLException;
import Oracle.sqlj.runtime.Oracle;
class Ts3
{
public static void main (string args[]) throws SQLException
{
try {
Oracle.connect(Ts3.class, connect.properties);
Ts3 ti = new Ts3();
ti.runExample ();
} catch (SQLExeception e) {
System.err.println(Error running the example: here only + e);
}
} // End of method main
while(true)
{
#sql { FETCH : mp INTO :eno, :en, :sl};
if(mp.endFetch())break;
System.out.println(eno);
System.out.println(en);
System.out.println(sl);
}
}
}
Lab 23
Choose all the fields from the stud_info table and select all fields.
Choose the layout wizard and select the type of canvas from this.
Choose all fields from the stud_info table and select all fields.
2. No formal solution. Same above solution are continuing for this question.
3. No formal solution.
Lab 24
1. No formal solution.
2. No formal solution.
3. No formal solution.
4. No formal solution.
5. No formal solution.
Lab 25
1.
create the relation for both stud_info and stud_sche table using student_id
and run the form.
2.
Create the relationship for department and course table and join these two
tables.
3. create the relation for department and inst table using depatment_id as
key.
Lab 26
1. create LOV for student_id and display the student_id for using LOV. and
execute the form.
2. Create a Lov for class table and display the class room detail.
3. create a lov for course table and display the course detail.
Lab 27
declare
ss number (8,2);
na char (10);
do date;
begin
select ename, doj, salary into na, do, ss from bonus
where eno = :eno;
:ename := na;
:doj := do;
:salary := ss;
if :radio_group4 = 1 then
:bonus := ss * .2;
endif;
end;
Trigger : When_Button_Pressed
PL/SQL Code
Begin
:tocharge := :loccall + :stdchr;
End;
Lab 28
1)
Push_button : view
Trigger : When_button_pressed
PL/SQL editor
Declare
al boolean;
Begin
al:= show_lov(lov12);
End;
PL/SQL editor
Declare
pn char(10);
qu number(7);
up number(8,2);
rl number (8,2);
Begin
Select pname, unitprice, quantity, reorderd into pn,up,qu,rl from Stock
where pid = :pid;
:pname := pn;
:unitprice := up;
:quantity := qu;
:reorderd := rl;
end;
Push_button : Exit
Trigger : When_button_pressed
PL/SQL editor
exit_form;
Push_button : previous
Trigger : when_button_pressed
PL/SQL editor
previous_record;
Push_button : Last
Trigger : When_button_pressed
PL/SQL editor
last_record;
Push_button : Next
Trigger : When_button_pressed
PL/SQL editor
next_record;
Push_button : first
Trigger : When_button_pressed
PL/SQL editor
go_block(sto);
first_record;
execute_query;
Push_button : Delete
Trigger : When_button_pressed
PL/SQL editor
delete_record;
commit_form;
Push_button : edit
Trigger : When_button_pressed
PL/SQL editor
go_item(pid);
execute_query;
commit_form;
Push_button : Save
Trigger : When_button_pressed
PL/SQL editor
commit_form;
Push_button : clear
Trigger : When_button_pressed
PL/SQL editor
go_block(sto);
clear_block(no_commit);
go_item(pid);
Sales
Declare
al number;
Begin
go_block(sto);
go_item(pid);
If (:quantity - :ordqty) <= :reorderd then
al := show_alert(alert 35);
Else
Insert into stock values(:pid, :pname, :unitprice, :quantity, :reorderd,
:costprice, :sellingprice, :ordqty);
al :=show_alert(alert 36);
:quantity := :quantity - :ordqty;
:costprice := :unitprice * :quantity;
:sellingprice := :costprice * 5;
execute_query;
commit_form;
end if;
end;
2)
Text_box Age
Trigger key : next_item
go_item(Age);
End if;
Text_box : pcat
Trigger key : Next_item
Text_box : Disease
Trigger : key_next_item
PL/SQL code
:Tcharge :=0;
go_item (cfees);
If :pcat = IP then
go_item(medcharge);
Else
go_item(op_fees);
End if;
Button :Add
trigger :When_button_pressed
clear_block (no_commit);
go_back(pat);
go_item(pid);
Button : Save
Trigger : When_button_pressed
clear_block (do_commit);
Set_item_property (op_fees,enabled,property_on);
Set_item_property (rent,enabled,property_on);
Set_item_property (inpatient,enabled,property_on);
Set_item_property (outpatient, enabled,property_on);
Button : Select
Trigger :When_button_pressed
Declare
F number;
Begin
Select pid, age, pcat, disease, tcharge, cfees, injectfees, op_fees, rent,
medcharge, ecgfees into :pid, :age, :pcat, :Disease, :Tcharge, :cfees,
:injectfees, :op_fees, :rent, :medcharge, ; ecgfees from Host where pid =
:pid;
Set_item_property(outpatient,enabled,property_on);
Set_item_property (inpatient,enabled,property_on);
If :pcat = ip then
Set_item_property(outpatient,enabled,property_off);
Else
Set_item_property(inpatient,enabled,property_off);
End if;
Exception
When no_data_found then
F := show_alert(error);
End;
Button : outpatient
Trigger : When_mouse_click
Begin
If :pcat = op then
:Tcharge := :cfees + :injectfees + :op_fees + :rent + :medcharge +
:ecgfees;
set_item_property (Inpatient,enabled,property_on);
else
message(invalid usage);
end if;
exception
Inpatient
When_mouse_click
Declare
T1 number(8,2);
T2 number(8,2);
T3 number(8,2);
T4 number(8,2);
T5 number(8,2);
Begin
If :pcat = IP then
Select cfees, op_fees,rent,medcharge,ecgfees into T1,T2,T3,T4,T5 from Host
where pid = :pid;
:Tcharge :=T1+T2+T3+T4+T5;
update Host set Tcharge = :Tcharge where pid = :pid;
set_itm_property(Inpatient, enabled,property_on);
else
message(invalid);
end if:
exception
when no_data_found then message (no data found);
end;
Exit
When_button_pressed
Exit_form;
Lab 29
1. create the student information report for stud_info table in tabular form.
4. Create report for group the course table in department wise and also
display the maximum fees.
Lab 30
YZ