Ora PL-SQL 2
Ora PL-SQL 2
Ora PL-SQL 2
1.
The worker table has 11 columns. You often query the table with conditions based on four or more
columns. You create an index on all columns in the table. What will result?
a.
b.
c.
d.
2.
First
Second
Third
Fourth
Fifth
Sixth
Seventh
3.
You must store currency data. All data will have two digits to the fight of the decimal point (ie,
25.xx). The numbers to the left of the decimal point will vary. Which data type is most appropriate?
a.
b.
c.
d.
NUMBER
NUMBER(T)
LANG
LANGRA
4.
NAME
WORKER ID
NAME
PHONE
ADDRESS
POSITION
NULL
NOT NULL
NOT NULL
NOT NULL
TYPE
NUMBER(3)
VARCHAR2(25)
VARCHAR2(9)
VARCHAR2(50)
UPDATE
There are hundreds of records in the EMPLOYEE TABLE. You need to modify the phone column to hold
only number values. Which statement will modify the data type appropriately?
a.
b.
c.
d. The data type of a column cannot be modified if there is data in the column.
5.
a.
b.
c.
d.
6.
BEGIN
FOR worker_record IN pay_cursor LOOP
Worker_id_table(worker_id):=
Worker_record.last_name;
END LOOP;
CLOSE salary_cursor;
END;
Why does this section cause an error?
a.
b.
c.
d.
7.
Your company will be granting workers a $150 salary increase. You need to evaluate results of the
increase from the worker table prior to the actual modification. You do not want to store in the results
in the current database. Which of the following is untrue?
a.
b.
c.
d.
8.
What command should be used to execute a script file named QUERYCOLOR.SQL from the SQL
Plus environment?
a.
b.
c.
d.
START QUERYCOLOR
EXECUTE QUERYCOLOR
RUN QUERYCOLOR
GET QUERYCOLOR
9.
You need to test if the current fetch within a PL/SQL loop was successful. Which cursor attribute is
needed to accomplish this task?
a.
b.
c.
d.
SQL%ISOPEN
SQLROWCOUNT
SQL%FOUND
A cursor attribute cannot be used within a PL/SQL loop.
10. You have been assigned the task of updating worker salaries. If a salary is less than 1000, it must be
incremented by 10%. The SQL Plus substitution variable will be used to accept a worker number.
Which PL/SQL block successfully updates salaries?
a.
DECLARE
V_sal worker.sal%type;
BEGIN
SELECT sal
INTO v_sal
FROM worker
WHERE workerno=&&p_workerno;
IF v_sal<1000 then
UPDATE worker
INTO sal:=sal*1.1
WHERE workerno=&p_workerno;
END IF;
END;
b.
DECLARE
V_sal worker.sal%type;
BEGIN
SELECT sal
INTO v_sal
FROM worker
WHERE worker=&&p_wokerno;
IF v_sal<1000 then sal:=sal*1. 1
END IF;
END;
c.
DECLARE
V_sal worker.sal%type;
BEGIN
SELECT sal
INTO v_sal
FROM worker
WHERE workerno=&&p_workerno;
IF v_sal<1000 then
UPDATE emp
sal:=sal*1.1
WHERE workerno=&p_workerno;
END IF;
END;
d. DECLARE
V_sal worker.sal%type;
BEGIN
SELECT sal
INTO v_sal
FROM worker
WHERE workerno=&&p_workerno;
IF v_sal<1000 then
UPDATE worker
SET sal:=sal*1.1
WHERE workerno=&p_workerno;
END IF;
END;
11. Examine the following:
SET SERVER OUTPUT ON
X NUMBER;
V_sal NUMBER;
VARCHAR2(25)
VARCHAR2(25)
13. In the declarative section of a PL/SQL block, you create-but do not initialize-a number variable.
When the block executes, what will be the initial value of the variable?
a.
b.
c.
d.
0
Null
The value will depend on the scale and precision of the variable.
The block will not execute because the variable was not initialized.
16. You are a user of the PROD database, which has over 1200 tables. What data dictionary view must
you query to determine the number of tables you can access?
a.
b.
c.
d.
ALL_OBJECTS
DBA_TABLES
DBA_SEGMENTS
USER_OBJECTS
DISTINCT object-type
user-objects;
SELECT
ROM
object-type
all-objects;
The first statement will display the distinct object types in the database; the second statement will
display the object types in the database.
The first statement will display the distinct object types owned by the users; the second statement will
display all object types in the database.
The first statement will display distinct object types owned by the user; the second statement
will display all the object types that the user can access.
The first statement will display the distinct object types that the user can access; the second statement
will display all the object types that the user owns.
a.
b.
c.
d.
0
1
2
3
20. Mike forgot his password. Which of the following commands will set a password for user, mike?
a.
b.
c.
d.
LATER USER mike PASSWORD BY green. The command must be issued by Mike.
ALTER USER mike IDENTIFIED BY green. The command must be issued by the DBA.
ALTER USER mike IDENTIFIED BY green. The command must be issued by Mike.
CHANGE password to green WHERE user=mike; The command must be issued by the DBA.
21. You are updating the worker table. Jane has been granted the same privileges as you. You ask her to
check your work before you issue a COMMIT command. What can she do on the workers table?
a.
b.
c.
d.
Null?
Type
PUPIL-ID
NAME
ADDRESS
GRADUATION
NOT NULL
NOT NULL
NUMBER(3)
VARCHAR2(25)
VARCHAR2(50)
DATE
Which of these statements inserts a new row into the PUPIL table?
a.
b.
c.
d.
NULL
NOT NULL
NOT NULL
TYPE
NUMBER(3)
VARCHAR2(25)
VARCHAR2(50)
DATE
The GRADUATION column is a foreign key column to the table. Examine the data in the GRADE DATA
table:
Graduation
11-May-2001
13-Jan-2001
19-Dec-2001
25-Jun-2000
Which of the following statements will produce the error.ORA-02291 integrity constraint (sys_c23)
violated. Parent key not found.?
a.
b.
c.
d.
UPDATE pupil
SET pupil-id=999
Graduation=11-MAY-2001
WHERE stud-id=101;
UPDATE pupil
SET name=Benson,
Graduation=11-MAY-2001
WHERE pupil-id=101;
UPDATE pupil
SET name=Benson,
Graduation=15-AUG-200
WHERE pupil-id=101*
UPDATE pupil
SET stud-id=NULL,
Address=50 NE Oak St
WHERE graduation=18-APR-2001
25. The view WORKER-VIEW is created based on the WORKER table as follows:
CREATE OF REPLACE VIEW worker-view
AS
SELECT deptno,Sum(sal)TOT-SAL,COUNT(+)NOT-WORKER
FROM worker
GROUP BY deptno;
What happens when the following command is issued?
UPDATE worker-view
SET lot-sal=25000
WHERE deptno=8;
a.
b.
c.
d.
26. You view a card, ANN_SAL, that is based on the worker table. The structure of the ANN_SAL view
is:
NAME
WORKERNO
YEARLY_SAL
MONTHLY_SAL
NULL
NOT NULL
TYPE
NUMBER(4)
NUMBER(9,2)
NUMBER(9,2)
250
500
750
1000
NUMBER(9)
VARCHAR(2)
NUMBER(9)
p.name,c.name
participant p,participant c
c-id= c.coach-id;
SELECT
FROM
p.name,c.name
participant p,player c
WHERE
c.coach-id=p.id;
The first statement will not execute; the second statement will.
The first statement will execute; the second statement will not execute.
The first statement is a self join; the second statement is not.
The results will be the same, but will be displayed differently.
29. How would you declare a PL/SQL table of records to hold the rows selected from the WORKER table?
a.
DECLARE
worker-table is TABLE OF worker%ROWTYPE
b. BEGIN
TYPE worker-table is TABLE of worker%ROWTYPE
worker-table worker-table-type;
c. DECLARE
TYPE worker-table is TABLE of worker%ROWTYPE
INDEX BY WHOLE NUMBER:
worker-table worker-table-type;
d. DECLARE
TYPE worker-table is TABLE of worker%ROWTYPE
INDEX BY BINARY INTEGER.
worker-table worker-table-type;
30. Which type of cursor should be created when you want to create a cursor that can be used several
times in a block, selecting a different active set each time it is opened?
a.
b.
c.
d.
A loop cursor.
A multiple selection cursor.
A cursor for each active set.
A cursor that uses parameters.
31. Which of the following is true when writing a cursor for loop?
a.
b.
c.
d.
You must explicitly fetch the rows within a cursor for loop.
You must explicitly open the cursor prior to the cursor for loop.
You must explicitly close the cursor prior to the end of the program.
You do not explicitly open, fetch, or close a cursor within a cursor for loop.
Null?
Not NULL
Type
Number(25)
VARCHAR2(14)
VARCHAR2(13)
DBMS-OUTPUT.PUT_LINE(house-rec):
DBMS.OUTPUT.PUT_LINE(house-rec-loc);
DBMS.OUTPUT.PUT_LINE(house-rec(1).loc);
You cant display a single file in the record because they are not specially identified in the declarative
section.
NUMBER(2);
worker
division-id
IN(10,20,30);
SQL/ROWCOUNT;
0
1
True
Null
35. Which two conditions in a PL/SQL block cause an exception error to occur?
a.
b.
c.
d.
36. You must create a program to insert records into the worker table. Which of the following
successfully uses the INSERT command?
a.
b.
c.
DECLARE
v-hiredate DATE:=SYSDATE:
BEGIN
INSERT INTO worker(workernp, wname, hiredate, divisionno)
VALUES(workerno-sequence.nextval, and name, v_hiredate and divisionno)
DECLARE
v-hiredate DATE:=SYSDATE:
BEGIN
INSERT INTO worker(workernp, wname, hiredate, divisionno)
DECLARE
v-hiredate DATE:=SYSDATE:
BEGIN
INSERT INTO worker(workernp, wname, hiredate)
VALUES(workerno-sequence.nextval, and name, v_hiredate and divisionno)
d.
END:
DECLARE
v-hiredate DATE:=SYSDATE:
BEGIN
INSERT INTO worker(wordernp, wname, v_hiredate and divisionno)
Job=Clerk
END:
(I);
0
4
6
8
12
Heading
Executable
Declarative
Exception handling
welcome.sql
RUN welcome.sql
START welcome.sql
EXECUTE welcome.sql
45. Which of the following statements is valid within the executable section of a PL/SQL block?
a.
b.
c.
d.
BEGIN
Worker_rec worker%ROWtype
END;
WHEN NO_DATA FOUND THEN
DBMS_OUTPUT PUT.LIN(Nothing found);
SELECT wname,sal
INTO w_ename,w_sal
FROM worker
WHERE
workno=106;
Procedure cal_max(n1 NUMBER n2 NUMBER, p_max OUT NUMBER)
IS
BEGIN
If n1>n2 then
p_max:=n1;
Else
p_max=n2;
END.
46. What command will send the output of an SQL* Plus session to a text file named LOG.LST?
a.
b.
c.
d.
SAVE LOG.LST
SPOOL LOG.LST
PRINT LOG.LST
SEND LOG.LST
NUMBER(9)
NUMBER(7,2)
NUMBER(7,2)
PK
Your supervisor asks you to calculate net revenue per unit for each product if the cost of each product is
increased 10% and the sale price of each product is increased 25%. You issue the following:
SELECT code, sale_price * 1.25 - cost * 1.10
FROM merchandise;
What conclusion can be drawn from the results?
a.
b.
c.
d.
48. You have been instructed to create a report that shows different jobs in each division within your
company. No duplicate roles can be displayed. Which of the following SELECT statements should be
used?
a.
b.
c.
d.
49. Which of the following SELECT statements displays worker names, salary, division numbers, and
average salaries for all workers who earn more than the average salary in their department?
a.
PK
VARCHAR2(25) NN
NUMBER(9)
DESCRIBE
UPDATE
CHANGE
ACCEPT
ID
LAST_NAME
FIRST_NAME
COMMISSION
NUMBER(9)
VARCHAR2(25)
VARCHAR2(25)
NUMBER(7,2)
You must display commission calculations for employees, and are given the following guidelines:
3
2
1
The statement generates an error.
59. Click EXHIBIT and examine the trace instance chart for the worker table (exhibit not available).
What SQL statement must be used to display each worker hire date from earliest to last?
a.
SELECT
FROM
b. SELECT
FROM
ORDER BY
c. SELECT
FROM
ORDER BY
d. SELECT
FROM
ORDER BY
hire_date
worker;
hire_date
worker
hire_date;
worker
worker
hire_date;
hire_date
worker
hire_date DESC;
Null
NOT NULL
Type
NUMBER(2)
VARCHAR2(14)
VARCHAR2(13)
division_table.loc.13
division_table[13].loc
:=
:=
Boston;
Boston;
c.
d.
division_table(13).loc
division_table_type(13).loc
:=
:=
Boston;
Boston;
61. You need to change the job title Secretary to Administrative Assistant for all secretaries. Which
of the following statements accomplishes this?
a.
b.
c.
d.
UPDATE worker
UPDATE worker
Job :=
Administrative Assistant
WHERE UPPER(job) = Secretary
UPDATE worker
SET job = Administrative Assistant
WHERE UPPER(job) = Secretary;
UPDATE worker
SET values job = Administrative Assistant
WHERE UPPER(job) = Secretary;
62. You must remove all data from the color table while leaving the table definition intact. What
command should you issue, if you must be able to undo the operation?
a.
b.
c.
d.
Heading.
Execution.
Declarative.
Exception handling.
DECLARE
i NUMBER := 0;
x_date DATE ;
BEGIN
i := i + 1;
LOOP
i := v_date + 5;
i := i + 1;
EXIT WHEN i = 5;
END LOOP;
END
You encounter unexpected results while executing the above code. How can you trace the values of
counter variable 1 and date variable x_date in an SQL* PLUS environment?
a.
b.
v_num
NUMBER;
v_name
NUMBER;
IF (v_sal.GT.10000) THEN
--- This code displays salaries if larger than 10,000.
last_name, first_name
worker
SALARY_IN
(SELECT salary)
FROM worker
WHERE division_no=3 OR division_no=5);
68. Which operator is not appropriate in the joined condition of a non-equijoin select statement?
a.
b.
In operators.
Like operators
c.
d.
Equal operators.
Greater than and equal to operators.
69. You must permanently remove all data from the INVOICE table, but will need the table structure in
the future. What single command should be issued?
a. DROP TABLE invoice
b. TRUNCATE TABLE invoice
c. DELETE
FROM invoice
d. TRNCATE TABLE invoice
KEEP STRUCTURE;
LONG
NUMBER
NUMBER(p,s)
INTEGER
Null
NOT NULL
NOT NULL
Type
NUMBER(3)
VARCHAR2(25)
VARCHAR2(50)
DATE
What statement will add a new column after the NAME column to hold phone numbers?
a.
b.
c.
09-dec-99 + 6
09-dec-99 - 12
09-dec-99 + (12/24)
09-dec-99 - 10-dec-99
(09-dec-99 - 10-dec-99) /6
(09-dec-99 - 10-dec-99) /12
75. Which statement should be used to add and immediately enable a primary key constraint to the
customer table using the id-number column?
a. This cannot be done.
b. ALTER TABLE customer
ADD CONSTRAINT cus-id-pk PRIMARY key(id-number);
c. ALTER TABLE customer
ADD (id-number CONSTRAINT cus-id-pk PRIMARY KEY);
d. ALTER TABLE customer
MODIFY(id-number CONSTRAINT cus-id-pk PRIMARY KEY);
76. Which of the following SELECT statements will query the worker table and retrieve the last name
and salary of the employee whose idea is 5?
a.
b.
c.
d.
SELECT last-name,salary
FROM worker;
SELECT last-name,salary
FROM worker;
WHERE id=5;
SELECT last-name,salary
INTO v-last-name,v-salary
WHERE id=5;
SELECT last-name,salary
FROM worker;
INTO v-last-name,v-salary
WHERE id=5;
Null?
Not NULL
Type
Number(20)
VARCHAR2(12)
VARCHAR2(13)
SELECT*
INTO division-rec
FROM division
b.
c.
d.
b.
c.
DECLARE
CURSOR work-cursor 1S
SELECT wname,divisionno
FROM work;
BEGIN
FOR work-rec IN work-cursor LOOP
INSERT INTO temp-work(name,dno)
VALUES (work-rec.wname,
work-re.divisionno);
END LOOP
END;
DECLARE
CURSOR work-cursor 1S
SELECT wname,divisionno
FROM work;
BEGIN
FOR work-rec IN work-cursor LOOP
OPEN work-cursor;
INSERT INTO temp-work(name,dno)
VALUES (work-rec.wname,
work-re.divisionno);
END LOOP
END;
DECLARE
CURSOR work-cursor 1S
SELECT wname,divsisionno
d.
FROM work;
BEGIN
FOR work-rec IN work-cursor LOOP
OPEN work-cursor;
INSERT INTO temp-work(name,dno)
VALUES (work-rec.wname,
work-re.divisionno);
END LOOP
CLOSE work-cursor;
END;
The above code cannot be simulated with a LOOP.
81. Using SQL Plus, you create a user with the following command:
CREATE USER Joshua IDENTIFIED BY jyd205
What must you do to allow Joshua database access?
a.
b.
c.
d.
Use the ALTER USER command to assign default table space to Joshua.
Grant Joshua the CREATE SESSION privilege.
Use the ALTER USER command to assign Joshua a default profile.
Database access is granted by default.
82. A DBA has added privileges to Randalls account to create tables and procedures on a database.
Which of the following can Randall perform?
a.
b.
c.
d.
He can create tables, drop tables, and create procedures in any schema of the database.
He can create any table or procedure in his schemas only. He can drop any table from his schema
only.
He can create a table in any schema of the database but can drop tables from and create
procedures only within his own schemas.
He can create a table or procedure in any schema of a database and can also drop tables in any
schema of the database.
a.
b.
c.
d.
MY_VIEWS
USER_VIEWS
SYSTEM_VIEWS
USER_TAB_VIEWS
84. You create the worker table using the following command:
CREATE VIEW division-salary-vu
AS SELECT division-no,salary,last-name
FROM worker
WHERE salary>45000
WITH CHECK OPTION;
Click on the EXHIBIT button and examine the worker table (exhibit not available). For which employee
can you update the dept no column using this view?
a.
b.
c.
d.
Brown
South
Chizza
None
85. Click on the exhibit button and examine the table instance chart of the patient table
Column name
Key type
Nulls/Unique
FK table
FK column
Data type
Length
Id_number
PK
NN, UU
ID_NUMBER
NUM
10
last_name
first_name
NN
NN
VARCHAR2
25
VARCHAR2
25
birth_date
physician_id
PHYSICIAN
DATE
NUM
10
You create the patient_vu view based on the id number and last name columns from the patient table.
How should you modify the view to contain only patients born in 1998?
a.
b.
c.
d.
86. Which of the following statements regarding the use of a sub query in the FROM clause is true?
a.
b.
c.
d.
Id_number
PK
NN, UU
ID_NUMBER
NUM
10
last_name
first_name
NN
NN
VARCHAR2
25
VARCHAR2
25
birth_date
physician_id
PHYSICIAN
DATE
NUM
10
You create the patient_id_seq sequence to be used with the patient tables primary key column. The
sequence begins at 1000 and has a maximum value of 99999999 and increments by 1. You must write a
script to insert a row into the patient table and use the sequence you created. Which script should be
used?
a.
b.
ID_NO
PK
NN, UU
NAME
NUM
9
VARCHAR2
25
SALARY
NN
NUM
8,2
DEPT_NO
FK
DEPARMENT
DEPT_NO
NUM
DATE
3
ID_NO
NAME
PK
NN, UU
NN
SALARY
HIRE_DATE
DEPT_NO
FK
DEPARMENT
FK column
Data type
Length
NUM
9
VARCHAR2
25
NUM
8,2
DEPT_NO
NUM
3
DATE
Which SQL statement will display employee hire date from earliest to latest?
a.
SELECT hire_date.
FROM worker;
b. SELECT hire_date.
FROM worker
ORDER BY hire_date;
c. SELECT hire_date;
FROM worker
GROUP BY hire_date;
d. SELECT hire_date.
FROM worker
ORDER BY hire_date DESC;
91. Evaluate the following PL/SQL block:
BEGIN
FROM I IN 1 . . 5 LOOP
IF i=1 THEN NULL;
ELSIF i=3 THEN COMMIT;
ELSIF i=5 THEN ROLLBACK;
ELSE INSERT INTO calculate(results);
VALUES(i);
END IF;
END LOOP;
COMMIT;
END;
How many values will be permanently inserted into the calculate table?
a.
b.
c.
d.
e.
f.
0
1
2
3
4
5
92. Which of the following scripts could be used to query the data dictionary to view only the names of
the primary key constraints using a substitution parameter for the table name?
a.
b.
c.
d.
FROM user_cons_columns
WHERE table_name=upper(&table) AND constraint_type= P;
93. Match the Constraint Name to its appropriate Definition:
Constraint Name
CHECK
NOT NULL
UNIQUE
PRIMARY KEY
FOREIGN KEY
Definition
The column must contain a value in each row.
Each value must be different in a column.
The value must be unique and present.
Defines a condition that each row must satisfy.
Establishes a relationship between columns.
94. What statement would be used to add a primary key constraint to the patient table using the
id_number column, immediately enabling the constraint?
a.
b.
1
2
3
4
5
6
7
96. Which SELECT statement displays the Order ID, Product ID, and quantity of items in the
merchandise table that matches both the Product ID and quantity of an item, order(20)?
a.
SELECT ordeid,prodid,qty
FROM merchandise
WHER (prodid,qty) IN
(SELECT prodid,qty
FROM merchandise
WHERE ordid=20)
b. SELECT ordeid,prodid,qty
FROM merchandise
WHERE (prodid,qty) =
(SELECT prodid,qty
FROM merchandise
WHERE ordid=20);
ANDordid<>20;
c. SELECT ordeid,prodid,qty
FROM merchandise
WHERE (prodid,qty) IN
(SELECT ordid,prodid,qty
FROM item
WHERE ordid=20);
AND ordid<>20;
d. SELECT ordeid,prodid,qty
FROM merchandise
WHERE (prodid,qty) IN
(SELECT prodid,qty
FROM merchandise
WHERE ordid=20);
AND ordid<>20;
97. Which of the following SELECT statements displays all workers without a subordinate?
a.
SELECT
w.wname
FROM work w
WHERE w.mgr IS NOT NULL;
b. SELECT w.wname
FROM work w
WHERE w.workno NOT IN (select m.mgr
FROM work w
WHER m.mgr IS NOT NULL);
c. SELECT w.wname
FROM work w
WHERE w.workno IN (select m.mgr
FROM work m);
d. SELECT w.wname
FROM work w
WHERE w.workno NOT IN (select m.mgr
FROM work m);
98. Examine the following cursor statement:
DECLARE
CURSOR query_cursor(v_salary)IS
SELECT last_name,salary_divison_no
FROM worker
WHERE SALARY>v_salary;
Why does this statement cause an error?
a.
b.
c.
d.
NULL?
NOT NULL
VARCHAR2
NOT NULL
NULL?
TYPE
NUMBER(4)
NUMBER(10)
NUMBER(2,9)
NUMBER(4)
DATE
NUMBER(7,2)
NUMBER(7,2)
NUMBER(2)
TYPE
NUMBER
NUMBER
NUMBER
You must create a report that displays employee details along with the tax category of each employee. The
tax category is determined by comparing the salary of the employee from the emp table to the upper and
lower salary values in the tax table. Which of the following SELECT statements will perform the
necessary comparisons?
a.
b.
c.
d.
Name
PART
Id PK
name
Product_id
cost
d.
Name
WORKER
id PK
Last_name
First_name
Divion_id
worker_division_id_idx
worker(divison_id);
id_number
PK
NN, U
ID_NUMBER
NUM
10
last_name
first_name
NN
NN
VARCHAR2
25
VARCHAR2
25
birth_date
Physician_id
PHYSICIAN
DATE
NUM
10
You must create the patient_id_seq sequence to be used with the patient tables primary key column. The
sequence will begin with 1000, have a maximum value of 9999999, not reuse numbers, and increment in
quantities of 1. Which of the following statements will accomplish the task?
a.
b.
c.
d.
All users.
Only yourself.
User Ed.
Users with access.
105.You must create a report that gives, per division, the number of workers and total salary as a
percentage of all divisions. Examine the results of the report:
DIVISION
10
20
30
%WORKERS
21.4
35.71
42.86
%SALARY
30.15
37.47
32.39
Which of the following SELECT statements will produce the above report?
a.
b.
c.
d.
SELECT divsionno
division,
(COUNT(*)/count(workno))* 100
%workers,
(SUM(sal)count(*))* 100
%salary
FROM scott.work GROUP BY divisiono;
SELECT divisionno
division,
PCT(workno)
%workers,
PCT(sal)
%salary
FROM scott.work
GROUP BY divisionno;
SELECT a.divisionno
division,
(a.num_work/COUNT(*))* 100
%workers,
(a.sal_sum/COUNT(*))*100
%salary.
FROM
(SELECT divisionno,COUNT(*)num_work,SUM(SAL)sal_sum
FROM scott.work
GROUP BY divisionno)a;
SELECT
division,
a.divisionno.
ROUND(a.num_work/b.total_count * 100,2)%workers
ROUND(a.sal_sum/b.total_sal * 100,2)
%salary%
FROM
(SELECT divisionno,COUNT(*)num_work,SUM(SAL)sal_sum
FROM scott.work
GROUP BY divisionno)b;
VARCHAR2(23)
VARCHAR2(23)
NUMBER(7,2)
Your manager requests that you write a statement to display all workers earning more than the average
salary of all workers. Evaluate the following SQL statement:
SELECT
FROM
WHERE
last_name
worker
salary > AVG(salary);
Move the function to the SELECT clause and add a GROUP BY clause.
Use a sub query in the WHERE clause to compare the salary value.
Change the function in the WHERE clause.
The statement requires no modification.
108.You attempt to query the worker database with the following command:
SELECT name,salary
FROM worker
Where salary=
(SELECT salary
FROM worker
WHERE last_name= Johnson OR dept_no=43)
The statement will cause an error because ______.
a.
b.
c.
d.
109.Which statement will provide the view definition of the work_view that is created based on the
worker table?
a.
b.
c.
d.
Describe work
DESCRIBE view work_view
SELECT TEXT
FROM user_views
WHERE view_name= WORK_VIEW;
SELECT view_text
FROM my_views
WHERE view_name= WORK_VIEW
110.Examine the structure of the movie title, copy, and check_out tables:
MOVIE
IdPK
Title
Director
COPY
IdPK
Title id PK
Available
CHECK_OUT
IdPK Copy_id
Title_id
Check_out_date
Expected_return_date
Customer-id
You need to create the MOVIES_AVAILABE view, and have the following parameters:
All
Two
One
A syntax error results.
111. There are three divisions within your company and each division has at least one worker bonus
program and at least one worker. Bonus values do not exceed 500; not all employees receive bonuses.
Evaluate the following block:
DECLARE
V_bonus worker.bonus%TYPE:=270;
BEGIN
UPDATE worker
SET bonus=bonus+v_bonus
WHERE division_id IN (10,20,30);
COMMIT;
END;
What is the result of the statement?
a.
b.
c.
d.
112.You have been given update privileges on the last_name column of the worker table. Which data
dictionary view would you query to display the column? The privileges were granted on the schema
that owns the worker table.
a.
b.
c.
d.
ALL_TABLES
TABLE_PRIVILEGES
ALL_COL_PRIVS_RECD
This cannot be retrieved from a single view.
c.
d.
114.You have been assigned the task of making major updates to the worker table. You disable the
primary key constraint on the workid column and the check constraint on the job column. What
happens when you try to enable the constraint after the update is completed?
a.
b.
c.
d.
Existing rows that dont conform with the constraints are automatically deleted.
Indexes on both columns with the primary key constraint and the check constraints are automatically
recreated.
All existing column values are verified to conform with the constraints and an error message is
narrated if any existing values are not confirmed.
The constraints must be recreated once they are disabled.
#_9
24_bottles
colors-1999
Slipper_#66*
NULL?
NOT NULL
NOT NULL
NOT NULL
TYPE
NUMBER(3)
VARCHAR2(25)
VARCHAR2(9)
VARCHAR2(50)
DATE
There are over two hundred records in the pupil table. You want to change the name of the graduation
column to grad_date. Which of the following is true?
a.
You can use the ALTER TABLE command with the MODIFY COLUMN clause to modify the
column.
b. You can use the ALTER TABLE command with the RENAME COLUMN clause to rename the
column.
c. You can use the ALTER TABLE command with the MODIFY clause to rename the column.
d. You cannot rename the column.
117.Examine the automobile table:
AUTOMOBILE
Column name
Key type
Nulls/Unique
FK table
FK column
Data type
Length
ID
PK
NN, UU
MODEL
STYLE
Color
NN
NN
NN
NUM
9
CHAR
20
CHAR
20
CHAR
20
LOT_NO
FK
NN
LOT
LOT_NO
NUM
3
Which SELECT statement will display the style, color, and lot number for all cars based on model?
a.
SELECT style,color,lot_no
FROM automobile
WHERE model=UPPER(%model);
b.
c.
d.
SELECT style,color,lot_no
FROM automobile
WHERE UPPER model=(&model);
SELECT style,color,lot_no
FROM automobile
WHERE UPPER model=UPPER(&model);
SELECT style,color,lot_no
FROM automobile
WHERE model=&model;
OPEN work_cursor.
OPEN work_cursor(clerk;,10);
OPEN work_cursor(10, manager);
OPEN work_cursor(p_divisionno,p_job);
119.As DBA, you use the CREATE USER command to create an account for user, Davis. Davis must
create tables and packages in his own schema. What command must be executed next to grant him
these privileges?
a.
c.
d.
VALUES(WORKNO_SEQ.NEXTVAL, Wallace,
TO_DATE(10-nov-52, DD-MON-YYYY),
TO_DATE(13-jan-01, DD-MON-RR));
121.You must retrieve worker details from the work table and process them in a PL/SQL block. Which
variable type must be created in the PL/SQL block to retrieve all rows and columns using a single
SELECT statement from the work table?
a.
b.
c.
d.
PL/SQL record.
PL/SQL table of records.
%ROWTYPE variable.
PL/SQL table of scalars.
LAST_NAME
Brown
Warner
West
Chalmers
Landers
Brunswick
Lauder
Ott
FIRST_NAME
Jerry
James
Dawn
Mack
Jillian
Kate
Susan
Trixie
SALARY
30000
25000
50000
32000
55000
DEPT_NO
255
233
102
145
233
145
FROM employee
WHERE salary<50000
GROUP BY dept_no
ORDER by last_name
123.Which of the following will display the average salary of divisions 3 and 6, but only if the
departments have an average salary of at least 3100?
a.
b.
c.
d.
ID
PK
NN, UU
MODEL
STYLE
Color
NN
NN
NN
NUM
9
CHAR
20
CHAR
20
CHAR
20
LOT_NO
FK
NN
LOT
LOT_NO
NUM
3
125.You need to create a report to display the ship date and order totals of your inventory table. If an
order has not been shipped, the report must indicate not shipped. If a total is not available, the
report must indicate not available. In the inventory table, the ship date column has a data type of
date and the total column has a data type of number. Which of the following statements should be
used to create the report?
a.
b.
b.
c.
d.
VARCHAR2(20)
NUMBER(3,2)
first-name,commission
worker
commission
(SELECT commission
FROM employee
WHERE UPPER(first-name)=Charles)
PRIMARY KEY,
NOT NULL);
130.How would a foreign key constraint be added on the division_no column in the worker table, referring
to the ID column in the division table?
a.
b.
c.
d.
Use the ALTER TABLE command with the ADD clause in the DETP table.
Use the ALTER TABLE command with the ADD clause on the EMP table.
Use the ALTER TABLE command with the MODIFY clause on the DEPT table.
This cannot be done.
Null
NOT NULL
Type
NUMBER(4)
VARCHAR2(20)
VARCHAR2(40)
DATE
The table is currently empty. Which statement prevents NULL values from being entered into the Name
column?
a.
PURCHASE_NO
PK
NN, U
NUM
8
CUSTOMER_ID
FK
NN
CUSTOMER
ID
NUM
8
CAR_ID
FK
NN
CAR
ID
NUM
8
SALES_ID
FK
NN
EMPLOYEE
ID
NUM
8
Id_number
PK
NN, UU
ID_NUMBER
NUM
10
last_name
first_name
NN
NN
VARCHAR2
25
VARCHAR2
25
birth_date
physician_id
PHYSICIAN
DATE
NUM
10
Which of the following DELETE statements will del ete a patient from the table by prompting the user for
the id_number of the patient to be deleted.
a.
b.
c.
d.
DELETE
FROM patient
WHERE id_number=&id_number
/
DEFINE: id_number
DELETE
FROM patient
WHERE id_number=&id_number
/
DELETE
DEFINE & id_number
FROM patient
WHERE id_number=&id_number
This cannot be done.
134.You must retrieve worker names and salaries from the work table. They must be displayed in
descending order. If two names match for a salary, then the two names will be displayed in
alphabetical order. Which statement should be used?
a.
SELECT wname,sal
FROM work
ORDER BY sal,wname;
b. SELECT wname,sal
FROM work
ORDER BY sal,DESC,wname;
c. SELECT wname,sal
FROM work
ORDER BY sal,wname;
d. This cannot be done.
135.For which three of these tasks would the WHERE clause be used?
a.
b.
c.
d.
e.
f.