DBMSLab
DBMSLab
INDEX
S. No Exercise Experiment Name Page No.
Creation, altering and droping of tables and inserting rows into a
1 EXE - 1 table (use constraints while creating tables) examples using SELECT 1-7
command.
Queries (along with sub Queries) using ANY, ALL, IN, EXISTS,
NOTEXISTS, UNION, INTERSET, Constraints. Example: - Select
2 EXE - 2 8-13
the roll number and name of the student who secured fourth rank in
the class.
Queries using Aggregate functions (COUNT, SUM, AVG, MAX and
3 EXE - 3 14-19
MIN), GROUP BY, HAVING and Creation and dropping of Views.
Queries using Conversion functions (to_char, to_number and
to_date), string functions (Concatenation, lpad, rpad, ltrim, rtrim,
lower, upper, initcap, length, substr and instr), date functions 20-28
4 EXE - 4
(Sysdate, next_day, add_months, last_day, months_between, least,
greatest, trunc, round, to_char, to_date)
i. Create a simple PL/SQL program which includes declaration
section, executable section and exception –Handling section (Ex.
Student marks can be selected from the table and printed for those
who secured first class and an exception can be raised if no records 29-32
5 EXE - 5
were found)
ii. Insert data into student table and use COMMIT, ROLLBACK and
SAVEPOINT in PL/SQL block.
Develop a program that includes the features NESTED IF, CASE and
6 EXE - 6 CASE expression. The program can be extended using the NULLIF 33-36
and COALESCE functions.
Program development using WHILE LOOPS, numeric FOR LOOPS,
nested loops using ERROR Handling, BUILT –IN Exceptions, USE 37-40
7 EXE - 7
defined Exceptions, RAISE- APPLICATION ERROR.
Programs development using creation of procedures, passing
8 EXE - 8 41-42
parameters IN and OUT of PROCEDURES.
Program development using creation of stored functions, invoke
9 EXE - 9 functions in SQL Statements and write complex functions. 43-44
EXPERIMENT: 1
1
Aim: Queries for Creating, Dropping, and Altering Tables and insert row into a table (use constraints
while creating tables) examples using Select Command.
Procedure:
SQL>/
3
Enter value for deptno: 20
Enter value for dname: admin
Enter value for loc: hyd
old 1: insert into dept values(&deptno,'&dname','&loc')
1 row created.
SQL> /
Enter value for deptno: 30
Enter value for dname: marketing
Enter value for loc: vzg
old 1: insert into dept values(&deptno,'&dname','&loc')
new 1: insert into dept values(30,'marketing','vzg')
1 row created.
4. Select Command: this command is used to print the record from the existing table.
View all records in dept table:
SQL> select *from dept;
DEPTNO DNAME LOC
10 sales vijayawada
20 admin hyd
30 marketing vzg
View records basing on given criteria on specific column.
Sales
Admin
Marketing
10 sales vijayawada
1. CREATE:
CREATE TABLE: This is used to create a new relation and the corresponding
2. DESC: It is used to describe a schema as well as to retrieve rows from table in descending order.
5
SYNTAX: DESC
EX: SQL> DESC EMP1;
NAME NULL? TYPE
3. ALTER: This is used for add, remove or modify the structure of the existing table
(a) ALTER TABLE ...ADD...: This is used to add some extra fields into existing relation.
Syntax: ALTER TABLE relation_name ADD(new field_1 data_type(size), new field_2
data_type(size),..);
(b) ALTER TABLE...MODIFY...: This is used to change the width as well as data type of fields of
existing relations.
Syntax: ALTER TABLE relation_name MODIFY (field_1 newdata_type(Size), field_2
newdata_type(Size),. .. , field_newdata_type(Size));
Example:
SQL>ALTER TABLE emp1 MODIFY(ename VARCHAR2(20), salary NUMBER(5));
TABLE ALTERED.
4. DROP TABLE: This is used to delete the structure of a relation. It permanently deletes the table.
Syntax: DROP TABLE tablename;
Example:
SQL>DROP TABLE EMP1;
Table dropped;
DROP: this command is used to remove the date from the existing table
DROP COLUMN IN TABLE
Syntax:
To DROP A COLUMN in an existing table, the Oracle ALTER TABLE syntax is:
ALTER TABLE table_name DROP COLUMN column_name;
Example customers DROP COLUMN customer_name;
SQL> ALTER TABLE customers DROP COLUMN customer_name;
6. TRUNCATE: This command will remove the data permanently. But structure will not be removed.
7
Syntax: TRUNCATE TABLE <Table name>
Example :
TRUNCATE TABLE EMP1;
EXPERIMENT: 2
8
QUERIES (ALONG WITH SUB QUERIES) USING ANY, ALL, IN, EXISTS, NOTEXISTS,
UNION, INTERSECT
SOLUTION:
To Create employee table:
Sql> create table employee(
Fname varchar2(20),
Lname varchar2(20),
Ssn number(4) primary key,
B_date date,
Address varchar2(30),
Gender char(1),
Salary number(7,2),
Super_ssn references employee(ssn),
Dno number(4)
);
Table created.
Like this we can insert the values into the table. To view data in the table following query is used.
9
SQL> SELECT *FROM EMPLOYEE;
1111 SMITH M
2222 POOJA F
3333 MARTIN M
3333 RAJA M
1. ALL:
Retrieve the names of employees whose salary is greater than the salary of all the employees in
department 10
SQL> SELECT FNAME, LNAME FROM EMPLOYEE WHERE SALARY> ALL ( SELECT
SALARY FROM EMPLOYEE WHERE DNO=10);
FNAME LNAME
ALLEN
MARTIN
TURNER
2. ANY
Retrieve the names of employees whose salary is greater than the salary of any one of the employees in
department 10
SQL> SELECT FNAME, LNAME FROM EMPLOYEE
WHERE SALARY> ANY( SELECT SALARY FROM EMPLOYEE WHERE DNO=10);
FNAME LNAME
TURNER
MARTIN
ALLEN
BLAKE
SMITH
KITS DIVILI DEPARTMENT OF CSE
DATABASE MANAGEMENT SYSTEMS - R1922058
3. IN
11
Retrieve the name of each employee who has a dependent with the firstname and same gender as the
employee
FNAME LNAME
SMITH
MARTIN
4. EXISTS
Retrieve the name of each employee who has a dependent with the firstname and same gender as the
employee
FNAME LNAME
SMITH
MARTIN
5.NOT EXISTS
Retrieve the names of employees who have no dependents
SQL> SELECT FNAME, LNAME FROM EMPLOYEE WHERE NOT EXISTS (SELECT *
FROM DEPENDENT WHERE SSN=ESSN);
FNAME LNAME
ALLEN
SQL Constraints 12
SQL constraints are used to specify rules for the data in a table.
Constraints are used to limit the type of data that can be insert into a table. This ensures the accuracy
and reliability of the data in the table. If there is any violation between the constraint and the data
action, the action is aborted.
Constraints can be column level or table level. Column level constraints apply to a column, and table
level constraints apply to the whole table.
The following constraints are commonly used in SQL:
NOT NULL - Ensures that a column cannot have a NULL value
Example:
SQL> create table person1 (id int, name varchar2 (10) not null, age int);
Table created.
UNIQUE - Ensures that all values in a column are different
Example:
SQL> create table person(id int unique, name varchar2(10),age int);
Table created.
PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Uniquely identifies each
row in a table
Example:
SQL> create table emp1(id number(10) primary key, name varchar2(10),sal int);
Table created.
FOREIGN KEY - Uniquely identifies a row/record in another table
o A FOREIGN KEY is a key used to link two tables together.
o A FOREIGN KEY is a field (or collection of fields) in one table that refers to the
PRIMARY KEY in another table.
o The table containing the foreign key is called the child table, and the table containing the
candidate key is called the referenced or parent table.
Example:
SQL> create table emp2 (eid int, city varchar2(10),foreign key(eid) references emp1(id));
Table created.
EXPERIMENT: 3
14
QUERIES USING AGGREGATE FUNCTIONS (COUNT, SUM, AVG, MAX AND MIN)
GROUP BY, HAVING and Creation and dropping of Views.
SOLUTION:
1. COUNT: Calculate the number of employees in dept 20.
SQL> SELECT COUNT (*) NO_EMP FROM EMP WHERE DEPTNO=20;
NO_EMP
30 9400
20 10875
10 8750
30 2850
20 3000
10 5000
5. MIN
15
Calculate the minimum salary for each dept
SQL> SELECT DEPTNO, MIN(SAL) FROM EMP GROUP BY DEPTNO
DEPTNO MIN(SAL)
30 950
20 800
10 1300
6. GROUP BY:
The GROUP BY clause is a SQL command that is used to group rows that have the same values.
The GROUP BY clause is used in the SELECT statement .Optionally it is used in conjunction with
aggregate functions to produce summary reports from the database.
GROUP BY Syntax
SELECT statements… GROUPBY column_name1[column_name2,…];
Grouping using a Single Column:
Create a table called data with gender column and values as male and female.
SQL> select * from data;
GENDER
male
female
female
female
female
female
male
male
male
female
male
male
female
male
male
female
16 rows selected.
male
female
8 male
8 female
3 c
4 d
1 a
2 b
5 a
1 z
6 e
7 rows selected.
KITS DIVILI DEPARTMENT OF CSE
DATABASE MANAGEMENT SYSTEMS - R1922058
7. HAVING
17
The HAVING clause was added to SQL because the WHERE keyword could not be used with
aggregate functions.
The WHERE clause places conditions on the selected columns, whereas the HAVING clause places
conditions on groups created by the GROUP BY clause.
The HAVING clause must follow the GROUP BY clause in a query and must also precede the
ORDER BY clause if used
HAVING Syntax
SELECT column_name(s) FROM table_name WHERE condition GROUP BY column_name(s)
HAVING condition
1 a cse 1000
2 b ece 2000
3 c eee 3000
4 d cse 4000
5 e ece 5000
SQL> select count (id), dept from emp GROUP BY dept having count (id)>1;
COUNT(ID) DEPT
---------------- ---------
2 cse
2 ece
8. View :
o Views in SQL are considered as a virtual table. A view also contains rows and columns.
o To create the view, we can select the fields from one or more tables present in the database.
o A view can either have specific rows based on certain condition or all the rows of a table.
EXPERIMENT: 4
20
QUERIES USING CONVERSION FUNCTIONS (TO_CHAR, TO_NUMBER AND TO_DATE),
STRING FUNCTIONS (CONCATENATION, LPAD, RPAD, LTRIM, RTRIM, LOWER, UPPER,
INITCAP, LENGTH, SUBSTR AND INSTR), DATE FUNCTIONS (SYSDATE, NEXT_DAY,
ADD_MONTHS, LAST_DAY, MONTHS_BETWEEN, LEAST,
GREATEST, TRUNC, ROUND, TO_CHAR)
a) Conversion Functions:
1. to_char: to_char is used to convert the attribute values to char.
SQL> select to_char(salary,'$99999.99') from emp;
TO_CHAR(SALARY)
$15000.00
$20000.00
$42000.00
$23000.00
$50000.00
TO_CHAR (
123.5
TO_CHAR(1
123.46
TO_CHAR(1 21
1,234.57
TO_CHAR(SY
2021/07/09
TO_CHAR(SY
09/07/2021
TO_CHAR
000023
TO_CHAR(
0000023
TO_CHA
00023
TO_CHA
00023
TO_CHA
######
234.568
TO_CHAR(2
2,345.23
TO_CHAR(23
$2,345.23
1210.73
3. to_date: to_date is used for convert and display the attribute values as date.
SQL> select to_date('01-01-2020', 'MM-DD-YYYY') from dual;
TO_DATE('
01-JAN-20
23
b) String functions:
1. Concatenation: CONCAT is used to add two attribute values such as string.
SQL> select concat (eno, loc) from emp;
CONCAT(ENO,LOC)
101vja
102hyd
103vja
104gnt
105hyd
2. lpad: LPAD() function is used to padding the left side of a string with a specific set of characters.
SQL> select lpad(ename,10,'*') from emp;
LPAD(ENAME,10,'*')
*******ali
******haji
**mohammad
******ravi
****irfath
3. rpad: RPAD() function is used to padding the right side of a string with a specific set of characters.
SQL> select rpad(ename,10,'*') from emp;
RPAD(ENAME,10,'*')
ali*******
haji******
mohammad**
ravi******
irfath****
4. ltrim: LTRIM() function is used to remove all specified characters from the left end side of a string
KITS DIVILI DEPARTMENT OF CSE
DATABASE MANAGEMENT SYSTEMS - R1922058
hi********
5. rtrim: RTRIM() function is used to remove all specified characters from the left end side of a string
SQL> select rtrim('******hi********','*') from dual;
RTRIM('*
******hi
6. lower: lower() function is used to convert the attribute value in to lower case.
SQL> select lower(ename) from emp;
LOWER(ENAM
ali
haji
mohammad
ravi
irfath
7. upper: upper() function is used to convert the attribute values in to upper case.
SQL> select upper(ename) from emp;
UPPER(ENAM
ALI
HAJI
MOHAMMAD
RAVI
IRFATH
8. initcap: initcap() is used to convert the attribute values first character in capital letter.
SQL> select initcap (ename) from emp;
KITS DIVILI DEPARTMENT OF CSE
DATABASE MANAGEMENT SYSTEMS - R1922058
INITCAP(EN 25
Ali
Haji
Mohammad
Ravi
Irfath
9. length: length() function is used to calculate the length of the given attribute.
SQL> select ename,length(ename) from emp;
ENAME LENGTH(ENAME)
ali 3
haji 4
mohammad 8
ravi 4
irfath 6
10. substr:substr() function is used to find the substring of the given attribute value. It retuns size-1 of
the given string/ attribute as a sub string.
SQL> select ename, substr(ename,4) from emp;
ENAME SUBSTR(ENAME,4)
ali
haji i
mohammad ammad
ravi i
irfath ath
11. instr: instr() function return the location of starting passion of the sub string in the existing value.
INSTR('WELCOMETO CRRCOE','TO') 26
c) Date functions:
SYSDATE
28-APR-21
NEXT_DAY(
02-MAY-21
3. add_months(): it returns the next date after adding number of months in the orguments.
SQL> select add_months(sysdate,5) from dual;
ADD_MONTH
28-SEP-21
4. last_day(): The LAST_DAY() function takes a date value as argument and returns the last day of
month in that date
SQL> select last_day(sysdate) from dual;
LAST_DAY(
30-APR-21
29-FEB-20
27
5. months_between(): it returns the numbers of months between given two dates.
SQL> select months_between('02-feb-2021','02-feb-2020') from dual;
MONTHS_BETWEEN('02-FEB-2021','02-FEB-2020')
12
MONTHS_BETWEEN(SYSDATE,'02-FEB-2020')
14.8600769
LEAST(300,450,100,440)
100
7. greatest(): it returns maximum values from the given arguments or attributes in the relation.
SQL> select greatest(300,450,100,440) from dual;
GREATEST(300,450,100,440)
450
8. trunc(): The TRUNC() function returns a DATE value truncated to a specified unit.
SQL> select trunc(sysdate,'mm') from dual;
TRUNC(SYS
01-APR-21
01-JAN-21
28
9. round(): Round function round a number to a specified length or precision.
SQL> select round(12.49,0) from dual;
ROUND(12.49,0)
12
ROUND(12.51,0)
13
10. to_char(): it convert the given date type attribute values to text and return the date in the specific
format.
SQL> select to_char(sysdate,'yyyy-mm-dd') from dual;
TO_CHAR(SY
2021-04-28
EXPERIMENT: 5
i. Create a simple PL/SQL program which includes declaration section, executable section and
29
exception –Handling section (Ex. Student marks can be selected from the table and printed for those
who secured first class and an exception can be raised if no records were found).
ii. Insert data into student table and use COMMIT, ROLLBACK and SAVEPOINT in PL/SQL block..
i). We have to create the student table and insert the records in to the table as follows:
PL/SQL CODE:
KITS DIVILI DEPARTMENT OF CSE
DATABASE MANAGEMENT SYSTEMS - R1922058
SQL>ed 5a
30
Enter the following code into the text editor and save the file with .sql format
begin
select sid,sname into temp1,temp2 from student where rank='first';
dbms_output.put_line('Student No:'|| temp1 ||' Name:'||temp2||' got first
rank');
exception
when no_data_found then
dbms_output.put_line('********************************************');
dbms_output.put_line('# Error: there is no student got first rank');
end;
/
SQL> @5a;
********************************************
# Error: there is no student got first rank
SQL> @5a
Student No:503 Name:Ramu got first rank
ii)
SQL> select *from student;
KITS DIVILI DEPARTMENT OF CSE
DATABASE MANAGEMENT SYSTEMS - R1922058
PL/SQL CODE:
SQL>ed 5b
Enter the following code into the text editor and save the file with .sql format
DECLARE
sno student.sid%type;
name student.sname%type;
srank student.rank%type;
BEGIN
sno := &sno;
name := '&name';
srank := '&srank';
INSERT into student values(sno,name,srank);
dbms_output.put_line('One record inserted');
COMMIT;
-- adding savepoint
SAVEPOINT s1;
-- second time asking user for input
sno := &sno;
name := '&name';
srank := '&srank';
INSERT into student values(sno,name,srank);
dbms_output.put_line('One record inserted');
ROLLBACK TO SAVEPOINT s1;
END;
/
SQL> @5b;
SQL> @5b 32
Enter value for sno: 504
old 7: sno := &sno;
new 7: sno := 504;
Enter value for name: ali
old 8: name := '&name';
new 8: name := 'ali';
Enter value for srank: first
old 9: srank := '&srank';
new 9: srank := 'first';
EXPERIMENT: 6
Develop a program that includes the features NESTED IF, CASE and CASE expression. The program
33
can be extended using the NULLIF and COALESCE functions.
A. NESTED IF:
A nested if-then is an if statement that is the target of another if statement. Nested if -then statements
mean an if statement inside another if statement
Syntax:-
if (condition1) then
-- Executes when condition1 is true
if (condition2) then
-- Executes when condition2 is true
end if;
end if;
PL/SQL CODE: PL/SQL Program to find biggest of three number using nested if.
SQL>ed 6a
Enter the following code into the text editor and save the file with .sql format
declare
a number:=10;
b number:=12;
c number:=5;
begin
dbms_output.put_line('a='||a||' b='||b||' c='||c);
if a>b AND a>c then
dbms_output.put_line('a is greatest');
else
if b>a AND b>c then
dbms_output.put_line('b is greatest');
else
dbms_output.put_line('c is greatest');
end if;
end if;
end;
/
SQL> @6a
KITS DIVILI DEPARTMENT OF CSE
DATABASE MANAGEMENT SYSTEMS - R1922058
B. CASE and CASE Expression : CASE statement selects one sequence of statements to execute.
However, to select the sequence, the CASE statement uses a selector rather than multiple Boolean
expressions. A selector is an expression, the value of which is used to select one of several alternatives.
Syntax
CASE selector
WHEN 'value1' THEN S1;
WHEN 'value2' THEN S2;
WHEN 'value3' THEN S3;
...
ELSE Sn; -- default case
END CASE;
SQL> create table emp(eno number(5), ename varchar2(10), loc varchar(10), salary
number(10,2));
Table created.
SQL> insert into emp values(101,'ali','vja',15000);
1 row created.
SQL> insert into emp values(102,'ravi','hyd',25000);
1 row created.
SQL> insert into emp values(103,'raju','gnt',35000); );
1 row created.
SQL> insert into emp values(104,'rakesh','vja',45000);
1 row created.
SQL> select *from emp;
ENO ENAME LOC SALARY
SQL> select loc, case(loc) when 'vja' then salary+2000 when 'hyd' then salary+1000 else salary
35
end "rev_salary" from emp;
LOC rev_salary
vja 17000
hyd 26000
gnt 35000
vja 47000
SQL> ed 6b
SQL> @6b
Enter value for grade: c
old 4: grade:='&grade';
new 4: grade:='c';
good
new 4: grade:='g';
No such grade 36
C. NULLIF: Takes two arguments. If the two arguments are equal, then NULL is returned. otherwise
the first argument is returned.
Syntax: select column_name, NULLIF(argument1,arguement2) from table_name;
Example:
SQL> select ename, nullif('ali','ali1') from emp;
ENAME NUL
ali ali
ravi ali
raju ali
rakesh ali
ali
ravi
raju
rakesh
D. COALESCE: COALESCE () function accepts a list of arguments and returns the first one that
evaluates to a non-null value.
Syntax: coalesce("expression1","expression2",...);
Example:
SQL> select coalesce(NULL,'CRRCOE','IT') from dual;
COALE
CRRCOE
EXPERIMENT: 7
Program development using WHILE LOOPS, numeric FOR LOOPS, nested loops using ERROR
37
Handling, BUILT –IN Exceptions, USE defined Exceptions, RAISEAPPLICATION ERROR.
SQL> @7a
Enter value for endval: 100
old 7: endval:=&endval;
new 7: endval:=100;
sum of odd numbers between 1 and 100 is 2500
B. FOR Loop: A FOR LOOP is a repetition control structure that allows us to efficiently write a loop
KITS DIVILI DEPARTMENT OF CSE
DATABASE MANAGEMENT SYSTEMS - R1922058
C. NESTED LOOP: PL/SQL allows using one loop inside another loop. It may be either
39
basic, while or for loop.
Syntax:
WHILE condition1 LOOP
sequence_of_statements1
WHILE condition2 LOOP
sequence_of_statements2
END LOOP;
END LOOP;
PL/SQL CODE: A PL/SQL program to print n prime number using nested loop.
SQL> ed 7c
DECLARE
i number(3);
j number(3);
BEGIN
i := 2;
LOOP
j:= 2;
LOOP
exit WHEN ((mod(i, j) = 0) or (j = i));
j := j +1;
END LOOP;
IF (j = i ) THEN
dbms_output.put_line(i || ' is prime');
END IF;
i := i + 1;
exit WHEN i = 50;
END LOOP;
END;
/
SQL> @7c
KITS DIVILI DEPARTMENT OF CSE
DATABASE MANAGEMENT SYSTEMS - R1922058
2 is prime
40
3 is prime
5 is prime
7 is prime
11 is prime
13 is prime
17 is prime
19 is prime
23 is prime
29 is prime
31 is prime
37 is prime
41 is prime
43 is prime
47 is prime
EXPERIMENT: 8
KITS DIVILI DEPARTMENT OF CSE
DATABASE MANAGEMENT SYSTEMS - R1922058
SQL> @findname
Procedure created.
SQL> ed pro8
42
set serveroutput on;
declare
enqno2 number(5);
fname2 varchar2(30);
begin
enqno2:=&enqno2;
findname(enqno2,fname2);
dbms_output.put_line('Person name of equiry id '||enqno2||' is '||fname2);
end;
/
SQL> @pro8
Enter value for enqno2: 114
old 5: enqno2:=&enqno2;
new 5: enqno2:=114;
declare
*
ERROR at line 1:
ORA-20100: The given number is not present
ORA-06512: at "SYSTEM.FINDNAME", line 7
ORA-06512: at line 6
SQL> @pro8
Enter value for enqno2: 112
old 5: enqno2:=&enqno2;
new 5: enqno2:=112;
EXPERIMENT: 9
Program development using creation of stored functions, invoke functions in SQL statements and write
43
complex functions.
Sol:
SQL> create table dept(deptno int,dname varchar(10));
Table created.
SQL> insert into dept values(1219,'sai');
1 row created.
SQL> @getname
Function created.
44
SQL> ed pro9
SQL> @pro9
Enter value for deptno: 1219
old 5: deptno2:=&deptno;
new 5: deptno2:=1219;
SQL> @pro9
Enter value for deptno: 1001
old 5: deptno2:=&deptno;
new 5: deptno2:=1001;
declare
*
ERROR at line 1:
ORA-20100: Your entered Department number is not exists
ORA-06512: at "SYSTEM.GETNAME", line 9
ORA-06512: at line 6
EXPERIMENT: 10
KITS DIVILI DEPARTMENT OF CSE
DATABASE MANAGEMENT SYSTEMS - R1922058
Develop programs using features parameters in a CURSOR, FOR UPDATE CURSOR, WHERE
45
CURRENT of clause and CURSOR variables.
Sol:
SQL> create table customers(id number(3), name varchar2(10), age number(3), address
varchar2(10), salary number(10,2));
Table created.
4 rows selected.
SQL> ed pro10
DECLARE
S IR C R REDDY COLLEGE OF ENGINEERING DEPARTMENT OF INFORMATION TECHNOLOGY
c_id customers.id%type;
c_name customers.name%type;
c_addr customers.address%type;
DATABASE MANAGEMENT SYSTEMS - R1922058
46
SQL> @pro10
1 ramesh ahmedabad
2 khilan Delhi
3 kaushik Kota
4 chitali Mumbai
PL/SQL procedure successfully completed.
EXPERIMENT: 11
Develop programs using before and after triggers, row and statement triggers and instead of triggers.
KITS DIVILI DEPARTMENT OF CSE
DATABASE MANAGEMENT SYSTEMS - R1922058
Sol:
47
SQL> create table customers(id number(3), name varchar2(10), age number(3), address
varchar2(10), salary number(10,2));
Table created.
4 rows selected.
PL/SQL Code for creation of trigger while insert / update records into a table.
SQL>ed pro11
SQL> @pro11
Trigger created.
EXPERIMENT: 12
Create a table and perform the search operation on table using indexing and non-indexing techniques.
KITS DIVILI DEPARTMENT OF CSE
DATABASE MANAGEMENT SYSTEMS - R1922058
Sol:
49
SQL> CREATE TABLE TEACHER(STAFF_ID VARCHAR2(4) PRIMARY KEY, STAFF_NAME
VARCHAR2(30), QUALIFICATION VARCHAR2(10), HIREDATE DATE, JOB VARCHAR2(30),
ADDRESS VARCHAR2(15), PH_NUM NUMBER(10), SALARY NUMBER(7, 2), DEPARTMENT
VARCHAR2(10));
Table created.
T101 SUNITHA MCA 29-06-06 ASSOCIATE PROFESSOR VIJAYAWADA 9985061308 23000 MCA
T102 FRED SMITH MTECH 07-MAR-03 ASSOCIATE PROFESSOR GUNTUR 9985063445 36000 MBA
T103 JACK BARNES BTECH 27-JUN-07 PROFESSOR TENALI 9985012345 27000 MTECH
T104 JANE DOE MCA 04-JUL-06 ASSISTANT PROFESSOR VIJAYAWADA 9985045678 29000 BTECH
T105 JOE SHMOE MBA 16-AUG-08 ASSOCIATE PROFESSOR ELURU 9987651308 36000 MCA
T106 JON BAKER MSC(COM) 12-JAN-03 PROFESSOR HYDERABAD 8876561308 46000 MCA
T107 JOHN DOE MSC(PHY) 06-FEB-04 ASSISTANT PROFESSOR VIJAYAWADA 8345661308 31000 MBA
T108 KIM SMITH MCA 10-MAR-08 ASSISTANT PROFESSOR VIZAG 8374561308 26000 MTECH
T109 MARY PARKER MTECH 02-APR-09 PROFESSOR NELLORE 7893427649 52000 MBA
T110 SAMUEL JOHN BTECH 19-MAY-05 ASSISTANT PROFESSOR ELURU 9982222208 26000 MBA
T111 FRANKLIN WONG MBA 20-AUG-06 ASSOCIATE PROFESSOR VIZAG 9985033333 20000 MTECH
T112 SLICIA ZELAYA MCA 16-SEP-04 ASSISTANT PROFESSOR VIJAYAWADA 9985202020 33000 BTECH
T113 JENNIFER WALLACE MSC(MATHS) 25-OCT-03 PROFESSOR HYDERABAD 9902192033 54000 MCA
T114 RAMESH NARAYANA MCA 24-NOV-04 ASSOCIATE PROFESSOR NARASARAOPET 9988776655 34000 MBA
T115 JOYCE ENGLISH MBA 22-DEC-06 ASSISTANT PROFESSOR VIJAYAWADA 9998765443 45000 MBA
15 rows selected.
Elapsed: 00:00:00.24
Index creation:
T101 SUNITHA MCA 29-06-06 ASSOCIATE PROFESSOR VIJAYAWADA 9985061308 23000 MCA
T102 FRED SMITH MTECH 07-MAR-03 ASSOCIATE PROFESSOR GUNTUR 9985063445 36000 MBA
T103 JACK BARNES BTECH 27-JUN-07 PROFESSOR TENALI 9985012345 27000 MTECH
T104 JANE DOE MCA 04-JUL-06 ASSISTANT PROFESSOR VIJAYAWADA 9985045678 29000 BTECH
T105 JOE SHMOE MBA 16-AUG-08 ASSOCIATE PROFESSOR ELURU 9987651308 36000 MCA
T106 JON BAKER MSC(COM) 12-JAN-03 PROFESSOR HYDERABAD 8876561308 46000 MCA
T107 JOHN DOE MSC(PHY) 06-FEB-04 ASSISTANT PROFESSOR VIJAYAWADA 8345661308 31000 MBA
T108 KIM SMITH MCA 10-MAR-08 ASSISTANT PROFESSOR VIZAG 8374561308 26000 MTECH
T109 MARY PARKER MTECH 02-APR-09 PROFESSOR NELLORE 7893427649 52000 MBA
T110 SAMUEL JOHN BTECH 19-MAY-05 ASSISTANT PROFESSOR ELURU 9982222208 26000 MBA
T111 FRANKLIN WONG MBA 20-AUG-06 ASSOCIATE PROFESSOR VIZAG 9985033333 20000 MTECH
T112 SLICIA ZELAYA MCA 16-SEP-04 ASSISTANT PROFESSOR VIJAYAWADA 9985202020 33000 BTECH
T113 JENNIFER WALLACE MSC(MATHS) 25-OCT-03 PROFESSOR HYDERABAD 9902192033 54000 MCA
T114 RAMESH NARAYANA MCA 24-NOV-04 ASSOCIATE PROFESSOR NARASARAOPET 9988776655 34000 MBA
T115 JOYCE ENGLISH MBA 22-DEC-06 ASSISTANT PROFESSOR VIJAYAWADA 9998765443 45000 MBA
15 rows selected.
Elapsed: 00:00:00.13