Uploaded by Mkhuleko Thabiso Nhlambo

DSO23ATST2 SOSH Memo

advertisement
FACULTY of INFORMATION and
COMMUNICATIONS TECHNOLOGY
DEPARTMENT of COMPUTER SCIENCE
SEMESTER TEST 2 – Memorandum
Subject Code : DSO23AT/ISY23AB/SFW20AT
Subject Name: Development Software 2a/Information Systems 2a/Software Skills 2a
Examiner
: Dr HJG OBERHOLZER
Moderator
: Mr K MOGAPI
Marks
: 75
Time: 3 Hours
Total Pages (Including this one) : 7
Date: May 2019
Rules
1.
2.
3.
4.
5.
6.
Do not tear any page from this test paper. Read and understand the question
before you answer. Answer all the questions.
Your answers must produce the exact same output as the ones the examiner(s) has
given as examples.
Complete the information on this cover page before you start answering questions.
The question paper is based on the S_STUDENT database. Install the database
on your computer if it is not installed.
You will receive a folder with an empty notepad inside it. Complete required details
on the top of the notepad and save it as Oracle_ST2_2019 and rename the folder
to your student number.
It’s your responsibility to make it a point that you follow the rules. Empty notepad
means 0% mark.
Student No
:
Surname and
Initials :
Lab :
Question
s
Marks
Computer # :
Quest 1
Quest 2
Quest 3
Quest 4
Total
16
9
17
33
75
Allocatio
n
%
Question 1
[16]
List for every subject the name of the subject, how many students registered for that
subject, the total fee owed by all the students that registered for the subject and the
name of the faculty that offers the subject. List only the subjects where more than one
student registered for that subject and where the total subject fee is more than R1500.
Sort your results as listed below.
SUBJECTS offered
---------------------------------------------------------------------------Financial Skills 1 has 2 registered students for a total fee of R2,000.00
that is offered by the faculty of FACULTY OF INFORMATION SCIENCES
Information Systems 1 has 2 registered students for a total fee of R2,400.00
that is offered by the faculty of FACULTY OF INFORMATION SCIENCES
Quantitative Techniques 1 has 2 registered students for a total fee of
R2,600.00 that is offered by the faculty of FACULTY OF INFORMATION SCIENCES
Systems Programming 1 has 2 registered students for a total fee of R2,800.00
that is offered by the faculty of FACULTY OF INFORMATION SCIENCES
4 rows returned
SELECT INITCAP(subj_name)
 || ’ has ’ ||
COUNT(R.subj_code)  || ’ registered students for a total fee of ’ ||
TO_CHAR(SUM(subj_fee), ’FML9,999.00’)  || ’ that is offered by the faculty of’
|| fac_name ”SUBJECTS offered”
½ -- plus  for the rest
FROM s_subject S, s_diploma D, s_faculty F, s_registration R 
WHERE F.fac_code=D.fac_code

AND D.dip_code=S.dip_code

AND S.subj_code=R.subj_code

GROUP BY subj_name, fac_name

HAVING COUNT(R.subj_code) > 1

AND SUM(subj_fee) > 1500
½
ORDER BY subj_name, fac_name;

Question 2
[9]
List the first initial, surname and date of birth of all students that celebrate their birthdays
in the same month(s) as those students whose surnames start with either an “M” or a
“P”. You are not allowed to hard code any dates of birth or surnames (or part of
surnames) that do not start with an M or a P. Sort your results as listed below.
STUDENTS
-------------------G MKASI
C BARNARD
H SMITH
T SMITH
W MASHILE
W PETOORS
V SMITH
7 rows selected.
Date of Birth
------------21 May
21 May
21 November
21 November
21 November
3 December
3 December
SELECT SUBSTR(initials,1,1)  || ’ ’ || surname students, ½
TO_CHAR(birthdate,’FMdd Month’)  ”Date of Birth” ½
FROM s_student
½
WHERE TO_CHAR(birthdate, ’Month’)  IN 
(
SELECT TO_CHAR(birthdate, ’Month’) 
FROM s_student ½
WHERE SUBSTR(surname,1,1) IN (’M’, ’P’) ); 
Question 3
[17]
Create a report to display for all staff jobs that start with an “L” the job, surname and
initials of the staff member, monthly salary, monthly bonus and total income. The total
income is defined as the sum of the monthly salary and monthly bonus (assume that
the database stores the annual values). If the staff member does not have a bonus
then Oracle must request the percentage that has to be entered by you during runtime
as a substitution variable. You have to take this percentage of his/her salary then as
his/her bonus. See the output listed below. You are not allowed to use SUBSTR or
specify any jobs. Do not confirm the increase after it has been entered.
Leave two blank lines after every job. Your report must resemble the output listed
below except for the report date that will be today’s date.
The report format must be as follows:







