Sie sind auf Seite 1von 20

Test: Semester 1 Mid Term Exam Part 1 Review your answers, feedback, and questio n scores below.

An asterisk (*) indica tes a correct answer. Section 1 (Answer a ll questions in this section) 1. SQL is a common access language for many types of databa ses, including Oracle. True or False? Mark for Review (1) Points True (*) False Correct 2. Which of the following statements about PL/SQL and SQL i Ma rk for Review s true? (1) Points PL/SQL and SQL are both ANSI-compliant. PL/SQL and SQL can be used with many typ es of databases, including Oracle. PL/SQL and SQL are both Oracle proprietary pr ogramming languages. PL/SQL allows basic program logic and control flow to be co mbined with SQL state ments. (*) Correct 3. A program which specifies a list of operations to be per formed sequentially to achieve the desired result can be ca lled: Mark fo r Review (1) Points declarative nondeclarative procedural (*) low level

Correct 4. Every PL/SQL anonymous block must start with the keyword DECLARE. Tru e or False? Mark for Review (1) Points True False (*) Correct 5. r Review (1) Po ints Anonymous Function (*) Provfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfv fvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfvfv fvfvfvfcedure Correct 6. 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 7. Whi ch statements are optional in a PL/SQL block? (Choose Mark for Review Which PL/S QL block type must return a value? Mark fo two.)

(1) Points (Choose all correct answers) DECLARE (*) BEGIN EXCEPTION (*) END; Cor rect 8. lock. True or False? (1) Points True (*) False Correct 9. What is the pu rpose of using DBMS_OUTPUT.PUT_LINE in a P Mark for Review Errors are handled in the Exception part of the PL/SQL b Mark for Review L/SQL block? (1) Points To perform conditional tests To allow a set of statements to be executed repeate dly To display results to check if our code is working correctly (*) To store ne w rows in the database Correct 10. Comparing PL/SQL with other languages such as C and Java , which of the following statements is true? Mark for Review (1) Poi nts PL/SQL is harder to learn

PL/SQL is easier to learn and more efficient (*) PL/SQL is easier to learn but l ess efficient PL/SQL is easier to learn and does not require an Oracle database or tool Correct PL/SQL and SQL can be used with many types of databases, including Oracle. PL/SQ L and SQL are both Oracle proprietary programming languages. PL/SQL allows basic program logic and control flow to be combined with SQL state ments. (*) Correct 3. A program which specifies a list of operations to be per formed sequentially to achieve the desired result can be called: Mark fo r Review (1) Points declar ative nondeclarative procedural (*) low level Correct 4. Every PL/SQL anonymous block must start with the keyword DECLARE. True or False? Mark for Review (1) Po ints True False (*)

Correct 5. r Review (1) Points Anonymous Function (*) Procedure Correct 6. Which lines of code will correctly display the message " The cat sat on the mat"? (Ch oose two.) Mark for Review (1) Points (Choose all correct answers) DBMS_OUTPUT.P UT_LINE('The cat sat on the mat'); (*) DBMS_OUTPUT.PUT_LINE(The cat sat on the m at); DBMS_OUTPUT.PUT_LINE('The cat' || 'sat on the mat'); DBMS_OUTPUT.PUT_LINE(' The cat sat ' || 'on the mat'); (*) Correct 7. Which statements are optional in a PL/SQL block? (Choose two.) Mark for Review (1) Points (Choose all correct ans wers) DECLARE (*) BEGIN EXCEPTION (*) END; Which PL/SQL block type must return a value? Mark fo

Correct 8. lock. True or False? (1) Points True (*) False Correct 9. What is the purpose of using DBMS_OUTPUT.PUT_LINE in a P Mark for Review Errors are handled in the Exception part of the PL/SQL b Mark for Review L/SQL block? (1) Points To perform conditional tests To allow a set of statements to be executed repeate dly To display results to check if our code is working correctly (*) To store ne w rows in the database Correct 10. Comparing PL/SQL with other languages such as C and Java , which of the following statements is true? Mark for Review (1) Poi nts PL/SQL is harder to learn PL/SQL is easier to learn and more efficient (*) P L/SQL is easier to learn but less efficient PL/SQL is easier to learn and does n ot require an Oracle database or tool Correct 11. The fact that PL/SQL is portab le is a good thing because: Mark for Review (1) Points

Exceptions can be ported to different operating systems Blocks can be sent to th e 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 C orrect 12. PL/SQL can be used not only with an Oracle database, but also with an y kind of relational database. True or False? Mark for Review (1) Points True Fa lse (*) Correct Section 2 (Answer all questions in this section) 13. Sing le row character functions are valid SQL functions in PL/SQL. True or False? Ma rk for Review (1) Points True (*) False Correct 14. The implicit data type conversion at Point A may not work correctl y. Why not? DECLARE v_mydate DATE; BEGIN V_MYDA TE := '29-Feb-04'; -- 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 strin g contains a valid date value If the database language is not English, 'Feb' has no meaning. (*) V_MYDATE has been entered in uppercase Incorr ect. Refer to Section 2 Lesson 5. 15. PL/SQL can convert a VARCHAR2 value contai ning alphabetic characte rs to a NUMBER value. True or False? Mark for Review (1 ) Points

