Oracle Bba

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 16

Create a table for employee details with employee number ad

PRIMARY KEY and the following fields name, designation, gender, age,
date of joining and salary. Insert at least 10 rows and perform various
queries using any one comparison, logical, set, sorting and grouping
operator.

EMPNO NAME DESIGNATION GEN AGE DOJ SALARY


---------- -------------- ---------------------- ------- -------- -------------- ------------
101 ANANDHI CLERK F 25 18-MAR-10 23000
102 BALA PROGRAMMER M 30 22-JAN-02 15000
103 CHITHRA JAVA F 27 12-JAN-05 25000
104 GAYATRI C# F 23 14-JAN-12 22000
105 ARUN TEACHER M 29 04-FEB-07 19500
106 SISIRA DOCTOR F 27 25-JUN-09 35000
107 NEHA JOURNALIST F 28 28-DEC-13 26000
108 SEEMA BIOLOGIST F 27 19-JUN-08 20000

EMPNO NAME DESIGNATION GEN AGE DOJ SALARY


---------- -------------- ------------------ -------- -------- -------------- ------------
108 SEEMA BIOLOGIST F 27 19-JUN-08 20000

EMPNO NAME DESIGNATION


------------ -------------- -----------------------
102 BALA PROGRAMMER
105 ARUN TEACHER
108 SEEMA BIOLOGIST
1. EMPLOYEE DETAILS

AIM:

To create a table for employee details with different attributes such as name,
designation, gender, age, date of joining and salary. Set the employee number as primary
key and insert 10 rows for the employee table. Perform various queries using any one
comparison, logical, set, sorting and grouping operator.

ALGORITHM:

STEP 1 – Start the program.

STEP 2 –StartProgramsOracle-OraHome 90Application DevelopmentSQL *Plus.

STEP 3 – Create a table for employee details.


SQL>CREATE TABLE employee(empno int,name char(10),designation
varchar2(10) ,gender char, age int(2),doj date, salary int(6),
CONSTRAINT empno_pk PRIMARY KEY(empno));

STEP 4 – Insert the values into the table.


SQL>INSERT INTO employee VALUES (&empno,’&name’,’&designation’,’&gender’,
&age,’&doj’, &salary);

STEP 5 – View the result.


SQL>SELECT * FROM employee;

STEP 6 – Perform query using conditional and logical operators.


SQL>SELECT * FROM employee WHERE age>=20 AND salary=20000;

STEP 7 – Perform query by using comparison operator.


SQL>SELECT empno, name, designation FROM employee WHERE salary BETWEEN
10000 AND 20000;

STEP 8 – Perform query by using set operator.


SQL>SELECT salary FROM employee WHERE empno>=100 INTERSECT SELECT salary
FROM employee WHERE age>=28;

STEP 9 – Perform operation using grouping operator.


SQL>SELECT salary FROM employee WHERE salary>=20000 GROUP BY empno,
name ORDER BY name;

STEP 11 – Stop the program.


SALARY
-----------
15000
19000

EMPNO NAME DESIGNATION GEN AGE DOJ SALARY


---------- -------------- ------------------ -------- --------- -------------- --------------
102 BALA PROGRAMMER M 30 22-JAN-02 15000
103 CHITHRA JAVA F 27 12-JAN-05 25000
105 ARUN TEACHER M 29 04-FEB-07 19500
108 SEEMA BIOLOGIST F 27 19-JUN-08 20000
106 SISIRA DOCTOR F 27 25-JUN-09 35000
101 ANANDHI CLERK F 25 18-MAR-10 23000
104 GAYATRI C# F 23 14-JAN-12 22000
107 NEHA JOURNALIST F 28 28-DEC-13 26000

EMPNO NAME
-------------- -----------------
101 ANANDHI
103 CHITHRA
104 GAYATRI
107 NEHA
106 SISIRA
108 SEEMA
RESULT:

The above result has been obtained successfully.


Create tables for library management system which demonstrates use of
primary key and foreign key. Master table should have the following fields
account number, title, author and rate. Transaction table should have the
following fields userid,account umber, date of issue and date of return.

Create a report(SELECT verb) with fees, account number,title,date of


issue for the given date of return with column formats.

ACCNO TITLE AUTHOR RATE


