DBMS Tutorials
Tutorial 1
Create following tables and insert given values:
(1) SUPPLIER
SUPPLIER_NO NAME ADDRESS
1001 MICHAEL BASILDON
1002 RINGWORLD GERMANY
1003 BABYLON LONDON
1004 JOHN BASILDON
1005 SMITH GERMANY
(2) PRODUCT
SUPPLIER_ MARKETING_ SUPPLY_
DESCRIPTION PRICE
PRODUCT_NO NO REP_NO DEPOT_NO
120 REDUCER 1200 1005 5 6
121 PLATE 1500 1004 3 1
122 HANDLE 700 1003 2 4
WIDGET
124 900 1005 4 2
REMOVER
136 SIZE WIDGET 1000 1001 1 5
137 SIZE WIDGET 15000 1002 2 16
(3) SALESREP
REP_NO NAME
1 MIKE
2 FRED
3 ALI
4 SAM
5 BILL ADAMS
6 SAM
(4) DEPOT
DEPOT_NO LOCATION ADDRESS REP_NO
1 NORTH UK 1
2 SOUTH USA 2
3 LONDON WEST USA 3
4 EAST NZ 4
5 WALES UK 5
6 NORTH KENYA 6
16 SOUTH UK 2
(5) CUSTOMER
CUSTOMER_NO NAME ADDRESS DEPOT_NO CREDIT_LIMIT
10 GARRY SMITH BRIXTON 6 1000
20 PATEL GRANGE 1 4000
30 DRAKE BRIXTON 4 7000
40 BOB SMITH LONDON 2 10000
50 JAMES GRANGE 3 5000
SAN
60 NORTON 5 17000
FRANSISCO
70 JOHN MICHAEL EUROPE 16 8000
(6) CORDER
CORDER_NO CUSTOMER_NO DATE_PLACED DATE_DELIVERED
200 20 01-JAN-1993 04-JAN-1993
201 40 17-JAN-1993 20-JAN-1993
202 20 01-JAN-1993 04-JAN-1993
203 30 02-FEB-1995 05-FEB-1995
204 10 13-MAR-1996 16-MAR-1996
205 70 31-JAN-1993 03-FEB-1993
206 40 01-JAN-1994 04-JAN-1994
207 20 02-AUG-1994 05-AUG-1994
(7) OLINE
CORDER_NO PRODUCT_NO QUANTITY
200 120 5
201 121 10
202 120 5
203 122 20
204 136 30
205 124 15
206 136 30
(8) STOCK
DEPOT_NO PRODUCT_NO QUANTITY RACK BIN_NO
1 120 50 1 1
2 137 100 10 2
3 136 40 2 3
4 120 60 7 1
5 121 90 5 4
6 124 120 4 7
16 122 80 10 8
Tutorial 2
(1) Change the price of „plate‟ from 1500 to 2000.
(2) Modify credit limit to 8000 for those customers who lives in „grange‟.
(3) Change the size of customer address to 30.
(4) Create a table cust1 with the attributes and formats
Customer_no number (10)
Name varchar2 (20)
Address varchar2 (20)
Rep_no number (10)
(5) Add new field email id in cust1 table.
(6) Display the structure of cust1 table.
(7) Display the content of cust1 table.
(8) Delete details of customer no 2 from cust1 table.
(9) Delete email id field from cust1 table.
(10) Delete all the data rows from cust1 and look at the contents again.
(11) Delete the table cust1 and then try to look at its contents again.
Tutorial 3
(1) Display current date and time.
(2) Display all tables created by user.
(3) List the customer numbers (customer_no) and names (name) of all customers.
(4) List all details of the product with a product number (product_no) of 121 and 136.
(5) List all details of depots with rep 5 as their rep(rep_no).
(6) List the product number (product_no) and description only of all products from
supplier number 1005 (supplier_no).
(7) List all details for all customers with names (name) starting from sm followed by 1
character followed by t followed by anything.)
(8) List all details for all orders with date_placed from 1-jan-1993 to 31-jan-1993. (use
between)
(9) List the sales rep number (rep_no), depot number and address for depots located at
NORTH and address is UK.
(10) Give the total number of items (quantity) in stock in all depots.
(11) Give the total number of items (order line quantity) which have been ordered with
corder_no 200.
(12) List product descriptions in reverse alphabetic order.
Tutorial 4
(1) Demonstrate the use of following aggregate and numeric functions:
a) aggregate functions: Avg(), min(), max(), count(), count(*), sum().
b) numeric functions: Abs(), power(), sqrt(), greatest(), least(), round(), mod().
(2) Demonstrate the use of following string and date conversion functions:
a) string functions: Lower(), upper(), initcap(), length(),translate(),trim(),lpad().
b) date conversion functions: to_char(), to_date(), last_day(),months_between().
Tutorial 5
(1) Give a list of depot locations paired with the name of the sales rep who covers that
depot.
(2) List the customer name and the depot location for the depot delivering to that customer
for all customers who receive deliveries from depots looked after by sales rep number
(rep_no) 3.
(3) List the sales rep number (rep_no) and depot location and address for depots looked
after by the sales rep whose name is mike.
(4) For all order lines (oline) for all orders (corder) for customers whose name is patel, list
the customer address, the date_placed, the product_no and the quantity.
(5) Give the total number of items (quantity) in stock in all depots.
(6) Give the total number of items (order line quantity) which have been ordered on the
order with corder_no 200.
(7) List the names of all customers who receive deliveries from depots which are looked
after by the sales rep whose name is fred.
(8) List the customer name, order date_placed, order line quantity and product description
for each order line (with its linked, order, customer and product rows) for customers
who receive deliveries from depot number 2.
(9) List supplier names paired with the names of the sales reps who market products
supplied by that supplier.
(10) List supplier names paired with the names of the sales reps who look after the depots
where products from that supplier are delivered.
(11) List the names of all customers who have ordered products which are marketed by the
sales rep whose name is ali.
(12) List the names of all customers who are delivered to by the depot which delivers to the
customer whose name is drake.
(13) List each product description and its price increased by 10%.
(14) List all order lines for the customer with customer_no 20 giving the product
description, the order line quantity and the value of the order line. (i.e. the order line
quantity * the price from the linked product row)
(15) Llist the locations and addresses of all depots which do not stock product number 122.
(ie where there is no stock row for that product for the depot)
(16) Set up a query which lists the names of all customers who have placed an order with
the order number (corder_no) of the order merged with the names of all customers who
have never placed an order (shown once, with the order number attribute null) i.e. an
outer join.
Tutorial 6
(1) List the description of product which are supplied by supplier SMITH using IN.
(2) List all product no which are not ordered by the customer having same CORDER_NO
as the CUSTOMER_NO 20.
(3) List the locations and addresses of all depots which stock any product which is supplied
to the depot whose location is wales.
(4) List the customer_no, date_placed and date_delivered for all orders which contain order
lines for the product with product_no 137 using existential quantification (ie the where
exists condition).
(5) List the depots which do not stock any product supplied by the supplier whose name is
ringworld.
(6) List the locations and addresses of all depots which stock all products supplied by the
supplier babylon 5.
(7) List the number of different products supplied by each supplier_no.
(8) List the name of each supplier with the location of each depot and the number of
products supplied by that supplier and stocked at that depot.
(9) List all product descriptions with the product's supplie name, sorted by product
description within supplier name(i.e. all products for a supplier listed together in
alphabetic order).
(10) Display customer name who has ordered on same date.
Tutorial 7
(1) List the number of different products supplied by each supplier_no.
(2) List the name of each supplier with the location of each depot and the number of
products supplied by that supplier and stocked at that depot.
(3) List the depot_no's of all depots where the average credit_limit for all the customers
receiving deliveries from the depot is > 20,000.
(4) List total no of quantity and product number ordered by customer.
(5) Give product number which has maximum quantity stock at any depot.
(6) Give customer address which has minimum credit limit.
(7) List supplier no who has supplied products whose total price is < 1000.
(8) Give total number of customers who has ordered product on same date.
(9) List sum of quantity stocked at each rack.
(10) Display total no of customers who has received product from same location.
Tutorial 8
(1) Implement “IF” Condition in Query
a) Put if condition on “price” attribute (IF Else)
b) Try nested IF on “price” attribute.
c) Display Price and quantity and there rating with “High” , “Medium” and
“Low”
(2) Create a view VProduct of product‟s id, description and price.
(3) Create a view of Vorder to get orders (order_id, product_id, description,
customer_name, quantity) placed by customer who belongs to “BRIXTON”.
(4) Insert a new row in VProduct 135, „Sofa‟ and 35000.
(5) Update product‟s quantity to 25 which is brought by customer „DRAKE‟ in Vorder.
(6) Delete details of product id 121 from VProduct.
(7) Delete view VProduct.
(8) Display name of all customers and all suppliers with their id by using union operator.
(9) List product which are not bought by any customer using minus operator.
(10) Give the name of suppliers who is also customer.
Tutorial 9
(1) Write a PL/SQL block to swap two numbers.
(2) Write a PL/SQL block to take personal details (Enrolment Number, Name, Phone
Number and Qualification) from user and display it.
(3) Write a PL/SQL block to find given year is leap year or not.
(4) Write a PL/SQL block to find factorial of a given number using for loop.
(5) Write a PL/SQL block to reverse a given number using while loop.
(6) Write a PL/SQL block to check whether given number is prime or not.
Tutorial 10
(1) Retrieving the records from the any table and displaying them one by one using
cursors.
(2) Create a cursor to increase salary. The salary increase is 20% for the employees
making less than $90,000 and 12% for the employees making $90,000 or more.
(3) Display Customer name and Deport location using Implicit cursor.
Tutorial 11
(1) Create one Stored Procedure to Insert, Delete and Update into one table.
(2) Create one Stored Procedure to increment salary with salary range limit.
(3) Create one Stored Procedure to find largest price with that product name.
Tutorial 12
(1) Trigger will display the salary difference between the old values and new values.
(2) Stop the transaction if the quantity entered (insert) by the user exceeds 1000.
(3) Maintain Log Table with use of trigger.