True False (*) Correct 16. What is wrong with this assignment statement? myvar : = 'To be or not to be'; 'That is the question'; Mark for Review (1) Points An as signment 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 (*) "my var" is not a valid name for a variable Character literals should not be enclose d in quotes Incorrect. Refer to Section 2 Lesson 5. 17. Examine the following co de: 1 DECLARE 2 x NUMBER; 3 BEGIN 4 x:= '300'; 5 END; After line 4, what is the value of x? Mark for Review (1) Points '300' 300 (*) NULL Correct 18. 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(s ysdate) TO_DATE(sysdate,'Month DD, YYYY')

TO_CHAR(sysdate, 'Month DD, YYYY') (*) Correct 19. Examine the following code. W hat 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 20. Examine the following code. What is the final value of V_MYBOOL ? DE CLARE v_mynumber NUMBER; v_mybool BOOLEAN ; BEGIN v_mynumber := 6; v_mybool := ( v_mynumber BETWEEN 10 AND 20); v_mybool := NOT (v_mybool); END; Mark for Review (1) Points True (*) False Correct 21. A collection is a composite data type. Tru e or False? Mark for Review (1) Points True (*) False Correct 22. What is the da ta type of the variable V_DEPT_TABLE in the followin g declaration? DECLARE TYPE dept_table_type IS TABLE OF departments%ROWTYPE INDEX BY PLS_INTEGER; v_dep t_t able dept_table_type; ... Mark for Review (1) Points

Scalar Composite (*) LOB Correct 23. Which of these are PL/SQL data types? (Choo se three.) Mark for Re view (1) Points Scalar (*) Identifier Delimiter Composite (*) LOB (*) Correct 24. Is the following variable declaration correct or not ? DECLARE display_qty CONSTANT NUMBER; Mark for Review (1) Points Correct. Not cor rect. (*) Correct 25. Assignment statements can continue over several lines in P L/SQL. T rue or False? Mark for Review (1) Points True (*) False Incorrect. Refe r to Section 2 Lesson 1. 26. When a variable is defined using the CONSTANT keywo rd, the value o f the variable cannot change. True or False? Mark for Review (1) Points True (*) False (Choose all correct answers)

Correct 27. Identify which of the following assignment statements are valid. ( C hoose three.) Mark for Review (1) Points (Choose all correct answers) v_last_nam e := Chandra; v_blackout_date := '31-DEC-2006'; (*) v_population := 333444; (*) v_music_type := 'ROCK'; (*) Correct 28. Which good programming practice guidelin e would make this code eas ier to read? DECLARE v_sal NUMBER(8,2); BEGIN SELECT salary INTO v_sal FROM employees WHERE employee_id = 100; UPDATE employees SET s alary = v_sal; END; Mark for Review (1) Points Declaring variables using %TYPE I ndenting each level of code (*) Using a consistent naming convention for variabl es Avoiding implicit data type conversions Correct 29. Which of the following is an example of using a case convention fo r 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 handl er in every PL/SQL block. Correct 30. Which of these are examples of good progra mming practice? (Choose three.) Mark for Review (1) Points (Choose all correct a nswers)

Declare two variables on each line of code. Use a NOT NULL constraint when a var iable must have a value (*) Use a clear and consistent naming convention for var iables. (*) Declare variables with the same names as table columns. Do not rely on implicit data type conversions. (*) Correct 31. PL/SQL does not look ________ _ in the child blocks. Mark for Review (1) Points Inward Upward Outward Downward (*) Correct 32. Examine the following code. At Line A, we want to assign a valu e o f 22 to the outer block's variable v_myvar. What code should we write at Lin e A? <<outer_block>> DECLARE v_myvar NUMBER; BEGIN <<inner_block>> DECLARE v_myv ar NUMBER := 15; BEGIN -- Line A END; END; Mark for Review (1) Points outer_bloc k.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 s ame name Correct 33. In the following code, Line A causes an exception. What va lue will be displayed when the code is executed? DECLARE outer_var VARCHAR2(50) := 'My'; BEGIN outer_var := outer_var || ' name'; DECLARE inner_var NUMBER; BEGI N inner_var := 'Mehmet'; -- Line A outer_var := outer_var || ' is'; END; outer_v ar := outer_var || ' Zeynep'; EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE(ou ter_var); END; Mark for Review (1) Points My My name (*) My name is My name is Z eynep Correct 34. What will be displayed when the following code is executed? DE CLARE varA NUMBER := 12; BEGIN DECLARE varB NUMBER := 8; BEGIN varA := varA + va rB; END; DBMS_OUTPUT.PUT_LINE(varB); END; Mark for Review (1) Points 8 12 Nothin g, the block will fail with an error (*) 20

