INF3707 TUT202 2018 Assignmnet02Solution Semester02
INF3707 TUT202 2018 Assignmnet02Solution Semester02
School of Computing
BARCODE
Assignment 2 Total marks Due date
50
Note that this is a COMPULSORY assignment!
To do this assignment, you need access to the JustLee books database
Question 1: Chapter 6
Give SQL statements for the following requests.
1.1 Create a sequence that generates integers starting with the value 5. Each value should be
three less than the previous value generated. The lowest value should be 0, and the sequence
should not be allowed to cycle. Name the sequence MY_FIRST_SEQ. (5 marks)
Answer
1.2 Issue a SELECT statement that displays NEXTVAL for MY_FIRST_SEQ three times. Since
the value is not being stored in the table, use dual table in the FROM clause of the SELECT
statement. What caused the error on the third SELECT? (5 marks)
Answer
SELECT my_first_seq.NEXTVAL
FROM DUAL;
Students should explain this error. If they copy and paste the error
from Oracle IDE, no marks
Question 2: Chapter 7
Create and execute statements to perform the following actions, using the JustLee Books
database:
2.1 Create a new user account. The account name should be a combination of your first initial
and last name. (1 marks)
Answer
CREATE USER finitiallastname
IDENTIFIED BY apassword;
2
INF3707
2.2 Attempt to log in to Oracle with the newly created account. What happened? (1 marks)
Answer
Connection will fail because the CREATE SESSION privilege is required.
2.3 Assign privileges to the new account that allow connecting to the database, creating new
tables and altering existing tables. (3 marks)
Answer
GRANT CREATE SESSION, CREATE TABLE, ALTER ANY TABLE
TO finitiallastname;
2.4 Create a role named CUSTOMERREP that allows inserting new rows in the ORDERS and
ORDERITEMS tables and deleting rows from these tables. (5 marks)
Answer
CREATE ROLE customerrep;
Question 3: Chapter 9
Give SQL statements for the following requests.
3.1 Determine which books customer Jake Lucas purchased. Perform the search using the
customer name, not the customer number. If he has purchased multiple copies of the same
book, induplicate the results. Generate the report using the JOIN keyword. (5 marks)
3.2 Which books where written by an author whose last name is Adams? Perform the search
using the author name. Generate the report using the JOIN keyword. (5 marks)
SELECT b.title
FROM books b JOIN bookauthor USING (isbn)
JOIN author a USING (authorid)
WHERE a.lname = 'ADAMS';
3
Question 4: Chapter 10
To perform this activity, refer to the tables of the JustLee Books database.
Management is proposing to increase the price of each book. The amount of the increase on
each book’s category is according to the following scale:
Computer books, 10%
Fitness books, 15%
Self-Help books, 25%
All other categories, 3%.
Create a query that displays each book’s title, category, current retail price, and revised retail
price. The format the prices to two decimal places. The column headings for the output should
be as follows: Title, category, Current Price and Revised Price. Sort the results by category. If
there is more than one book in category, perform a secondary sort on the book’s title. (10
marks)
Answer
SELECT title "Title", category "Category", retail "Current Price",
Round(decode(category,
'COMPUTER',retail*1.1,'FITNESS',retail*1.15,'SELF HELP',retail*1.25,
retail*1.03), 2) "Revised price"
FROM books
order by category, title;
or
Question 5: Chapter 11
Give SQL statements for the following requests.
Determine, which orders, had a higher total amount due than order 1008. Use subqueries to
answer the question (10 marks)
4
INF3707
Or