100% found this document useful (1 vote)
2K views16 pages

Mid Exam Semester 1 Part 1

PL/SQL is a portable, procedural programming language that allows code to be developed on one platform and deployed on another. It can be used with any relational database, not just Oracle. PL/SQL code is easier to learn and more efficient than languages like C and Java. A PL/SQL block consists of the sections: DECLARE, BEGIN, EXCEPTION, and END arranged in that order. Nested blocks allow inner blocks to reference variables in outer blocks if the outer block is labeled.

Uploaded by

Madalina Marcu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
2K views16 pages

Mid Exam Semester 1 Part 1

PL/SQL is a portable, procedural programming language that allows code to be developed on one platform and deployed on another. It can be used with any relational database, not just Oracle. PL/SQL code is easier to learn and more efficient than languages like C and Java. A PL/SQL block consists of the sections: DECLARE, BEGIN, EXCEPTION, and END arranged in that order. Nested blocks allow inner blocks to reference variables in outer blocks if the outer block is labeled.

Uploaded by

Madalina Marcu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Section 1

(Answer all questions in this section)


1. 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 the 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
Correct
2. PL/SQL can be used not only with an Oracle database, but also with any
kind of relational database. True or False?

Mark for
Review
(1) Points

True
False (*)
Incorrect. Refer to Section 1 Lesson 2.
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/SQL is easier to learn but less efficient
PL/SQL is easier to learn and does not require an Oracle database or
tool
Correct
4. Which of the following tools can NOT be used to develop and test PL/SQL
code?

Mark for
Review
(1) Points

Oracle Jdeveloper
Oracle Application Express

Oracle JSQL (*)


Oracle iSQL*Plus
Incorrect. Refer to Section 1 Lesson 3.
5. Which lines of code will correctly display the message "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'); (*)
Correct
6. Given below are the parts of a PL/SQL block:
1.
2.
3.
4.

END;
EXCEPTION
DECLARE
BEGIN

Mark for
Review
(1) Points

Arrange the parts in order.

2,1,4,3
3,4,2,1 (*)
3,2,4,1
4,3,2,1
Correct
7. 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 check if our code is working correctly (*)
To store new rows in the database

Correct
8. Errors are handled in the Exception part of the PL/SQL block. True or False?

Mark for
Review
(1) Points

True (*)
False
Correct
9. Every PL/SQL anonymous block must start with the keyword DECLARE. True
or False?

Mark for
Review
(1) Points

True
False (*)
Correct
10. PL/SQL is an Oracle proprietary, procedural, 4GL programming language.
True or False?

Mark for
Review
(1) Points

True
False (*)
Correct
Section 1
(Answer all questions in this section)
11. A program which specifies a list of operations to be performed sequentially
to achieve the desired result can be called:

Mark for
Review
(1) Points

declarative
nondeclarative
procedural (*)
low level

Correct
12. The P in PL/SQL stands for:

Mark for
Review
(1) Points

Processing
Procedural (*)
Primary
Proprietary
Correct

Section 2
(Answer all questions in this section)
13. PL/SQL does not look _________ in the child blocks.

Mark for
Review
(1) Points

Inward
Upward
Outward
Downward (*)
Correct
14. 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 must 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

15. What will be displayed when the following block is executed?


<<outer>>
DECLARE
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;

Mark for
Review
(1) Points

HelloWorld
Hello World
World
The code will fail since the inner variable is not within the scope of the
outer block. (*)
Correct
16. What will be displayed when the following code is executed?
DECLARE
varA NUMBER := 12;
BEGIN
DECLARE
varB NUMBER := 8;
BEGIN
varA := varA + varB;
END;
DBMS_OUTPUT.PUT_LINE(varB);
END;

Mark for
Review
(1) Points

8
12
Nothing, the block will fail with an error (*)
20
VarB
Correct
17. Examine the following code. At Line A, we want to assign a value of 22 to
the outer block's variable v_myvar. What code should we write at Line A?
<<outer_block>>
DECLARE
v_myvar NUMBER;
BEGIN

Mark for
Review
(1) Points

<<inner_block>>
DECLARE
v_myvar NUMBER := 15;
BEGIN
-- Line A
END;
END;

outer_block.v_myvar := 22; (*)


