You are on page 1of 6

SARDAR PATEL UNIVERSITY

BCA
Course : US03CBCA22
(Database Management System - II Lab)
Credits : 02
Lab Hr Per Week : 04

University examination duration : 03 Hours

Page 1 of 6
(US03CBCA22)
Journal List

Assignment 01 : Table creation with constraints:

1. TABLE NAME: DEPT


Name Type Constraints
--------------------- -------- ----------------
DEPTNO NUMBER(2) Primary Key
DNAME VARCHAR2(14)
LOC VARCHAR2(13)

DEPTNO DNAME LOC


------------ ------------- --------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON

2. TABLE NAME: EMP


Name Type Constraints
--------------------- -------- ----------------
EMPNO NUMBER(4) Primary Key
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2) Foreign Key dept (deptno)

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO


7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 09-DEC-82 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 12-JAN-83 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10

Page 2 of 6
3. Create table CUSTOMER_MST

No Field Name Type Size Constraint


1 CUST_NO VARCHAR2 6 It can hold values that must be start with
either ANA or VVN or BAK, PRIMARY
KEY
2 CUST_NAME VARCHAR2 15 Can not hold NULL values
3 ADDRESS VARCHAR2 20
4 CITY VARCHAR2 10 Can hold values either ANAND, V V
NAGAR or BAKROL

Insert following records:

CUST_NO CUST_NAME ADDRESS CITY


ANA001 ALAN UNDI SHERI ANAND
VVN001 SMITH NANA BAZAR V V NAGAR
ANA002 BLAKE TOWN HALL ROAD ANAND
BAK001 ADAMS VADTAL ROAD BAKROL
VVN002 WILLIAMS MOTA BAZAR V V NAGAR
ANA003 RODRICKS TOWN HALL ROAD ANAND

4. Create table CUSTOMER_DTL

No Field Name Type Size Constraint


1 CUST_NO VARCHAR2 6 Reference to the primary key of
CUSTOMER_MST table.
2 BILL_MON VARCHAR2 3
3 PREV_READ NUMBER 5
4 CURR_READ NUMBER 5
5 UNIT_PRICE NUMBER 5,2 VALUE MUST BE GREATER THAN
ZERO
6 DUE_DATE DATE

Insert following records:

CUST_NO BILL_MON PREV_READ CURR_READ UNIT_PRICE DUE_DATE


ANA001 NOV 1234 2545 5.50 26-DEC-05
VVN001 DEC 256 365 5.50 20-JAN-06
ANA002 NOV 245 578 5.50 26-DEC-05
BAK001 DEC 45 145 5.50 20-JAN-06
VVN002 DEC 254 545 5.50 20-JAN-06
ANA003 NOV 2255 2365 5.50 26-DEC-05

Page 3 of 6
Assignment 02 : PL/SQL Block:

1. Write a PL/SQL block to print “HELLO MESSAGE”.


2. Write a PL/SQL block that will take two integer numbers. Print addition,
subtraction, multiplication, division of the inputted numbers.
3. Write a PL/SQL block to take an input in the form of number and check whether
the number is EVEN or ODD.
4. Write a PL/SQL block to take an input in the form of number and check whether
the number is positive, negative or zero.
5. Display the values value from 1 to 10 using LOOP..END LOOP, WHILE..LOOP
AND FOR LOOP.
6. Write a PL/SQL block to take an input in the form of string, print reverse string.

Assignment 03 : PL/SQL Block – Implicit cursor (EMP and DEPT table) (Use of
COMMIT, ROLLBACK and SAVEPOINT)

1. Write a PL/SQL block that will take an input in the form of department number.
Increase the salaries of the employees working in the department by 5.5%. If the
increment updates the total salary of that department by 255 take back the
increment else give the increment permanently.
2. Write a PL/SQL block that will update the salaries of the employees working with
SCOTT. If more than FOUR employees salaries are affected by the increment take
back the increment, else give the increment permanently.
3. Write a PL/SQL block that will take an input in the form of department number.
Decrease the salaries of the employees working in that department by 0.75%. If at
least a record is updated keep the change permanent else print appropriate
message and terminate the block.

Assignment 04 : CURSOR

1. Display empno, name, salary, job and deptno of employees using cursor &
%rowtype
2. Write a cursor to display Department wise Employee information in following
format.
Department wise Employee Information
------------------------------------------------------
Department No. : XX Department Name: XXXX
----------------------------------------------------------------------------------------------
Employee Employee Job Salary Commission Hiredate
Number Name
----------------------------------------------------------------------------------------------
. .. .. ..
. .. .. ..
----------------------------------------------------------------------------------------------

Page 4 of 6
Department No. : XX Department Name: XXXX
----------------------------------------------------------------------------------------------
Employee Employee Job Salary Commission Hiredate
Number Name
----------------------------------------------------------------------------------------------
. .. .. ..
. .. .. ..
----------------------------------------------------------------------------------------------
3. Write a cursor to display the Electricity consumption report in following format.
Electricity consumption
------------------------------------------------------------------------------------------------------------
Customer No Name Consumption City
. .. .. ..
. .. .. ..
------------------------------------------------------------------------------------------------------------
Total Consumption: -----------

4. Write a cursor that will take input as a city and month. And display the inputted
month wise report for particular city in the following format:
Electricity Bill
Current Date:_______
Month: __________
------------------------------------------------------------------------------------------------------------
Readings
Customer No. Name Previous Current Consumption Unit Price Total
Bill
------------------------------------------------------------------------------------------------------------
* ** ** ** ** ** ***
* ** ** ** ** ** ***
------------------------------------------------------------------------------------------------------------

Assignment 05 : PL/SQL Block with exception handling. (EMP and DEPT table)

1. Write a PL/SQL block to take an input in the form of department number. Print
department information if the department number is present in the DEPT table else
print appropriate message and terminate the block.
2. Write a PL/SQL block to take an input in the form of job. Print employee
information if the job is with one employee in the EMP table, if the job is with more
than one employee print appropriate message and terminate the block, and if the
job is not present print appropriate message and terminate the block.
3. Write a PL/SQL block to take an input in the form of department number. If the total
salary paid to that department is greater than 1900 then raise the user defined
exception, print appropriate message and terminate the block. If the total salary is
less than or equal to 1900 update the salaries of the employees working in the
department by 2.5%.
Page 5 of 6
Assignment 06 : FUNCTION

1. Create a function to accept deptno and return dname.


2. Create a function to check salaries of two employees, and return the max out of
two.
3. Create a function that will take employee number, check comm for particular
empno and return his sal, if comm > 450 else return 0 and display message
accordingly.

Assignment 07 : PROCEDURE

1. Write a procedure to display the employee name if the salary > 3500 --for a
particular empno. (supply an empno & return employee name)
2. Write a procedure that will take department number, if that department is having
more than four employees print that department information from the procedure,
else print appropriate message from the BLOCK which calls the procedure.

Assignment 08 : TRIGGERS

Create a table with same structure as EMP named EMP1

1. Insert a record in EMP1 table as and when user inserts a record in EMP table.
2. Insert record(s) in EMP1 table as and when user updates record(s) of EMP table.
3. Insert record(s) in EMP1 table when user deletes record(s) from EMP table.

Page 6 of 6

You might also like