----------- ---------------- ------------------------- -------------------
111 MP SARAVANAN 650
222 WEB RAMYA 780
333 DS PRADEEPA 400
444 JAVA KALAIVANI 500
555 FC JANARTHANAN 820

USERID ACCNO DOI DOR


------------ ----------------- ------------------- -------------------
123 111 19-JUN-16 19-JUL-16
234 222 08-MAY-16 9-MAY-16
345 333 10-AUG-16 10-SEP-16
456 444 20-MAY-16 20-JUN-16
567 555 01-JAN-16 01-FEB-16
2. LIBRARY MANAGEMENT SYSTEM

AIM:

To create tables for library management system such as master table and
transaction table, which demonstrate the use of primary key and foreign key. Create a
report with fields fees, account number, title and date of issue for the given date of return
with column format.

ALGORITHM:

STEP 1 – Start the program.

STEP 2 –StartProgramsOracle-OraHome 90Application DevelopmentSQL* Plus.

STEP 3 – Create table ‘master’.


SQL>CREATE TABLE master (accno number (5), title varchar(10),author varchar(10),
rate number (10), CONSTRAINT accno_pk PRIMARY KEY (accno));

STEP 4 –Insert values into master table.


SQL>INSERT INTO master VALUES (&accno,’&title’,’&author’,’&rate’);

STEP 5 – View the master table by using SELECT query.


SQL>SELECT * FROM master;

STEP 6 – Create table ‘transaction’.


SQL>CREATE TABLE transaction (userid number (5),accno number (5),doi date,
dor date);

STEP 7- Insert values for transaction table.


SQL>INSERT INTO transaction VALUES(&userid,&accno,’&doi’,’&dor’);

STEP 8 – View transaction table.


SQL>SELECT * FROM transaction;

STEP 9 – Report generation.


SQL>column accno heading acc.no justify center
SQL>column title heading title justify center
SQL>column rate heading rate justify center
SQL>SELECT master.accno,master.title,transaction.doi FROM master,transaction
WHERE master.accno=transaction.accno AND transaction.dor=’20-JUN-16’;

STEP 10 – Stop the program.


ACC.NO TITLE DOI
--------------- ----------------- ---------------------
444 JAVA 20-MAY-16
RESULT:

The above result has been obtained successfully.


Write a PL/SQL to update the rate field by 20% more than the current rate in
the inventory table which has the following fields: product number, product
name and rate. After updating the table a new field (ALTER) called for number
of item and place values for the new field without PL/SQL block.

PRONO PRONAME RATE


-------------- -------------------- ----------------
100 PENCIL 10
200 PEN 20
300 ERASER 5
400 SHARPNER 7
500 SCALE 8

PRONO PRONAME RATE


-------------- -------------------- ----------------
100 PENCIL 10
200 PEN 20
300 ERASER 6
400 SHARPNER 7
500 SCALE 8
3. INVENTORY TABLE

AIM:

To create a PL/SQL to update the rate field by 20% more than the current rate in the
inventory table. Alter the number of item and place without any PL/SQL block.

ALGORITHM:

STEP 1 – Start the program.

STEP 2 – SelectProgramsOracle-OraHome 90Application DevelopmentSQL * Plus.

STEP 3-Create a table for inventory with attributes such as prono, proname and rate.
SQL>CREATE TABLE invent (prono number(5),proname varchar(10),rate number(4));

STEP 4 – Insert values for the inventory table.


SQL>INSERT INTO invent VALUES(&prono,’&proname’,&rate);

STEP 5 – View the result.


SQL>SELECT * FROM invent;

STEP 6 – Update the rate field by using PL/SQL block.


SQL>BEGIN
2 UPDATE invent SET rate=rate+(rate/100*20) WHERE prono=300;
3 COMMIT;
4 END;
5/
STEP 7 – View the updated table by using SELECT statement.
SQL>SELECT * FROM invent;

STEP 8 – Alter the inventory table by adding a column for ‘number of item’ and insert
values for the new field without using PL/SQL block.
SQL>ALTER TABLE invent ADD noofitem number(10);

STEP 9 – Insert value for the new field ‘number of item’ by using UPDATE statement.
SQL>UPDATE invent SET noofitem=10 WHERE prono=100;

STEP 10 – View the result using SELECT query.