Page length - 28 lines
Page width - 75 characters
The job and staff names must respectively be 10 and 20 characters wide
You are not allowed to format the salaries, bonuses or incomes as part of the query
itself
Sort in ascending sequence of job and staff names
Clear all formats, titles, columns, and other report settings at the end of the report
Marks will be subtracted for unnecessary clearing of settings or unnecessary settings
set
Enter value for percentage_bonus: 12.5
Wed May 15
page
1
Total Monthly STAFF Income Report
Monthly
Monthly
Job
Staff member
Salary
Bonus
TOTAL Income
---------- -------------------- ---------- ---------- --------------------LECTURER
COETZEE, HHH
06,066.67 00,100.00
R072,900.00
ERASMUS, HG
07,500.00 00,052.00
R090,052.00
HONEYBALL, PA
MORGAN, I
06,000.00 00,750.00
R072,750.00
NKOSI, HJ
11,000.00 01,375.00
R133,375.00
NKOSI, RN
06,066.67 00,100.00
R072,900.00
OLIVIER, G
06,500.00 00,812.50
R078,812.50
PRETORIUS, BB
07,500.00 00,500.00
R090,500.00
PRETORIUS, CM
09,000.00 01,050.00
R109,050.00
RICHMOND, M
04,500.00 00,050.00
R054,050.00
VAN DER MERWE, KOOS
11,000.00 01,000.00
R133,000.00
VENTER, PJ
07,000.00 00,875.00
R084,875.00
LIBRARIAN
BARENDSEN, PP
DE WET, MA
DE WET, PA
READY, B
=
02,500.00
03,000.00
03,000.00
02,000.00
=
=
End of Page
TTI 'Total Monthly STAFF Income Report' ½
BTI '= = = End of Page = = ='
SET PAGESIZE 28
SET LINES 75
SET VERIFY OFF
00,312.50
00,375.00
00,375.00
00,100.00
=
=
=
½
½
½
½
COLUMN A HEADING 'Job'
COLUMN B HEADING 'Staff member'
COLUMN C HEADING 'Monthly|Salary'
COLUMN D HEADING 'Monthly|Bonus'
COLUMN E HEADING 'TOTAL Income'
FORMAT A10
½
FORMAT A20
½
FORMAT 09,999.99
FORMAT 09,999.00
FORMAT L099,999.00

BREAK ON A SKIP 2
SELECT job A, surname || ’, ’ || initials B, salary/12 C,

NVL(bonus, salary * &Percentage_Bonus / 100) / 12 D,

salary + NVL(bonus, salary * &Percentage_Bonus / 100) / 12 E
FROM s_staff
½
WHERE job LIKE ’L%’ 
ORDER BY a, b;

TTITLE OFF
BTI OFF
CLEAR COLUMN
SET VERIFY ON
CLEAR BREAK
R030,312.50
R036,375.00
R036,375.00
R024,100.00
½
½
½
½
½




Question 4
[33]
4.1 Write two SQL statements to create the two Oracle database tables as defined
below.
(6½)
OL_ATHLETE
Column name
AthleteCode
AthleteName
BirthDate
Height
Data type
Fixed character length of six characters of which the
first three characters represent the country of the
athlete and the next three his/her paticipation number
Variable length character string of up to fifteen
characters
Date
Numeric representing the format 9.99 Only heights of
up to 2.99 meters not more.
CREATE TABLE ol_athlete
(
athleteCode
athleteName
birthdate
height

CHAR(6),
½
VARCHAR2(15), ½
DATE,
½
NUMBER(3,2));

