PL/SQL Section 1 Quiz
PL/SQL Section 1 Quiz
Tes
Tinjau jawaban, umpan balik, dan skor pertanyaan Anda di bawah ini. Tanda
bintang (*) menunjukkan jawaban yang benar.
Section 1
(Jawab semua pertanyaan di bagian ini)
1. Which of the following can be compiled as a standalone program outside the
database?
A program developed in PL/SQL
A program developed in PL/SQL or C
None of these can be compiled outside of a database
Programs developed in Java or C, but not in PL/SQL (*)
A program developed in PL/SQL or Java
Correct
(1/1) Point
2. PL/SQL can be used not only with an Oracle database, but also with any kind
of relational database. True or False?
True
False (*)
Correct
(1/1) Point
3. Which of the following can be done using PL/SQL?
Manage database tasks such as security
Create complex applications
Create custom reports
All of these can be done (*)
Retrieve and modify data in Oracle database tables
Correct
(1/1) Point
4. Which of the following can be done using PL/SQL?
Create customized reports
Update data (DML)
All of these can be done (*)
Manage database security
Develop Web applications using the Web Application Toolkit
Correct
(1/1) Point
5. You can create a Web site application written entirely in PL/SQL. True or False?
True
False (*)
Incorrect. Refer to Section 1 Lesson 2.
(0/1) Point
Halaman 1 dari 3 Berikutnya
Tes
Tinjau jawaban, umpan balik, dan skor pertanyaan Anda di bawah ini. Tanda
bintang (*) menunjukkan jawaban yang benar.
Section 2
(Jawab semua pertanyaan di bagian ini)
1. Is the following variable declaration correct or not?
DECLARE
name, dept VARCHAR2(14);
Correct.
Not correct. (*)
Correct
(1/1) Point
2. When a variable is defined using the CONSTANT keyword, the value of the
variable cannot change. True or False?
True (*)
False
Correct
(1/1) Point
3. 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;
Tes
Tinjau jawaban, umpan balik, dan skor pertanyaan Anda di bawah ini. Tanda
bintang (*) menunjukkan jawaban yang benar.
Section 2
(Jawab semua pertanyaan di bagian ini)
6. 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';
...
v_date_of_birth.outer
<< outer.v_date_of_birth >>
outer.v_date_of_birth (*)
<< outer>>v_date_of_birth
Correct
(1/1) Point
7. If you are using the %TYPE attribute, you can avoid hard coding the:
Constraint
Table name
Data type (*)
Column name
Correct
(1/1) Point
8. Code is easier to read if you declare one identifier per line. True or False?
True (*)
False
Correct
(1/1) Point
9. Which of the following is a composite data type?
RECORD (*)
CLOB
DATE
VARCHAR2
Correct
(1/1) Point
10. Which statement most closely describes "data type"?
It is the value of a variable.
It allows different kinds of data to be stored in a single variable.
It is used to test if errors have occurred.
It specifies a storage format, constraints, and a valid range of values for a
variable. (*)
Correct
(1/1) Point
Sebelumnya Halaman 2 dari 3 Berikutnya
Tes
Tinjau jawaban, umpan balik, dan skor pertanyaan Anda di bawah ini. Tanda
bintang (*) menunjukkan jawaban yang benar.
Section 2
(Jawab semua pertanyaan di bagian ini)
11. Which of the following are valid identifiers? (Choose two.)
(Pilih semua jawaban yang benar)
Full Name
completion_%
#hours
v_code (*)
students_street_address (*)
Correct
(1/1) Point
12. Which of the following are valid identifiers? (Choose two.)
(Pilih semua jawaban yang benar)
#students
number_of_students_in_the_class
yesterday (*)
yesterday's date
v$testresult (*)
Correct
(1/1) Point
13. When PL/SQL converts data automatically from one data type to another, it is
called _______ conversion.
Explicit
TO_CHAR
Implicit (*)
Correct
(1/1) Point
14. Which of the following statements about implicit conversions is NOT true?
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.
Code containing implicit conversions typically runs faster than code containing
explicit conversions. (*)
Correct
(1/1) Point
15. PL/SQL can implicitly convert a CHAR to a NUMBER, provided the CHAR
contains a numeric value, for example '123'. True or False?
True (*)
False
Correct
(1/1) Point
Sebelumnya Halaman 3 dari 3
Tes
Tinjau jawaban, umpan balik, dan skor pertanyaan Anda di bawah ini. Tanda
bintang (*) menunjukkan jawaban yang benar.
Section 3
(Jawab semua pertanyaan di bagian ini)
1. Employee_id 999 does not exist. What will happen when the following code is
executed?
DECLARE
employee_id employees.employee_id%TYPE := 999;
BEGIN
UPDATE employees
SET salary = salary * 1.1
WHERE employee_id = employee_id;
END;
An exception is raised because you cannot give a variable the same name as a
table column.
Every employee row is updated. (*)
Correct
(1/1) Point
2. A PL/SQL block contains the following DML statement:
UPDATE wf_countries
SET population = population * 1.1
WHERE country_id = 229;
True or False?
True
False (*)
Correct
(1/1) Point
4. Which one of these SQL statements can be directly included in a PL/SQL
executable block?
SELECT salary FROM employees
WHERE department_id=60;
CREATE TABLE new_emps (last_name VARCHAR2(10), first_name VARCHAR2(10));
The block will fail because the SELECT is trying to read two columns into three
PL/SQL variables. (*)
The block will execute successfully, and the V_SALARY variable will be set to
NULL.
The block will fail because the SELECT statement returns more than one row.
The block will fail because V_LAST was declared before V_FIRST.
Correct
(1/1) Point
Halaman 1 dari 3 Berikutnya
Tes
Tinjau jawaban, umpan balik, dan skor pertanyaan Anda di bawah ini. Tanda
bintang (*) menunjukkan jawaban yang benar.
Section 3
(Jawab semua pertanyaan di bagian ini)
6. Does PL/SQL allow you to have a variable with the same name as a database
column?
No
Yes (*)
Correct
(1/1) Point
7. 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;
True
False (*)
Correct
(1/1) Point
8. Which of the following is NOT a good guideline for retrieving data in PL/SQL?
THE SELECT statement should fetch exactly one row.
Declare the receiving variables using %TYPE
Specify the same number of variables in the INTO clause as database columns in
the SELECT clause.
The WHERE clause is optional in nearly all cases. (*)
Correct
(1/1) Point
9. If a DELETE statement does not include a WHERE clause, all rows in the table
are deleted. True or False?
True (*)
False
Correct
(1/1) Point
10. When explicitly inserting a row into a table, the VALUES clause must include a
value for every column of the table. True or False?
True
False (*)
Correct
(1/1) Point
Sebelumnya Halaman 2 dari 3 Berikutnya
Tes
Tinjau jawaban, umpan balik, dan skor pertanyaan Anda di bawah ini. Tanda
bintang (*) menunjukkan jawaban yang benar.
Section 3
(Jawab semua pertanyaan di bagian ini)
11. What keyword goes at the beginning of the following SQL statement?
_____ INTO test1 a
USING all_objects b
ON (a.object_id = b.object_id)
WHEN MATCHED
THEN UPDATE
SET a.status = b.status
WHEN NOT MATCHED THEN
INSERT (object_id, status)
VALUES (b.object_id, b.status);
INSERT
DELETE
UPDATE
MERGE (*)
Correct
(1/1) Point
12. You want to modify existing rows in a table. Which of the following are NOT
needed in your SQL statement?
A MODIFY clause. (*)
An UPDATE clause.
The name of the column(s) you want to modify.
A new value for the column you want to modify (this can be an expression or a
subquery).
The name of the table.
Correct
(1/1) Point
13. What is wrong with the following statement?
MERGE INTO emps e
USING new_emps ne
ON (e.employee_id = ne.employee_id)
WHEN MATCHED
THEN UPDATE
SET ne.salary = e.salary
WHEN NOT MATCHED
THEN INSERT VALUES
(ne.employee_id, ne.first_name, ne.last_name, .... ne.salary, ....);
The SET clause is trying to update the source table from the target table. (*)
The INSERT clause must include a column list as well as a list of column values.
4
Tes
Tinjau jawaban, umpan balik, dan skor pertanyaan Anda di bawah ini. Tanda
bintang (*) menunjukkan jawaban yang benar.
Section 4
(Jawab semua pertanyaan di bagian ini)
1. What type of control structures are repetition statements that enable you to
execute statements in a PLSQL block repeatedly?
Loops (*)
CASE statements
CASE expressions
IF statements
Correct
(1/1) Point
2. What is the correct form of a simple IF statement?
IF condition THEN statement;
END IF; (*)
IF condition;
THEN statement;
END IF;
IF condition
THEN statement
ENDIF;
IF condition THEN statement;
Correct
(1/1) Point
3. What will be displayed when this block is executed?
DECLARE
v_bool1 BOOLEAN := NULL;
v_bool2 BOOLEAN := NULL;
v_char VARCHAR(10) := 'Start';
BEGIN
IF (v_bool1 = v_bool2) THEN
v_char:='Equal';
ELSE v_char:='Not equal';
END IF;
DBMS_OUTPUT.PUT_LINE(v_char);
END;
Start
Nothing will be displayed. The block will fail because you cannot compare two
null values.
Equal
Not equal (*)
Correct
(1/1) Point
4. Examine the following code:
DECLARE
v_score NUMBER(3);
v_grade CHAR(1);
BEGIN
v_grade := CASE v_score
-- Line A
....
The CASE expression must convert a numeric score to a letter grade: 90 -> A, 80 -
> B, 70 -> C and so on. What should be coded at Line A?
Tes
Tinjau jawaban, umpan balik, dan skor pertanyaan Anda di bawah ini. Tanda
bintang (*) menunjukkan jawaban yang benar.
Section 4
(Jawab semua pertanyaan di bagian ini)
6. What will be the value of variable c after the following code is executed?
DECLARE
a BOOLEAN := TRUE;
b BOOLEAN := NULL;
c NUMBER;
BEGIN
IF a AND b THEN c := 2;
ELSIF a OR b THEN c := 0;
ELSE c := 1;
END IF;
END;
1
2
0 (*)
Null
Correct
(1/1) Point
7. A PL/SQL block contains the following code:
v_counter := 1;
LOOP
EXIT WHEN v_counter = 5;
v_counter := v_counter + 1;
END LOOP;
Tes
Tinjau jawaban, umpan balik, dan skor pertanyaan Anda di bawah ini. Tanda
bintang (*) menunjukkan jawaban yang benar.
Section 4
(Jawab semua pertanyaan di bagian ini)
11. Examine the following code:
DECLARE
v_outer_count NUMBER := 1;
v_inner_count NUMBER := 1;
BEGIN
LOOP
LOOP
v_inner_count := v_inner_count + 1;
EXIT WHEN v_inner_count > 5; -- Line A
END LOOP;
v_outer_count := v_outer_count + 1;
EXIT WHEN v_outer_count > 3;
END LOOP;
END;
It will display 2, 3, 4.
It will result in an error because the counter was not explicitly declared.
It will display 1, 2, 3.
It will result in an error because you cannot modify the counter in a FOR loop. (*)
Correct
(1/1) Point
15. In a FOR loop, an explicitly declared counter is automatically incremented by
1 for each iteration of the loop. True or False?
True
False (*)
Correct
(1/1) Point
Sebelumnya Halaman 3 dari 3
MID TEST
Tes
Tinjau jawaban, umpan balik, dan skor pertanyaan Anda di bawah ini. Tanda
bintang (*) menunjukkan jawaban yang benar.
Section 1
(Jawab semua pertanyaan di bagian ini)
END
DECLARE (*)
Correct
(1/1) Point
2. Which of the following tools can NOT be used to develop and test PL/SQL code?
Oracle Jdeveloper
Oracle iSQL*Plus
Correct
(1/1) Point
BEGIN
DBMS_OUTPUT.PUT_LINE('Hello');
DBMS_OUTPUT.PUT_LINE(' and Goodbye');
Correct
(1/1) Point
Named (*)
Correct
(1/1) Point
5. Which of the following statements about PL/SQL and SQL is true?
PL/SQL allows basic program logic and control flow to be combined with SQL
statements. (*)
PL/SQL and SQL can be used with many types of databases, including Oracle.
Correct
(1/1) Point
Tes
Tinjau jawaban, umpan balik, dan skor pertanyaan Anda di bawah ini. Tanda
bintang (*) menunjukkan jawaban yang benar.
Section 1
(Jawab semua pertanyaan di bagian ini)
END
DECLARE (*)
Correct
(1/1) Point
2. Which of the following tools can NOT be used to develop and test PL/SQL code?
Oracle Jdeveloper
Oracle iSQL*Plus
Correct
(1/1) Point
BEGIN
DBMS_OUTPUT.PUT_LINE('Hello');
DBMS_OUTPUT.PUT_LINE(' and Goodbye');
Correct
(1/1) Point
Named (*)
Correct
(1/1) Point
PL/SQL allows basic program logic and control flow to be combined with SQL
statements. (*)
PL/SQL and SQL can be used with many types of databases, including Oracle.
Correct
(1/1) Point
Tes
Tinjau jawaban, umpan balik, dan skor pertanyaan Anda di bawah ini. Tanda
bintang (*) menunjukkan jawaban yang benar.
Section 1
(Jawab semua pertanyaan di bagian ini)
6. In which three ways does PL/SQL extend the SQL programming language?
Correct
(1/1) Point
7. You can create a Web site application written entirely in PL/SQL. True or False?
True
False (*)
(0/1) Point
8. Comparing PL/SQL with other languages such as C and Java, which of the following
statements is true?
PL/SQL is easier to learn and does not require an Oracle database or tool
(1/1) Point
Section 2
(Jawab semua pertanyaan di bagian ini)
Parentheses: ()
Correct
(1/1) Point
Number
Letter (*)
Special character
Correct
(1/1) Point
Tes
Tinjau jawaban, umpan balik, dan skor pertanyaan Anda di bawah ini. Tanda
bintang (*) menunjukkan jawaban yang benar.
Section 2
(Jawab semua pertanyaan di bagian ini)
11. Which of these are examples of good programming practice? (Choose three.)
(0/1) Point
12. 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;
Correct
(1/1) Point
Single (*)
Multi
Large
image
Correct
(1/1) Point
14. 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;
…
Composite (*)
LOB
PLS_INTEGER
Scalar
Correct
(1/1) Point
15. When declared using %TYPE, a variable will inherit ____ from the column on which it
is based.
Correct
(1/1) Point
Tes
Tinjau jawaban, umpan balik, dan skor pertanyaan Anda di bawah ini. Tanda
bintang (*) menunjukkan jawaban yang benar.
Section 2
(Jawab semua pertanyaan di bagian ini)
16. 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 ?
If the SALARY column is ALTERed later, the PL/SQL code need not be changed. (*)
Correct
(1/1) Point
17. Which of the following are valid assignment statements? (Choose two.)
v_string = 'Hello';
v_date := 28-Dec-2006;
v_string := Hello;
Correct
(1/1) Point
18. Which of the following statements about implicit conversions is NOT true?
Code containing implicit conversions may not work in the future if Oracle changes the
conversion rules.
Code containing implicit conversions typically runs faster than code containing explicit
conversions. (*)
Correct
(1/1) Point
19. The LENGTH and ROUND functions can be used in PL/SQL statements. True or
False?
True (*)
False
Correct
(1/1) Point
20. When you use a function to convert data types in a PL/SQL program, it is called
______ conversion.
Implicit
TO_CHAR
Explicit (*)
Correct
(1/1) Point
Tes
Tinjau jawaban, umpan balik, dan skor pertanyaan Anda di bawah ini. Tanda
bintang (*) menunjukkan jawaban yang benar.
Section 2
(Jawab semua pertanyaan di bagian ini)
16. 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 ?
If the SALARY column is ALTERed later, the PL/SQL code need not be changed. (*)
Correct
(1/1) Point
17. Which of the following are valid assignment statements? (Choose two.)
v_string = 'Hello';
v_string := Hello;
Correct
(1/1) Point
18. Which of the following statements about implicit conversions is NOT true?
Code containing implicit conversions may not work in the future if Oracle changes the
conversion rules.
Code containing implicit conversions typically runs faster than code containing explicit
conversions. (*)
Correct
(1/1) Point
19. The LENGTH and ROUND functions can be used in PL/SQL statements. True or
False?
True (*)
False
Correct
(1/1) Point
20. When you use a function to convert data types in a PL/SQL program, it is called
______ conversion.
Implicit
TO_CHAR
Explicit (*)
Correct
(1/1) Point
Section 2
(Jawab semua pertanyaan di bagian ini)
True (*)
False
Correct
(1/1) Point
Section 3
(Jawab semua pertanyaan di bagian ini)
DECLARE
v_result employees.salary%TYPE;
BEGIN
SELECT salary
INTO v_result
FROM employees
SELECT salary
INTO v_result
FROM employees;
SELECT SUM(salary)
INTO v_result
SELECT salary
INTO v_result
FROM employees
Correct
(1/1) Point
28. Which one of these SQL statements can be directly included in a PL/SQL executable
block?
IF... THEN...;
SHOW USER;
Correct
(1/1) Point
29. When used in a PL/SQL block, which SQL statement must return exactly one row?
INSERT
UPDATE
DELETE
SELECT (*)
MERGE
Correct
(1/1) Point
30. Which of the following SQL DML commands can be used inside a PL/SQL block?
Correct
(1/1) Point
Tes
Tinjau jawaban, umpan balik, dan skor pertanyaan Anda di bawah ini. Tanda
bintang (*) menunjukkan jawaban yang benar.
Section 3
(Jawab semua pertanyaan di bagian ini)
31. There are no employees in Department 77. What will happen when the following
block is executed?
BEGIN
DELETE FROM employees
WHERE department_id=77;
DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT)
END;
A NULL is displayed.
An exception is raised because the block does not contain a COMMIT statement.
Correct
(1/1) Point
32. You can use implicit cursor attributes such as SQL%ROWCOUNT directly inside a
DML statement. For example:
True or False?
True
False (*)
Correct
(1/1) Point
33. 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;
No data is inserted.
Correct
(1/1) Point
As many as you want until a different DML statement (UPDATE, DELETE or MERGE) is
executed.
One
Correct
(1/1) Point
35. Which of the following will delete all employees who work in the Sales department?
FROM employees;
Correct
(1/1) Point
Tes
Tinjau jawaban, umpan balik, dan skor pertanyaan Anda di bawah ini. Tanda
bintang (*) menunjukkan jawaban yang benar.
Section 3
(Jawab semua pertanyaan di bagian ini)
UPDATE employees
SET salary = 5000, commission_pct = NULL WHERE department_id = 50; ;
The statement fails because you cannot modify more than one column in a single
UPDATE statement.
All employees who have a salary of 5000 have their commission percentage set to
NULL.
The statement fails because you cannot use NULL in the SET clause.
All employees in department 50 have their salary changed to 5000 and their
Correct
(1/1) Point
Section 4
(Jawab semua pertanyaan di bagian ini)
DECLARE
v_date DATE := SYSDATE;
BEGIN
WHILE v_date < LAST_DAY(v_date) LOOP
v_date := v_date + 1;
END LOOP;
DBMS_OUTPUT.PUT_LINE(v_date);
END;
If today's date is 17th April 2007, what will be displayed when this block
executes?
17-Apr-2007
01-May-2007
31-Dec-2007
30-Apr-2007 (*)
Correct
(1/1) Point
DECLARE
v_boolean BOOLEAN := FALSE;
v_counter NUMBER(4) := 0;
BEGIN
... Line A
…
END;
Which of the following is NOT valid at line A?
Correct
(1/1) Point
39. Which statement best describes when a WHILE loop shouild be used?
true (*)
Correct
(1/1) Point
40. Which one of these statements about using nested loops is true?
The outer loop must be labeled if you want to exit the outer loop from within the inner
loop. (*)
The outer loop must be labeled, but the inner loop need not be labeled.
Correct
(1/1) Point
Tes
Tinjau jawaban, umpan balik, dan skor pertanyaan Anda di bawah ini. Tanda
bintang (*) menunjukkan jawaban yang benar.
Section 4
(Jawab semua pertanyaan di bagian ini)
DECLARE
i INTEGER := 0;
BEGIN
<< i_loop >>
WHILE i <= 10 LOOP
i := i+1;
<< j_loop >>
FOR j IN 1..5 LOOP
_______ WHEN i = j*2; -- Point A
DBMS_OUTPUT.PUT_LINE(i || j);
END LOOP;
END LOOP;
END;
EXIT j_loop
EXIT outerloop
Correct
(1/1) Point
1
This is an infinite loop; the loop will never finish. (*)
(0/1) Point
DECLARE
v_count NUMBER := 0;
v_string VARCHAR2(20);
BEGIN
LOOP
v_string := v_string || 'x';
IF LENGTH(v_string) > 10 THEN
EXIT;
END IF;
v_count := v_count + 1;
END LOOP;
DBMS_OUTPUT.PUT_LINE(v_count);
END;
11
xxxxxxxxxxx
10 (*)
Correct
(1/1) Point
DECLARE
v_count NUMBER := 10;
v_result NUMBER;
BEGIN
LOOP
v_count := v_count - 1;
EXIT WHEN v_count < 5;
v_result := v_count * 2;
END LOOP;
DBMS_OUTPUT.PUT_LINE(v_result);
END;
NULL
12
10 (*)
Correct
(1/1) Point
DECLARE
x BOOLEAN := FALSE;
y BOOLEAN := FALSE;
z BOOLEAN ;
BEGIN
z := (x OR NOT y);
-- Line A
....
END;
What is the value of Z at Line A?
NULL
False
True (*)
An error will occur because you cannot combine two Boolean variables using "NOT".
Correct
(1/1) Point
Section 4
(Jawab semua pertanyaan di bagian ini)
DECLARE
v_a BOOLEAN;
v_b BOOLEAN := FALSE;
v_c BOOLEAN ;
BEGIN
v_c := (v_a AND v_b);
-- Line A
....
END;
Undefined
True
NULL
False (*)
Correct
(1/1) Point
Correct
(1/1) Point
48. A basic loop is a type of control structure used to change the logical flow of
statements in a PL/SQL block. True or False?
True (*)
False
Correct
(1/1) Point
IF condition
THEN statement1
ELSE statement 2;
END IF;
IF condition;
THEN statement1;
ELSE statement2;
END IF;
IF condition
THEN statement1
ELSE statement 2;
Correct
(1/1) Point
IF (v_job='President')
THEN v_salary := 10000;
ELSE is missing
Correct
(1/1) Point