v_myvar := 22;
<<outer_block>>.v_myvar := 22;
v_myvar(outer_block) := 22;
We cannot reference the outer block's variable because both variables
have the same name
Correct
18. Which good programming practice guideline would make this code easier to
read?
DECLARE
v_sal NUMBER(8,2);
BEGIN
SELECT salary INTO v_sal
FROM employees WHERE employee_id = 100;
UPDATE employees SET salary = v_sal;
END;

Mark for
Review
(1) Points

Declaring variables using %TYPE


Indenting each level of code (*)
Using a consistent naming convention for variables
Avoiding implicit data type conversions
Incorrect. Refer to Section 2 Lesson 7.
19. What good programming practice would make this code easier to follow?
DECLARE
v_myvar VARCHAR2(20);
BEGIN
DECLARE
v_myvar VARCHAR2(15);
BEGIN
...
END;
END;

Mark for
Review
(1) Points

Using a consistent naming convention for variables


Labeling the blocks (*)
Avoid using column names as identifiers
Developing a case convention for the code
Correct
20. Which of the following is an example of using a case convention for good
programming practice?

Mark for
Review
(1) Points

Assign variables by using functions.


Declare variables in the DECLARE section.
Declare data types in uppercase. (*)
Include an exception handler in every PL/SQL block.
Incorrect. Refer to Section 2 Lesson 7.
Section 2
(Answer all questions in this section)
21. Assignment statements can continue over several lines in PL/SQL. True or
False?

Mark for
Review
(1) Points

True (*)
False
Correct
22. Variables can be assigned a value in both the Executable and Declaration
sections of a PL/SQL program. True or False?

Mark for
Review
(1) Points

True (*)
False
Correct
23. When a variable is defined using the NOT NULL keywords, the variable must
contain a value. True or False?

Mark for
Review
(1) Points

True (*)
False
Correct
24. When a variable is defined using the CONSTANT keyword, the value of the
variable cannot change. True or False?

Mark for
Review
(1) Points

True (*)
False
Correct
25. Which of the following are PL/SQL lexical units? (Choose two.)

Mark for
Review
(1) Points

(Choose all correct answers)


Identifiers (*)
Table Columns
Reserved Words (*)
Anonymous Blocks
SQL Workshop
Correct
26. Reserved words can be used as identifiers. True or False?

Mark for
Review
(1) Points

True
False (*)
Correct
27. Which statements about lexical units are true? (Choose two.)

Mark for
Review
(1) Points

(Choose all correct answers)


They are named objects stored in the database
They are the building blocks of every PL/SQL program (*)
They are optional but can make a PL/SQL block execute faster
They are sequences of characters including letters, digits, tabs, returns
and symbols (*)
Correct
28. Examine the following code. What is the final value of V_MYVAR ?
DECLARE
v_myvar NUMBER;
BEGIN
v_myvar := 1 + 2 * 3;
v_myvar := v_myvar * 2;
END;

Mark for
Review
(1) Points

81
49
14 (*)
18
Correct
29. 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
30. What is wrong with this assignment statement?

myvar :=

'To be or not to be';

Mark for
Review

'That is the question';

(1) Points

An assignment statement must be a single line of code


Nothing is wrong, the statement is fine
An assignment statement must have a single semicolon at the end (*)
"myvar" is not a valid name for a variable
Character literals should not be enclosed in quotes
Incorrect. Refer to Section 2 Lesson 5.
Section 2
(Answer all questions in this section)
31. The implicit data type conversion at Point A may not work correctly. Why
not?
DECLARE
v_mydate DATE;
BEGIN
V_MYDATE := '29-Feb-2004'; -- Point A
END;

Mark for
Review
(1) Points

There are only 28 days in February


Oracle cannot implicitly convert a character string to a date, even if the
string contains a valid date value
If the database language is not English, 'Feb' has no meaning. (*)
V_MYDATE has been entered in uppercase
Correct
32. The DECODE function is available in PL/SQL procedural statements. True or
False?

Mark for
Review
(1) Points

True
False (*)
Correct
33. 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
34. If today's date is 14th June 2007, which statement will correctly convert
today's date to the value: June 14, 2007 ?

Mark for
Review
(1) Points

TO_CHAR(sysdate)
TO_DATE(sysdate)
TO_DATE(sysdate,'Month DD, YYYY')
TO_CHAR(sysdate, 'Month DD, YYYY') (*)
Correct
35. Single row character functions are valid SQL functions in PL/SQL. True or
False?

