Semester 1 Mid Term Exam Part 1 PDF

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 16

Semester 1 Mid Term Exam Part 1 Section 1 (Answer all questions in this section)

1. Which of the following can you use PL/SQL to do?


Mark for Review (1) Points
Update data (DML) Develop Web applications using the Web Application Toolkit Man
age database security Create customized reports All of the above (*) Correct 2.
The fact that PL/SQL is portable is a good thing because:
Mark for Review (1) Points
Exceptions can be ported to different operating systems Blocks can be sent to th
e operating system. PL/SQL code can be developed on one platform and deployed on
another (*) PL/SQL code can be run on any operating system without a database C
orrect 3. Comparing PL/SQL with other languages such as C and Java, which of the
following statements is true?
Mark for Review (1) Points
PL/SQL is harder to learn PL/SQL is easier to learn and more efficient (*) PL/SQ
L is easier to learn but less efficient PL/SQL is easier to learn and does not r
equire an Oracle database or tool Correct 4. A program which specifies a list of
operations to be performed sequentially to achieve the desired result can be ca
lled:
Mark for Review (1) Points
declarative

nondeclarative procedural (*) low level Correct 5. PL/SQL is an Oracle proprieta


ry, procedural, 4GL programming language. True or False?
Mark for Review (1) Points
True False (*) Correct 6. SQL is a common access language for many types of data
bases, including Oracle. True or False?
Mark for Review (1) Points
True (*) False Correct 7. Which keywords must be included in every PL/SQL block?
(Choose two.)
Mark for Review (1) Points
(Choose all correct answers) DECLARE END; (*) EXCEPTION BEGIN (*) DBMS_OUTPUT.PU
T_LINE Correct 8. What is the purpose of using DBMS_OUTPUT.PUT_LINE in a PL/SQL
block?
Mark for Review (1) Points
To perform conditional tests

To allow a set of statements to be executed repeatedly To display results to che


ck if our code is working correctly (*) To store new rows in the database Correc
t 9. Errors are handled in the Exception part of the PL/SQL block. True or False
?
Mark for Review (1) Points
True (*) False Correct 10. Which lines of code will correctly display the messag
e "The cat sat on the mat"? (Choose two.)
Mark for Review (1) Points
(Choose all correct answers) DBMS_OUTPUT.PUT_LINE('The cat sat on the mat'); (*)
DBMS_OUTPUT.PUT_LINE(The cat sat on the mat); DBMS_OUTPUT.PUT_LINE('The cat' ||
'sat on the mat'); DBMS_OUTPUT.PUT_LINE('The cat sat ' || 'on the mat'); (*) In
correct. Refer to Section 1 Lesson 3. Section 1 (Answer all questions in this se
ction) 11. Which statements are optional in a PL/SQL block? (Choose two.)
Mark for Review (1) Points
(Choose all correct answers) DECLARE (*) BEGIN EXCEPTION (*) END; Correct

12. In which part of the PL/SQL block are declarations of variables defined?
Mark for Review (1) Points
Executable Exception Declarative (*) Definition Correct
Section 2 (Answer all questions in this section) 13. Assignment statements can c
ontinue over several lines in PL/SQL. True or False?
Mark for Review (1) Points
True (*) False Correct 14. Variables can be assigned a value in both the Executa
ble and Declaration sections of a PL/SQL program. True or False?
Mark for Review (1) Points
True (*) False Correct 15. When a variable is defined using the NOT NULL keyword
s, the variable must contain a value. True or False?
Mark for Review (1) Points
True (*) False Correct

16. When a variable is defined using the CONSTANT keyword, the value of the vari
able cannot change. True or False?
Mark for Review (1) Points
True (*) False Correct 17. ______ are meant to store large amounts of data.
Mark for Review (1) Points
Variables Scalar data types LOBs (*) Correct 18. Which statement most closely de
scribes "data type"?
Mark for Review (1) Points
It is the value of a variable. It specifies a storage format, constraints, and a
valid range of values for a variable. (*) It allows different kinds of data to
be stored in a single variable. It is used to test if errors have occurred. Corr
ect 19. A collection is a composite data type. True or False?
Mark for Review (1) Points
True (*) False Correct 20. Which good programming practice guideline would make
this code easier to read? DECLARE v_sal NUMBER(8,2); BEGIN SELECT salary INTO v_
sal
Mark for Review (1) Points

