0% found this document useful (0 votes)
486 views9 pages

PLSQL Semestar1 MidTerm Sa Resenjima

The document contains questions and answers about PL/SQL programming concepts. Some key points covered include: - PL/SQL extends SQL with procedural programming features like conditional control and iterative control. - Variables are declared in the declarative section of a PL/SQL block and their data types determine allowed values and operations. - Implicit data conversions can cause problems if conversion rules change, so explicit conversions are preferable. - DML statements like INSERT, UPDATE, DELETE can be used within transactions to group multiple changes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
486 views9 pages

PLSQL Semestar1 MidTerm Sa Resenjima

The document contains questions and answers about PL/SQL programming concepts. Some key points covered include: - PL/SQL extends SQL with procedural programming features like conditional control and iterative control. - Variables are declared in the declarative section of a PL/SQL block and their data types determine allowed values and operations. - Implicit data conversions can cause problems if conversion rules change, so explicit conversions are preferable. - DML statements like INSERT, UPDATE, DELETE can be used within transactions to group multiple changes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 9

1. Using Oracle Application Express, you can create Web applications that include PL/SQL. True or False?

 TRUE (*)
 FALSE

2. You can create a Web site application written entirely in PL/SQL. True or False?
 True
 False (*)

3. Which of the following statements is true?


 You can embed PL/SQL statements within SQL code.
 You can embed procedural constructs within SQL code.
 You can embed SQL statements within PL/SQL code. (*)
 None of these are correct.

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.

5. In which part of the PL/SQL block are declarations of variables defined?


 Definition
 Declarative (*)
 Executable
 Exception

6. This PL/SQL anonymous block will execute successfully. True or False?


DECLARE
v_date DATE := SYSDATE;
DBMS_OUTPUT.PUT_LINE(v_date);
END;
 True
 False (*)

7. Which of the following is a PL/SQL programming environment?


 PL/SQL Express
 Oracle Cdeveloper
 SQL*Workshop in Application Express (*)
 Java*Plus

8. In a PL/SQL block, which of the following should not be followed by a semicolon?


 END
 DECLARE (*)
 All PL/SQL statements
 All SQL statements

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 (*)

15. What is wrong with this code?


DECLARE
v_a NUMBER;
BEGIN
v_a := 27;
<<inner_block>>
BEGIN
v_a := 15;
END;
 Nothing is wrong, the code will execute successfully.
 Variable v_a is out of scope within the inner block and therefore cannot be referenced.
 The inner block has no END; statement. (*)
 The outer block has no label.
16. If a variable is defined with the same name in both an inner and outer block, and referenced in the outer block, it will
reference the ___________ block value of the variable.
 Inner
 Neither - can't define a variable with the same name in both blocks
 Outer (*)

17. PL/SQL does not look _________ in the child blocks.


 Downward (*)
 Inward
 Upward
 Outward

18. Which of the following are PL/SQL lexical units? (Choose two.)
 SQL Workshop
 Anonymous Blocks
 Reserved Words (*)
 Table Columns
 Identifiers (*)

19. What is a lexical unit?


 A type of variable
 A building block of a PL/SQL block (*)
 A data type for a column

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

21. Is the following variable declaration correct or not?


DECLARE
maxsalary NUMBER(7) = 5000;
 Correct.
 Not correct. (*)

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 (*)

27. A variable is declared as:


DECLARE
v_holdit employees.last_name%TYPE;
BEGIN ...
Which of the following is a correct use of the INTO clause?

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;

28. What will happen when the following block is executed?


DECLARE
v_last employees.last_name%TYPE;
v_first employees.first_name%TYPE;
v_salary employees.salary%TYPE;
BEGIN
SELECT first_name, last_name
INTO v_first, v_last, v_salary
FROM employees WHERE employee_id=100;
END;
 The block will fail because V_LAST was declared before V_FIRST.
 The block will fail because the SELECT statement returns more than one row.
 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.

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.

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


 As many as needed (*)
 Only one
 A maximum of four DML statements
 None. A transaction cannot include DML statements.

31. 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 an error occurs.
 Two rows are inserted. (*)
 No data is inserted.
 One record of data is inserted.

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

38. Examine the following code:


BEGIN
FOR i IN 1..5 LOOP
FOR j IN 1..8 LOOP
EXIT WHEN j = 7;
DBMS_OUTPUT.PUT_LINE(i || j);
END LOOP;
END LOOP;
END;
How many lines of output will be displayed when this code is executed?
 30 (*)
 35
 6
 40
39. Examine the following code:
DECLARE
v_score NUMBER(3);
v_grade CHAR(1);
BEGIN
CASE v_score
-- Line A
....
The CASE statement 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?
 WHEN 90 THEN v_grade = 'A'
 WHEN 90 THEN v_grade := 'A'; (*)
 WHEN 90 THEN 'A'
 WHEN 90 THEN 'A';

40. Look at the following code:


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?
 False
 An error will occur because you cannot combine two Boolean variables using "NOT".
 True (*)
 NULL

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

42. Examine the following code:


DECLARE
a BOOLEAN := TRUE;
b BOOLEAN := FALSE;
c BOOLEAN := TRUE;
d BOOLEAN := FALSE;
game char(4) := 'lost';
BEGIN
IF ((a AND b) AND (c OR d))
THEN game := 'won'; END IF;
What is the value of GAME at the end of this block?
 won
 NULL
 lost (*)
 False
43. Name three types of control structures in PL/SQL. (Choose three)
 SELECT statements
 EXCEPTIONS
 LOOP statements (*)
 CASE statements (*)
 IF statements (*)

44. What will be displayed when this block is executed?


DECLARE
v_bool1 BOOLEAN := TRUE;
v_bool2 BOOLEAN;
v_char VARCHAR(4) := 'up';
BEGIN
IF (v_bool1 AND v_bool2) THEN
v_char:='down';
ELSE v_char:='left';
END IF;
DBMS_OUTPUT.PUT_LINE(v_char);
END;
 null
 up
 down
 left (*)

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 (*)

49. A PL/SQL block contains the following code:


v_counter := 1;
LOOP
EXIT WHEN v_counter=5;
END LOOP;
v_counter := v_counter + 1;
What is the value of V_COUNTER after the loop is finished?
 6
 5
 This is an infinite loop; the loop will never finish. (*)
 1

50. Look at this code:


DECLARE
v_bool BOOLEAN := TRUE;
v_date DATE;
BEGIN
LOOP
EXIT WHEN v_bool;
SELECT SYSDATE INTO v_date FROM dual;
END LOOP;
END;
How many times will the SELECT statement execute?
 An infinite number of times because the EXIT condition will never be true
 Twice
 Once
 Never (the SELECT will not execute at all) (*)

You might also like