Mark for
Review
(1) Points

True (*)
False
Correct
36. Which of these are PL/SQL data types? (Choose three.)

Mark for
Review
(1) Points

(Choose all correct answers)


Scalar (*)
Identifier
Delimiter
Composite (*)
LOB (*)

Correct
37. ______ are meant to store large amounts of data.

Mark for
Review
(1) Points

Variables
Scalar data types
LOBs (*)
Correct
38. What is the data type of the variable V_DEPT_TABLE in the following
declaration?
DECLARE
TYPE dept_table_type IS TABLE OF departments%ROWTYPE INDEX BY
PLS_INTEGER; v_dept_table dept_table_type; ...

Mark for
Review
(1) Points

Scalar
Composite (*)
LOB
Correct
39. Which of the following declarations is invalid?

Mark for
Review
(1) Points

v_count PLS_INTEGER:=0;
college_name VARCHAR2(20):='Harvard';
v_pages CONSTANT NUMBER; (*)
v_start_date DATE := sysdate+1;
Correct
40. Which of the following can be assigned to a Boolean variable?
1. Null
2. False
3. True
4. 0
2 and 3
2, 3 and 4

Mark for
Review
(1) Points

1, 2 and 3 (*)
1, 2, 3 and 4
Correct
Section 2
(Answer all questions in this section)
41. You need to declare a variable to hold a value which has been read from the
SALARY column of the EMPLOYEES table. Which of the following is an
advantage of declaring the variable as: employees.salary%TYPE ?

Mark for
Review
(1) Points

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 conversions.
Correct

Section 3
(Answer all questions in this section)
42. The following anonymous block of code is run:
BEGIN
INSERT INTO countries (id, name)
VALUES ('XA', 'Xanadu');
SAVEPOINT XA;
INSERT INTO countries (id, name)
VALUES ('NV','Neverland');
COMMIT;
ROLLBACK TO XA;
END;
What happens when the block of code finishes?

No data is inserted and no errors occur.


No data is inserted and an error occurs
Two rows are inserted and no errors occur.
Two rows are inserted and an error occurs. (*)
Incorrect. Refer to Section 3 Lesson 4.

Mark for
Review
(1) Points

43. How many DML statements can be included in a single transaction?

Mark for
Review
(1) Points

Only one
None. A transaction cannot include DML statements.
A maximum of four DML statements
As many as needed (*)
Correct
44. 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
45. A PL/SQL block includes the following statement:
SELECT last_name INTO v_last_name
FROM employees
WHERE employee_id=100;

Mark for
Review
(1) Points

What is the value of SQL%ISOPEN immediately after the SELECT statement


is executed?

True
False (*)
Null
Error. That attribute does not apply for implicit cursors.
Correct
46. You declare an implicit cursor in the DECLARE section of a PL/SQL block.
True or False?

Mark for
Review
(1) Points

True
False (*)
Correct
47. The 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;
employee_id employees.employee_id%TYPE := 100;
BEGIN
SELECT last_name INTO v_last_name
FROM employees
WHERE employee_id = employee_id;
END;

Mark for
Review
(1) Points

True
False (*)
Correct
48. Which one of these SQL statements can be directly included in a PL/SQL
executable block?

Mark for
Review
(1) Points

SELECT last_name FROM employees


WHERE employee_id=100;
DESCRIBE employees;
UPDATE employees
SET last_name='Smith';
(*)
DROP TABLE employees;
Incorrect. Refer to Section 3 Lesson 2.
49. A variable is declared as:
DECLARE
v_salary employees.salary%TYPE;
BEGIN
Which of the following is a correct use of the INTO clause?

Mark for
Review
(1) Points

SELECT salary
INTO v_salary
FROM employees
WHERE employee_id=100;
(*)
SELECT v_salary
INTO salary
FROM employees
WHERE employee_id=100;
SELECT salary
FROM employees
INTO v_salary;
SELECT salary
FROM employees
WHERE employee_id=100
INTO v_salary;
Incorrect. Refer to Section 3 Lesson 2.
50. Which rows will be deleted from the EMPLOYEES table when the following
code is executed?
DECLARE
salary employees.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 table.
No rows. (*)
All rows whose SALARY column value is equal to 12000.
Correct

Mark for
Review
(1) Points

You might also like