VarB Correct 35. When nested blocks are used, which blocks can or must be labele d? Mark for Review (1) Points The inner block must be labeled, the outer block c an be labeled. Both blocks must be labeled Nested blocks cannot be labeled The o uter block must be labeled if it is to be referred to in the inner block. ( *) C orrect 36. Which of the following can be assigned to a Boolean variable? 1. Null 2. False 3. True 4. 0 Mark for Review (1) Points 2 and 3 2, 3 and 4 1, 2 and 3 (*) 1, 2, 3 and 4 Correct 37. If you are using the %TYPE attribute, you can avoi d hard coding th e: Mark for Review (1) Points Data type (*) Table name Column n ame Constraint Correct 38. 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 N UMBER; (*) v_start_date DATE := sysdate+1; Correct 39. Valid identifiers begin w ith a Mark for Review (1) Points Number Letter (*) Special character Correct 40. Which of the following are valid identifiers? (Choose two.) Mark for Review (1) Points (Choose all correct answers) yesterday (*) yesterday's date number_of_st udents_in_the_class v$testresult (*) #students Correct 41. Delimiters are _____ that have special meaning to the Oracle database. Mar k for Review (1) Points id entifiers variables symbols (*) Correct Section 3 (Answer all questions in this section) 42. Ther e are no employees in Department 77. What will happen when the following block i s executed?

BEGIN DELETE FROM employees WHERE department_id=77; DBMS_OUTPUT.PUT_LINE(SQL%ROW COUNT) END; Mark for Review (1) Points A NO_DATA_FOUND exception is raised. A NU LL is displayed. A zero (0) is displayed. (*) An exception is raised because the block does not contain a COMMIT statement. Incorrect. Refer to Section 3 Lesson 3. 43. Which SQL statement can NOT use an implicit cursor? Mark for Revi ew (1) Points A DELETE statement An UPDATE statement A SELECT statement that returns m ultiple rows (*) A SELECT statement that returns one row Correct 44. Which is th e correct way to erase one row from a table? Mark for Review (1) Points REMOVE e mployee_id=100 FROM employees; DROP TABLE employees WHERE employee_id=100; TRUNC ATE employees WHERE employee_id=100; DELETE FROM employees WHERE employee_id=100 ; (*) Correct 45. 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; UPDAT E employees SET last_name='Smith'; (*) DROP TABLE employees; Correct 46. A varia ble is declared as: DECLARE v_holdit employees.last_name%TYPE; BEGIN ... Which o f the following is a correct use of the INTO clause? Mark for Review (1) Points SELECT * INTO v_holdit FROM employees; SELECT last_name INTO v_holdit FROM emplo yees; SELECT last_name INTO v_holdit FROM employees WHERE employee_id=100; (*) S ELECT salary INTO v_holdit FROM employees WHERE employee_id=100; Correct 47. Whi ch of the following is NOT a good guideline for retrieving data in PL/SQL? Mark for Review (1) Points Declare the receiving variables using %TYPE The WHERE clau se is optional in nearly all cases. (*) Specify the same number of variables in the INTO clause as database columns in t he SELECT clause.

THE SELECT statement should fetch exactly one row. Correct 48. Which one of thes e SQL statements can be directly included in a PL /SQL executable block? Mark fo r Review (1) Points DELETE FROM employees WHERE department_id=60; (*) SELECT sal ary FROM employees WHERE department_id=60; CREATE TABLE new_emps (last_name VARC HAR2(10), first_name VARCHAR2(10)); DROP TABLE locations; Correct 49. The follow ing anonymous block of code is run: BEGIN INSERT INTO countries (id, name) VALUE S ('XA', 'Xanadu'); SAVEPOINT XA; INSERT INTO countries (id, name) VALUES ('NV', 'Neverland'); COMMIT; ROLLBACK TO XA; END; What happens when the block of code f inishes? Mark for Review (1) Points 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. (*) Correct 50. The following anonymo us block of code is run: BEGIN INSERT INTO countries (id, name) VALUES ('XA', 'X anadu'); INSERT INTO countries (id, name) VALUES ('NV','Neverland'); COMMIT; COM MIT; ROLLBACK; END; What happens when the block of code finishes?

Mark for Review (1) Points You have nothing new; the last ROLLBACK undid the INS ERTs. You have the rows added twice; there are four new rows. You have the two n ew rows added. (*) You get an error; you cannot COMMIT twice in a row. Correct