Sei sulla pagina 1di 2

Practical No 3: Creating database objects, Controlling user

access and using set operators


a) Creating views, sequences, indexes and synonyms

Creation of views for AP database


1. Create view “vendors_view_one” with columns vendor_name, vendor_state and
vendor_phone
2. Create view “vendors_view_two” for vendors table with all the vendors belonging to state
California(CA)
3. Change the phone no to (800) 555 – 3941 for vendor ‘register of copyrights’ in
“vendor_view_one”
4. Drop the above created views
5. Create a view “vendor_phone_list” with column names vendor_name,
vendor_contact_last_name, vendor_contact_first_name and vendor_phone
6. Create a view “vendor_invoices” with columns vendor_name, invoice_number,invoice_date
& invoice_total that joins the details of vendors table & invoices table
7. Create a view with stores the top 5 invoice totals of vendors
(hint: use ROWNUM pseudo column)
8. Create a view “outstanding_invoices” to store invoice_number, invoice_date, invoice_total
and balance_due and balance_due should be greater than zero. (hint: balance_due =
invoice_total – payment_total – credit_total
9. Create a view that calculates the invoice summary of each vendor. Invoice summary includes
total number of invoices and total amount of those invoices by each vendor
10. Create a view “vendor_payment” with WITH CHECK clause, which joins the data from
vendors & invoices tables to display all the invoices that have balance_due greater than
zero.
11. Update view “vendors_payment” to change the payment_total to 400, payment_date to 1st
aug 2008 for invoice number ‘p-0608’.
12. Update view “vendors_payment” to change the payment_total to 4000, payment_date to 1st
aug 2008 for invoice number ‘p-0608’. (note the message)
13. Insert a new row in “vendors_payment”

Creation of sequences on Ap database


1. Create a “vendor_id_seq” sequence on for vendor_id using all the optional parameters
,starting with 120 and ending with 5000. Insert 2 records in the vendors table using
sequence.
2. Find the current value for “vendor_id_seq”
3. Find the next value for “vendor_id_seq”
4. Reset the “maxvalue” attribute of “vendor_id_seq” to 3000
5. Drop sequence “vendor_id_seq”
Creation of synonyms on Accounts payable database:
1. Create public synonyms for each of the tables used by the payment_entry user. Use
AP connection to execute them
2. Drop the synonym created for vendors table

b) Granting & Revoking Privileges on user objects


1. Write a script that creates a database role named payment_entry in AP schema. This new
role should SELECT and UPDATE privileges for the vendors table; SELECT & UPDATE
privileges for the invoices table; and SELECT, UPDATE & INSERT privileges for the
invoice_line_items table. This role should also have the right to create a session
2. Create a new user named TOM with a password of “temp” and assign the payment_entry
role to him. Create a new connection in SQL developer with user name TOM. Write a SELECT
statement to select all of the columns for all of the rows in the vendors table, and use the
TOM connection to run it. Finally write the delete statement that attempts to delete one of
the rows in the vendors table, and use the TOM connection to run it.
3. Revoke UPDATE privilege from the “payment_entry” role

c) Using SET operators, date – time functions, roll up, cube and grouping sets
1. Use UNION operator to generate a result set consisting of two columns from the
vendors table: vendor_name & vendor_state. If the vendor is in California the
vendor_state value should be “CA”; otherwise the vendor_state value should be
“outside CA”. Sort the final result set by vendor_ name.
2. Write a SELECT statement that returns these columns from the invoices table:
The invoice_date column
• Use the TO_CHAR function to return the invoice_date column with its full date
and time including a four digit year on a 24 – hr clock.
• Use the TO_CHAR function to return the invoice_date column with its full date
and time including a four digit year on a 12-hr clock with an am/pm indicator.
3. Write a SELECT statement that returns these columns from the invoices table:
• The invoice_number column
• The invoice_date column
• The invoice_date column plus 30 days
• The payment_date column
• A column named days_to_pay that shows the number of days between
invoice_date and the payment_date
• The number of the invoice_date’s month
• The four digit year of the invoice_date
• The last day of the invoice date’s month.
When you have this working, add a WHERE clause that retrieves just the invoices for the
month of May based on the invoice_date, not the number of invoice month.
4. What is total amount invoiced for each general ledger account number? Use ROLLOUP
operator to include a row that gives the grand total. Hint: use the line_item_amt
column of the Invoice_Line_Items table. (also observe the difference when we use CUBE
operator)

Potrebbero piacerti anche