PLSQL Semestar1 MidTerm Sa Resenjima
PLSQL Semestar1 MidTerm Sa Resenjima
PLSQL Semestar1 MidTerm Sa Resenjima
TRUE (*)
FALSE
2. You can create a Web site application written entirely in PL/SQL. True or False?
True
False (*)
4. In which three ways does PL/SQL extend the SQL programming language? (Choose three)
By adding procedural constructs. (*)
By adding conditional control. (*)
By adding iterative control. (*)
By adding compound constructs.
9. Which of the following is an example of using a case convention for good programming practice?
Assign variables by using functions.
Declare data types in uppercase. (*)
Declare variables in the DECLARE section.
Include an exception handler in every PL/SQL block.
10. 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;
Declaring variables using %TYPE
Indenting each level of code (*)
Using a consistent naming convention for variables
Avoiding implicit data type conversions
11. What are the data types of the variables in the following declaration?
DECLARE
fname VARCHAR2(25);
lname VARCHAR2(25) DEFAULT 'fernandez';
BEGIN …
Composite
Scalar (*)
LOB
PLS_INTEGER
12. Type of a variable determines the range of values the variable can have and the set of operations that are defined for
values of the type.
True (*)
False
13. Which of the following variable declarations does NOT use a number data type?
v_count BINARY_INTEGER;
v_count PLS_INTEGER := 0;
v_students LONG; (*)
v_median_age NUMBER(6,2);
14. If you use the %TYPE attribute, you can avoid hard-coding the column name. True or False?
True
False (*)
18. Which of the following are PL/SQL lexical units? (Choose two.)
SQL Workshop
Anonymous Blocks
Reserved Words (*)
Table Columns
Identifiers (*)
20. When a variable is defined using the NOT NULL keywords, the variable must contain a value. True or False?
True (*)
False
22. Which of the following are required when declaring a variable? (Choose two.)
Identifier name (*)
CONSTANT
NOT NULL
Data type (*)
23. Explicit conversions can be slower than implicit conversions. True or False?
True
False (*)
24. The DECODE function is available in PL/SQL procedural statements. True or False?
True
False (*)
25. 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
26. Which of the following are disadvantages of implicit data type conversions? (Choose two.)
Oracle cannot implicitly convert a number value to a character string
If Oracle changes the conversion rules in the future, your code may not work any more (*)
You cannot store alphabetic characters in a variable of data type NUMBER
The code is harder to read and understand (*)
SELECT *
INTO v_holdit
FROM employees;
SELECT last_name
INTO v_holdit
FROM employees
WHERE employee_id=100; (*)
SELECT last_name
INTO v_holdit
FROM employees;
SELECT salary
INTO v_holdit
FROM employees
WHERE employee_id=100;
The block will execute successfully, and the V_SALARY variable will be set to NULL.
29. 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 in the table.
No rows. (*)
All rows whose SALARY column value is greater than 12000.
All rows whose SALARY column value is equal to 12000.
32. There are three employees in department 90. What will be displayed when the following code is executed?
DECLARE
v_open CHAR(3) := 'NO';
BEGIN
UPDATE employees SET job_id = 'ST_CLERK'
WHERE department_id = 90;
IF SQL%FOUND THEN
v_open := 'YES';
END IF;
DBMS_OUTPUT.PUT_LINE(v_open || ' ' || SQL%ROWCOUNT);
END;
Nothing will be displayed. The block will fail because you cannot use implicit cursor attributes directly in
a call to DBMS_OUTPUT.PUT_LINE.
NO 3
YES 1
YES 3 (*)
33. 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.
An exception is raised because the UPDATE statement did not modify any rows.
No rows are updated but the block completes successfully.
Every employee row is updated. (*)
34. Assume there are 5 employees in Department 10. What happens when the following statement is executed?
UPDATE employees
SET salary=salary*1.1;
No rows are modified because you did not specify "WHERE department_id=10"
A TOO_MANY_ROWS exception is raised.
All employees get a 10% salary increase. (*)
An error message is displayed because you must use the INTO clause to hold the new salary.
35. Is it possible to insert more than one row at a time using an INSERT statement with a VALUES clause?
No, there is no such thing as INSERT ... VALUES.
No, you can only create one row at a time when using the VALUES clause. (*)
Yes, you can list as many rows as you want, just remember to separate the rows with commas.
36. The MERGE statement will INSERT or DELETE rows in a target table based on matching values in a source table. True
or False?
True
False (*)
37. What type of loop statement would you write for Point A?
BEGIN
FOR v_outerloop IN 1..3 LOOP
-- Point A
DBMS_OUTPUT.PUT_LINE('Outer loop is:'||v_outerloop||
' and inner loop is: '||v_innerloop);
END LOOP;
END LOOP;
END;
WHILE v_outerloop
FOR v_innerloop IN 1..5 LOOP (*)
LOOP
WHILE v_innerloop <=5 LOOP
41. What type of control structures are repetition statements that enable you to execute statements in a PLSQL block
repeatedly?
IF statements
CASE expressions
Loops (*)
CASE statements
45. When using a counter to control a FOR loop, which of the following is true ?
You must have exactly one counter but it is implicitly declared. (*)
You can have multiple counters, but you need at least one.
You must have exactly one counter and you must explicitly declare it.
You don't need a counter; you can test for anything (for example, whether a BOOLEAN is TRUE or FALSE).
46. In a WHILE loop, the controlling condition is checked at the start of each iteration. True or False?
True (*)
False
47. Which statement best describes when a FOR loop should be used?
When the number of iterations is known (*)
When testing the value in a Boolean variable
When the controlling condition must be evaluated at the start of each iteration
48. How many EXIT statements can be coded inside a basic loop?
One only
None
Two
As many as you need, there is no limit (*)