Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

62868446

Question 1
1.1
(i)there is a space between the data type of the stock_no# and the length of said data type and
the data type is not in lower case
(ii) my correction is change “stock_no# NUMBER (4) NOT NULL” to “(stock_no# number(4)
NOT NULL,
1.2
INSERT INTO mycustomer01(Customer#, First_name , Last_name)
Values (1000, ‘Jan’,’Zwane’)
1.3
GRANT select TO * WITH GRANT OPTIONS
FOR mycustomer01
1.4
SELECT to_char(2090.55,’9,999.99’) AS Value FROM mycustomer01
1.5
Display the isbn and title off books whose pubid and category match the pubid and category of
books containing the string oracle in it.
1.6
SELECT phone.SUBSTR(9,4) as phone
FROM publisher
WHERE name = ‘ Publish Our Way’
1.7
----

1.8
Alter table MyCustomers02
ADD CONSTRAINT lastname_nonull NOT NULL (Lastname)
1.9
(i)’rr’ is not a valid parameter for date format using to char and by is in lowercase
(ii)SELECT orderdate ,sum(shipcost)
FROM orders
GROUP BY to_char(orderdate,'YY');
1.10
SELECT COUNT(Referred)
FROM Customers
WHERE Referred <> NULL

1
62868446

Question 2
2.1
CREATE TABLE MyCustomers03 (
myCUSTOMER# number(4),
myLASTNAME varchar2(10) NOT NULL,
myFIRSTNAME varchar2(10) NOT NULL,
myADDRESS varchar2(20),
myCITY varchar2(2),
myZIP varchar2(5),
CONSTRAINT mycustomers03_pky PRIMARY KEY (myCUSTOMER#)
)

2.2
Alter table MyCustomers02
ADD CONSTRAINT mycustomers03_pky PRIMARY KEY (myCUSTOMER#) ;
2.3
INSERT INTO MyCustomer03(Customer#, myLASTNAME, myFIRSTNAME, myADDRESS,
myCITY,myZIP)
FROM customers
Values (b.Customer#, lastname, firstname, address, city, zip)

2.4
Alter table MyCustomers02
ADD email varchar2(60)
ADD province varchar2(15)
2.5
CREATE INDEX my_customers_state_idx

SELECT table_names, index_names, Index_type


FROM user_indexes
WHERE table_names = ‘ MyCustomers03’

DESC my_customers_state_idx

DROP my_customers_state_idx
2.6
----

End of page

2
62868446

Question 3
3.1
SELECT a.customer#, a.lastname, b.city
FROM customers b
JOIN customers a ON a.city = b.city
WHERE b.city <> UNIQUE

3.2
SELECT Customer#, Zip. SUBSTR(3,2) AS Zipdigits, Zip.INSTR(3) AS Position
FROM customers

Question 4

4.1
SELECT AVG(retail), name, category
JOIN publisher USING pubid
WHERE ((category=’Children’) OR (category=’Computer’)) AND average > 50
GROUP BY publisher name, category

4.2
SELECT title, MIN(retail)
FROM books
JOIN bookauthor ba USING isbn
JOIN Author a ON ba.authorid = a.authorID
WHERE ((fname = ‘Sam’ )AND (name = ‘Smith’))

4.3
SELECT title,retail
FROM customers
WHERE title in( SELECT title FROM customers WHERE (retail > AVG(retail)))

You might also like