Oracle Quiz Answers. Oracle Quiz Questions An asterisk (*) indicates a correct answer.
marți, 12 martie 2013
Section 2 Lesson 7: Good Programming Practices
Good Programming Practices
Section 1
1. Comments change how a PL/SQL program executes, so an unsuitable comment can cause the program to fail. True or False? (1) Points
True
False (*)
2. Examine the following code:
DECLARE
v_first_name varchar2 (30);
v_salary number (10);
BEGIN
SELECT first_name, salary
INTO v_first_name, v_salary
FROM employees
WHERE last_name = 'King';
END;
Which programming guideline would improve this code?
(1) Points
Use a suitable naming convention for variables.
Indent the code to make it more readable. (*)
Use upper and lower case consistently.
3. What symbol is used to comment a series of lines? (1) Points
/ / before and after the comment
/* */ before and after the comment (*)
* * before and after the comment
4. Which of the following are examples of good programming practice? (Choose two.) (1) Points
(Choose all correct answers)
Use the %TYPE attribute to declare a variable according to another previously declared variable or database column. (*)
Declare one or more identifiers per line for improved performance.
For clarity, use column names as identifiers.
Use meaningful names for identifiers. (*)
5. Which of the following are examples of good programming practice? (Choose three.) (1) Points
(Choose all correct answers)
Document code with comments. (*)
Use implicit data type conversions.
Develop naming conventions for identifiers and other objects. (*)
Indent code so that it can be read more easily. (*)
Use table column names as the names of variables.
6. Which of the following makes PL/SQL code easier to read and maintain? (1) Points
Place multiple statements on the same line.
Type everything in lowercase.
Use suitable comments in the code. (*)
Section 2 Lesson 6: Nested Blocks and Variable Scope
Nested Blocks and Variable Scope
Section 1
1. A variable is global to an outer block and local to the inner block. True or False? (1) Points
True
False (*)
2. Examine the following code. What is the scope of variable v_myvar?
DECLARE
v_myvar NUMBER;
BEGIN
v_myvar := 6;
DECLARE
v_hervar NUMBER;
BEGIN
v_hervar := 4;
END;
END;
(1) Points
Only the outer block
Both the inner and the outer block (*)
Only the inner block
Neither block
3. What values will be displayed when the following code is executed?
DECLARE
v_mynum NUMBER;
BEGIN
v_mynum := 7;
DECLARE
v_mynum NUMBER;
BEGIN
DBMS_OUTPUT.PUT_LINE(v_mynum);
v_mynum := 3;
END;
DBMS_OUTPUT.PUT_LINE(v_mynum);
END;
(1) Points
3,3
3,7
Null, 7 (*)
Null, 3
4. Examine the following code. Line A causes an exception. What will be displayed when the block is executed?
DECLARE
x NUMBER := 10;
y NUMBER;
BEGIN
x := 15;
y := 'Happy'; -- Line A
x := 20;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(x);
END;
(1) Points
10
20
15 (*)
Nothing is displayed
5. For the anonymous block below, what is the correct reference to the father's date of birth in the inner block?
<<outer>>
DECLARE
v_father_name VARCHAR2(20):='Patrick';
v_date_of_birth DATE:='20-Apr-1972';
BEGIN
DECLARE
v_child_name VARCHAR2(20):='Mike';
v_date_of_birth DATE:='12-Dec-2002';
...
(1) Points
v_date_of_birth.outer
<<outer>>v_date_of_birth
<<outer.v_date_of_birth>>
outer.v_date_of_birth (*)
6. An inner block is nested within an outer block. An exception occurs within the inner block, but the inner block does not have an EXCEPTION section. What happens? (1) Points
The exception is propagated to the outer block and the remaining executable statements in the outer block are skipped. (*)
The exception is propagated to the outer block and the remaining executable statements in the outer block are executed.
Oracle automatically tries to re-execute the inner block.
The outer block is bypassed and the exception is always propagated to the calling environment.
7. What is wrong with this code?
DECLARE
v_a NUMBER;
BEGIN
v_a := 27;
<<inner_block>>
BEGIN
v_a := 15;
END;
(1) Points
The outer block has no label.
Variable v_a is out of scope within the inner block and therefore cannot be referenced.
The inner block has no END; statement. (*)
Nothing is wrong, the code will execute successfully.
8. What happens when an exception occurs in the executable section of a PL/SQL block? (1) Points
Oracle keeps trying to re-execute the statement which caused the exception.
The remaining statements in the executable section are not executed. Instead, Oracle looks for an EXCEPTION section in the block. (*)
The remaining statements in the executable section of the block are executed.
The exception is always propagated to the calling environment.
9. Examine the following nested blocks. Line B causes an exception. What will be displayed when this code is executed?
DECLARE
var_1 NUMBER;
BEGIN
var_1 := 4;
DECLARE
var_2 NUMBER;
BEGIN
var_2 := 'Unhappy'; -- Line B
var_1 := 8;
END;
var_1 := 12;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(var_1);
END;
(1) Points
Unhappy
12
8
4 (*)
10. Examine the following code. At Line A, we want to assign a value of 25 to the outer block's variable (V1). What must we do?
DECLARE
v_myvar NUMBER; -- This is V1
BEGIN
DECLARE
v_myvar NUMBER := 8;
BEGIN
-- Line A
END;
END;
(1) Points
At Line A, code:
v_myvar := 25;
Label both blocks and at line A, code:
v_myvar := 25;
It cannot be done because the outer block's v_myvar is out of scope at Line A.
Label the outer block and (at Line A) dot-prefix v_myvar with the block label. (*)
It cannot be done because the outer block's v_myvar is in scope but not visible at Line A.
Section 2 Lesson 5: Writing PL/SQL Executable Statements
Writing PL/SQL Executable Statements
Section 1
1. Examine the following code: DECLARE x VARCHAR2(20); BEGIN x:= 5 + 4 * 5 ; DBMS_OUTPUT.PUT_LINE(x); END; What value of x will be displayed? (1) Points
45
29
25 (*)
14
2. Which explicit function is used to convert a character into a number? (1) Points
TO_DATE
TO_NUMBER (*)
TO_CHAR
3. Using implicit conversions is good programming practice. (1) Points
True
False (*)
4. Examine the following block. What should be coded at Line A?
DECLARE
v_char VARCHAR2(8) := '24/09/07';
v_date DATE;
BEGIN
v_date := ....... Line A
END;
(1) Points
v_date := FROM_CHAR(v_char,'dd/mm/yy');
v_date := TO_DATE(v_char,'dd/mm/yy'); (*)
v_date := v_char;
5. When PL/SQL converts data automatically from one data type to another, it is called _______ conversion. (1) Points
Explicit
Implicit (*)
TO_CHAR
6. The DECODE and MAX functions can be used in PL/SQL statements. True or False? (1) Points
True
False (*)
7. Which of the following are valid PL/SQL operators? (Choose three.) (1) Points (Choose all correct answers)
Concatenation (*)
Exception
Exponential (*)
Arithmetic (*)
8. Which of the following statements about implicit conversions is NOT true? (1) Points
Code containing implicit conversions typically runs faster than code containing explicit conversions. (*)
Code containing implicit conversions may not work in the future if Oracle changes the conversion rules.
Code containing implicit conversions is harder to read and understand.
9. Which of the following is correct? (1) Points
v_family_name = SMITH;
V_FAMILY_NAME = SMITH;
v_family_name := SMITH;
v_family_name := 'SMITH'; (*)
10. The TO_CHAR function is used for explicit data type conversions. True or False? (1) Points
True (*)
False
11. Explicit conversions can be slower than implicit conversions. True or False? (1) Points
True
False (*)
12. PL/SQL statements must be written on a single line. (1) Points
True
False (*)
13. What will happen when the following code is executed?
DECLARE v_new_date DATE;
BEGIN
v_new_date := 'Today';
DBMS_OUTPUT.PUT_LINE(v_new_date);
END;
(1) Points
The block will execute and display today's date.
The block will execute and display the word "Today".
The block will fail because the character value "Today" cannot be implicitly converted to a date. (*)
14. The LENGTH and ROUND functions can be used in PL/SQL statements. True or False? (1) Points
True (*)
False
15. PL/SQL can implicitly convert a CHAR to a NUMBER, provided the CHAR contains a numeric value, for example '123'. True or False? (1) Points
True (*)
False
16. Which of the following data type conversions can be done implicitly? (Choose two.) (1) Points
(Choose all correct answers)
DATE to NUMBER
NUMBER to VARCHAR2 (*)
NUMBER to PLS_INTEGER (*)
Section 2 Lesson 4: Using Scalar Data Types
Using Scalar Data Types
Section 1
1. If you use the %TYPE attribute, you can avoid hard-coding the column name. True or False? (1) Points
True
False (*)
2. Code is easier to read if you declare one identifier per line. True or False? (1) Points
True (*)
False
3. Which of the following is NOT a good guideline for declaring variables? (1) Points
Declare one identifier per line
Use column names as identifiers (*)
Use NOT NULL when the variable must have a value
4. Which of the following variable declarations does NOT use a number data type? (1) Points
v_count PLS_INTEGER := 0;
v_median_age NUMBER(6,2);
v_students LONG; (*)
v_count BINARY_INTEGER;
5. When declared using %TYPE, a variable will inherit ____ from the column on which it is based. (1) Points
The name of the column
The value of the column
The data type and size of the column (*)
6. Which of the following is NOT a character data type? (1) Points
VARCHAR2
BOOLEAN (*)
CHAR
LONG
Section 2 Lesson 3: Recognizing Data Types
Recognizing Data Types
Section 1
1. Which of the folowing are scalar data types? (Choose three.) (1) Points (Choose all correct answers)
Array
Character (*)
Table
Date (*)
Boolean (*)
2. Which of the following is a composite data type? (1) Points
CLOB
VARCHAR2
RECORD (*)
DATE
3. What are the data types of the variables in the following declaration?
DECLARE
fname VARCHAR2(20);
fname VARCHAR2(15) DEFAULT 'fernandez';
BEGIN
...
(1) Points
Scalar (*)
Composite
LOB
4. A datatype may specify a valid range of values. True or False? (1) Points
True (*)
False
5. A Scalar data type holds a ____ value. (1) Points
Multi
Large
Single (*)
6. A datatype specifies and restricts the possible data values that can be assigned to a variable. True or False? (1) Points
True (*)
False
7. Which of the following are PL/SQL data types? (Choose three.) (1) Points (Choose all correct answers)
Large Objects (LOB) (*)
Lexical
Scalar (*)
Delimiter
Composite (*)
Section 2 Lesson 2: Recognizing PL/SQL Lexical Units
Recognizing PL/SQL Lexical Units
Section 1
1. What is a lexical unit? (1) Points
A data type for a column
A building block of a PL/SQL block (*)
A type of variable
2. What characters must enclose non-numeric literal values? (1) Points
Double quotes: " "
Parentheses: ()
Single quotes: ' ' (*)
3. The name of a variable is an example of an identifier. True or False? (1) Points
True (*)
False
4. Which of the following symbols can be used to enclose a comment in PL/SQL? (1) Points
? ?
*/ / *
:: ::
/* */ (*)
5. Which of the following are lexical units? (Choose two.) (1) Points (Choose all correct answers)
Data types
PL/SQL blocks
Identifiers (*)
Literals (*)
6. Which of the following is a valid naming convention for an identifier? (Choose two.) (1) Points (Choose all correct answers)
Can include letters or numbers (*)
Cannot contain a reserved word (*)
Can be over 30 characters
Can start with a number or special character
Section 2 Lesson 1: Using Variables in PL/SQL
Using Variables in PL/SQL
Section 1
1. Evaluate the following declaration. Determine whether or not it is legal.
DECLARE
name,dept VARCHAR2(14);
(1) Points
legal
illegal (*)
2. Examine the following variable declarations:
DECLARE v_number NUMBER := 10; v_result NUMBER;
Which of the following correctly assigns the value 50 to V_RESULT? (1) Points
v_result := v_number * 5;
v_result := 100 / 2;
v_result := ROUND(49.77);
All of the above. (*)
3. After they are declared, variables can be used only once in an application. True or False? (1) Points
True
False (*)
4. Constants must be initialized. True or False? (1) Points
True (*)
False
5. Evaluate the following declaration. Determine whether or not it is legal. DECLARE
test NUMBER(5); (1) Points
legal (*)
illegal
6. Which of the following are required when declaring a variable? (Choose two.) (1) Points (Choose all correct answers)
Identifier name (*)
CONSTANT
Data type (*)
NOT NULL
7. Variables may be reused. True or False? (1) Points
True (*)
False
8. A function called FORMAT_TODAYS_DATE accepts no parameters and returns today's date in the format: Month DD, YYYY
The following anonymous block invokes the function:
DECLARE v_today DATE; BEGIN -- invoke the function here
Which of the following statements correctly assigns the date variable v_today to the value returned by the format_todays_date function?
(1) Points
format_todays_date := v_today('Month DD, YYYY');
v_today := format_todays_date ('Month DD, YYYY');
v_today := format_todays_date(v_today);
v_today := TO_DATE(format_todays_date, 'Month DD, YYYY'); (*)
Abonați-vă la:
Postări (Atom)