FROM employees WHERE employee_id = 100; UPDATE employees SET salary = v_sal; END
; Declaring variables using %TYPE Indenting each level of code (*) Using a consi
stent naming convention for variables Avoiding implicit data type conversions Co
rrect Section 2 (Answer all questions in this section) 21. Which of these are ex
amples of good programming practice? (Choose three.)
Mark for Review (1) Points
(Choose all correct answers) Declare two variables on each line of code. Use a N
OT NULL constraint when a variable must have a value (*) Use a clear and consist
ent naming convention for variables. (*) Declare variables with the same names a
s table columns. Do not rely on implicit data type conversions. (*) Correct 22.
Which of the following will help to make code easier to read?
Mark for Review (1) Points
Naming variables. Using %Type. Including comments in the code. (*) Incorrect. Re
fer to Section 2 Lesson 7. 23. Which of the following can be assigned to a Boole
an variable? 1. Null 2. False 3. True 4. 0 2 and 3
Mark for Review (1) Points

2, 3 and 4 1, 2 and 3 (*) 1, 2, 3 and 4 Correct 24. You need to declare a variab
le to hold a value which has been read from the SALARY column of the EMPLOYEES t
able. Which of the following is an advantage of declaring the variable as: emplo
yees.salary%TYPE ? It is shorter than coding NUMBER(8,2) If the SALARY column is
ALTERed later, the PL/SQL code need not be changed. (*) It executes much faster
than using NUMBER(8,2) It allows the software to perform implicit data type con
versions. Correct 25. A variable must have a value if NOT NULL is specified. Tru
e or False?
Mark for Review (1) Points
Mark for Review (1) Points
True (*) False Correct 26. What will be displayed when the following code is exe
cuted? DECLARE varA NUMBER := 12; BEGIN DECLARE varB NUMBER := 8; BEGIN varA :=
varA + varB; END; DBMS_OUTPUT.PUT_LINE(varB); END; 8 12 Nothing, the block will
fail with an error (*) 20 VarB
Mark for Review (1) Points

Correct 27. When nested blocks are used, which blocks can or must be labeled?
Mark for Review (1) Points
The inner block must be labeled, the outer block can be labeled. Both blocks mus
t be labeled Nested blocks cannot be labeled The outer block must be labeled if
it is to be referred to in the inner block. (*) Correct 28. Examine the followin
g code. Line A causes an exception. What will be displayed when the block is exe
cuted? DECLARE var_a NUMBER := 6; var_b DATE; BEGIN var_a := var_a * 2; var_b :=
'28 December 2006'; -- Line A var_a := var_a * 2; EXCEPTION WHEN OTHERS THEN DB
MS_OUTPUT.PUT_LINE(var_a); END; 12 (*) 24 6 Nothing will be displayed Correct 29
. PL/SQL does not look _________ in the child blocks.
Mark for Review (1) Points
Mark for Review (1) Points
Inward Upward Outward Downward (*) Correct

30. What will be displayed when the following block is executed? <<outer>> DECLA
RE v_myvar VARCHAR2(10) := 'Hello' ; BEGIN <<inner>> DECLARE v_myvar VARCHAR2(10
) := 'World'; BEGIN v_myvar := v_myvar || ' ' || outer.v_myvar; END; DBMS_OUTPUT
.PUT_LINE(inner.v_myvar); END; HelloWorld Hello World World The code will fail s
ince the inner variable is not within the scope of the outer block. (*) Correct
Section 2 (Answer all questions in this section) 31. TO_NUMBER, TO_CHAR, and TO_
DATE are all examples of:
Mark for Review (1) Points
Mark for Review (1) Points
Implicit conversion functions Explicit conversion functions (*) Character functi
ons Operators Correct 32. What is the output when the following program is execu
ted? set serveroutput on DECLARE a VARCHAR2(10) := '333'; b VARCHAR2(10) := '444
'; c PLS_INTEGER; d VARCHAR2(10); BEGIN c := TO_NUMBER(a) + TO_NUMBER(b); d := a
|| b; DBMS_OUTPUT.PUT_LINE(c); DBMS_OUTPUT.PUT_LINE(d); END;
Mark for Review (1) Points

Nothing. The code will result in an error. c=777 and d=333444 (*) c=777 and d=77
7 c=333444 and d=777 Correct 33. Which of the following are disadvantages of imp
licit data type conversions? (Choose two.)
Mark for Review (1) Points
(Choose all correct answers) The code is harder to read and understand (*) You c
annot store alphabetic characters in a variable of data type NUMBER If Oracle ch
anges the conversion rules in the future, your code may not work any more (*) Or
acle cannot implicitly convert a number value to a character string Correct 34.
Which of the following are valid assignment statements? (Choose two.)
Mark for Review (1) Points
(Choose all correct answers) v_string = 'Hello'; v_string := Hello; v_number :=
17 + 34; (*) v_string := 'Hello'; (*) v_date := 28-DEC-06; Correct 35. PL/SQL ca
n convert a VARCHAR2 value containing alphabetic characters to a NUMBER value. T
rue or False?
Mark for Review (1) Points
True False (*) Correct