OL_ITEM
Column name
ItemType
ItemDesc
PriceMoney
CREATE TABLE ol_item 
(
itemType
itemDesc
priceMoney
Data type
Must be able to store the values of “F” or “T”
Variable character length of twenty five
characters
The price money is stored as a local currency.
Must allow for prices up to $9,999.99 or
R9,999.99 only depending on the country.
CHAR,
VARCHAR2(25),
NUMBER (6,2));
½
½

4.2 Write one SQL statement to add the following data to table OL_ATHLETE. Name
the columns for which you add the data. The date of birth is currently not known.
You are not allowed to use substitution variables.
(3)
AthleteCod
e
JAM101
AthleteNam
e
Usain Bolt
Birthdate
Height
1.93m
INSERT INTO ol_athlete  (athleteCode, AthleteName, Height) VALUES ½
(’JAM101’ , ’Usain Bolt’ , 1.93);
½½½
4.3 Write one SQL statement to change the length of the item description to be able
to store descriptions up to a length of 20 characters.
(2½)
ALTER TABLE ol_item
MODIFY itemDesc VARCHAR2(20);

½
4.4 Write one SQL statement to add one more column named gender to table
OL_ATHLETE. This column must allow the athlete’s gender automatically to be
added as “M” to a new row of data when the gender is not specified.
(3)
ALTER TABLE ol_athlete
ADD gender CHAR
DEFAULT ’M’;



4.5 Write one SQL statement to add the following data to table OL_ATHLETE. You
are not allowed to specify the columns for which you add the data. The height
and gender are not known and the gender must get its value automatically. The
date of birth must be specified as given. You are not allowed to use substitution
variables.
(3½)
AthleteCode
RSA800
AthleteName
Caster
Semenya
Birthdate
17 MARCH 1992
Height
Gender
Automatic
INSERT INTO ol_athlete VALUES
½
(’RSA800’, ’Caster Semenya’,
½½
TO_DATE(’17 MARCH 1992’, ’DD MONTH YYYY’), ½ NULL, DEFAULT);
½½
4.6 Write one SQL statement to add the following data to table OL_ITEM. You are
not allowed to specify the columns for which you add the data. You are not
allowed to use substitution variables.
(2)
Long Jump is field item (F) with a price money of $7,500.00 or R7,500.00
depending on the country.
INSERT INTO ol_item VALUES ½
(’F’, ’Long Jump’, 7500);
½½½
-- do not specify $ or , or . or R
4.7 Write one SQL statement to make all your changes until this point permanent. (1)
COMMIT;

4.8 Write one SQL statement to add the height of athlete RSA800 as 1.78m.
UPDATE ol_athlete
SET height = 1.78

WHERE athleteCode=’RSA800’;

(3)
-- not athleteName=’Caster Semenya’
4.9 Write one SQL statement to add the comment “Caster Semenya is the 800m
WORLD CHAMPION” to column athleteCode.
(2½)
COMMENT ON COLUMN  ol_athlete.athleteCode IS
’Caster Semenya is the 800m WORLD CHAMPION’;
½½
½
4.10 Write one SQL statement to undo all the previous statements until the last
statement that made your changes permanent.
(1)
ROLLBACK;

4.11 Write one SQL statement to remove the last row you added to the database in
question 4.6 Assume there are more than 100 rows in the table.
(2)
DELETE FROM ol_item

WHERE itemDesc=’Long Jump’;  -- only correct answer
4.12 Write one SQL statement to remove table OL_ITEM from the database, but keep
the structure.
(1)
TRUNCATE TABLE ol_item;

4.13 Write one SQL statement to query the appropriate data dictionary to check
whether your table OL_ITEM still exists in the data dictionary.
(2)
SELECT table_name
FROM user_tables
WHERE table_name=’OL_ITEM’;
½
½

-- ol_item must be in capital letters
End of Paper
Download