PRONO PRONAME RATE NOOFITEM
-------------- -------------------- ---------------- ---------------------
100 PENCIL 10 10
200 PEN 20 10
300 ERASER 6 10
400 SHARPNER 7 10
500 SCALE 8 10
RESULT:

The above result has been obtained successfully.


REGNO NAME VB RDBMS TOT AVG RESULT
---------- ------------ ---------- ---------- ------------ ---------- --------------
101 ASHA 67 78
102 BARANI 90 90
103 CHITRA 78 89
104 DEEPA 78 78
105 HARIMI 67 90
106 RAVI 35 30

REGNO NAME VB RDBMS TOT AVG RESULT


---------- ------------ ---------- ---------- ------------ ---------- --------------
101 ASHA 67 78 145 72.5
102 BARANI 90 90 180 90
103 CHITRA 78 89 167 83.5
104 DEEPA 78 78 156 78
105 HARIMI 67 90 157 78.5
106 RAVI 35 30 65 32.5

REGNO NAME VB RDBMS TOT AVG RESULT


---------- ------------ ---------- ---------- ------------ ---------- --------------
101 ASHA 67 78 145 72.5 P
102 BARANI 90 90 180 90 P
103 CHITRA 78 89 167 83.5 P
104 DEEPA 78 78 156 78 P
105 HARIMI 67 90 157 78.5 P
106 RAVI 35 30 65 32.5 F
4.

AIM:

ALGORITHM:

STEP 1 – Start the program.

STEP 2 – StartProgramsOracle-OraHome90Application DevelopmentSQL*Plus.

STEP 3 – Create a table named ‘it’ with attributes such as regno, name,VB,
RDBMS, Total, Average and result with regno as primary key
SQL>CREATE TABLE it (regno number(10),name varchar2(10),VB
number(10),RDBMS number(10),tot number (10), avg float(10),result
varchar2(10),CONSTRAINT regno_pk PRIMARY KEY(empno));

STEP 4 – Insert values into the ‘it’ table using INSERT statement.
SQL>INSERT INTO it VALUES (&regno,’&name’,&VB,&RDBMS);

STEP 5 – View the inserted values using SELECT query.


SQL>SELECT * FROM it;

STEP 6 – Enter values for ‘tot’ column using UPDATE statement.


SQL>UPDATE it SET tot=VB+RDBMS WHERE regno=101;

STEP 7 – Enter the values for column ‘avg’ using UPDATE statement.
SQL>UPDATE it SET avg=tot/2 WHERE regno=101;

STEP 8 – View the updated table ‘it’.


SQL>SELECT * FROM it;

STEP 9 – Set ‘result’ as ‘P’ if the avg is greater than 40 and update the table.
SQL>UPDATE it SET result=’P’ WHERE avg>40;

STEP 10 - Set ‘result’ as ‘F’ if the avg is less than 40 and update the table.
SQL>UPDATE it SET result=’F’ WHERE avg<40;

STEP 11 – View the updated ‘it’ table.


SQL>SELECT * FROM it;
REGNO NAME VB RDBMS
----------- ----------------- ----------- ------------
101 ASHA 67 78
102 BARANI 90 90
103 CHITRA 78 89
104 DEEPA 78 78
105 HARIMI 67 90

REGNO NAME VB RDBMS


----------- ----------------- ----------- ------------
106 RAVI 35 30
STEP 12 – Use PL/SQL block to retrieve regno, name,VB and RDBMS from IT with result as ‘P’
and exit the block if no such record is found.
SQL> DECLARE
2 c_regno IT.regno%type;
3 c_name IT.name%type;
4 c_vb IT.vb%type;
5 c_rdbms IT.rdbms%type;
6 c_result IT.result%type;
7 CURSOR C_IT IS SELECT regno,name,vb,rdbms,result FROM IT;
8 BEGIN
9 OPEN C_IT;
10 LOOP
11 FETCH c_it into c_regno,c_name,c_vb,c_rdbms,c_result;
12 IF( C_RESULT = 'p' ) THEN
13 DBMS_OUTPUT.PUT_LINE(c_regno || ' ' || c_name || ' ' || c_vb || '
'|| c_rdbms);
14 END IF;
15 EXIT WHEN c_it%notfound;
16 END LOOP;
17 CLOSE C_IT;
18 END;
19 /

You might also like