36. Examine the following code: 1 2 3 4 5 DECLARE x NUMBER; BEGIN x:= '300'; END
;
Mark for Review (1) Points
After line 4, what is the value of x? '300' 300 (*) NULL Correct 37. Examine the
following code. What is the final value of V_MYBOOL ? DECLARE v_mynumber NUMBER
; v_mybool BOOLEAN ; BEGIN v_mynumber := 6; v_mybool := (v_mynumber BETWEEN 10 A
ND 20); v_mybool := NOT (v_mybool); END; True (*) False Correct 38. When you use
a function to convert data types in a PL/SQL program, it is called ______ conve
rsion.
Mark for Review (1) Points
Mark for Review (1) Points
Explicit (*) Implicit TO_CHAR Correct 39. Reserved words can be used as identifi
ers. True or False?
Mark for Review (1) Points

True False (*) Correct 40. Delimiters are _____ that have special meaning to the
Oracle database.
Mark for Review (1) Points
identifiers variables symbols (*) Correct Section 2 (Answer all questions in thi
s section) 41. Valid identifiers begin with a
Mark for Review (1) Points
Number Letter (*) Special character Correct
Section 3 (Answer all questions in this section) 42. Which rows will be deleted
from the EMPLOYEES table when the following code is executed? DECLARE salary emp
loyees.salary%TYPE := 12000; BEGIN DELETE FROM employees WHERE salary > salary;
END; All rows whose SALARY column value is greater than 12000. All rows in the t
able.
Mark for Review (1) Points

No rows. (*) All rows whose SALARY column value is equal to 12000. Correct 43. T
he following code will return the last name of the employee whose employee id is
equal to 100: True or False? DECLARE v_last_name employees.last_name%TYPE; empl
oyee_id employees.employee_id%TYPE := 100; BEGIN SELECT last_name INTO v_last_na
me FROM employees WHERE employee_id = employee_id; END; True False (*) Correct 4
4. Which one of these SQL statements can be directly included in a PL/SQL execut
able block?
Mark for Review (1) Points
Mark for Review (1) Points
DELETE FROM employees WHERE department_id=60; (*) SELECT salary FROM employees W
HERE department_id=60; CREATE TABLE new_emps (last_name VARCHAR2(10), first_name
VARCHAR2(10)); DROP TABLE locations; Correct 45. A variable is declared as: DEC
LARE v_holdit employees.last_name%TYPE; BEGIN ... Which of the following is a co
rrect use of the INTO clause? SELECT * INTO v_holdit FROM employees;
Mark for Review (1) Points

SELECT last_name INTO v_holdit FROM employees; SELECT last_name INTO v_holdit FR
OM employees WHERE employee_id=100; (*) SELECT salary INTO v_holdit FROM employe
es WHERE employee_id=100; Incorrect. Refer to Section 3 Lesson 2. 46. Which SQL
statement can NOT use an implicit cursor?
Mark for Review (1) Points
A DELETE statement An UPDATE statement A SELECT statement that returns multiple
rows (*) A SELECT statement that returns one row Correct 47. Assume there are 5
employees in Department 10. What happens when the following statement is execute
d? UPDATE employees SET salary=salary*1.1; All employees get a 10% salary increa
se. (*) No rows are modified because you did not specify "WHERE department_id=10
" A TOO_MANY_ROWS exception is raised. An error message is displayed because you
must use the INTO clause to hold the new salary. Correct 48. There are no emplo
yees in Department 77. What will happen when the following block is executed? BE
GIN DELETE FROM employees WHERE department_id=77; DBMS_OUTPUT.PUT_LINE(SQL%ROWCO
UNT) END;
Mark for Review (1) Points
Mark for Review (1) Points

A NO_DATA_FOUND exception is raised. A NULL is displayed. A zero (0) is displaye


d. (*) An exception is raised because the block does not contain a COMMIT statem
ent. Correct 49. Which of the following best describes a database transaction?
Mark for Review (1) Points
All the DML statements in a single PL/SQL block A related set of SQL DML stateme
nts which must be executed either completely or not at all (*) A single SQL stat
ement that updates multiple rows of a table A SELECT statement based on a join o
f two or more database tables Correct 50. How many DML statements can be include
d in a single transaction?
Mark for Review (1) Points
Only one None. A transaction cannot include DML statements. A maximum of four DM
L statements As many as needed (*) Correct

You might also like