0% found this document useful (0 votes)
259 views6 pages

Section 3 (Quiz)

The quiz covers SQL statements like INSERT, UPDATE, DELETE and the implicit cursor attributes in PL/SQL. Some key points: - When using INSERT...VALUES, you can insert multiple rows by separating the row values with commas, but the column values must match the column list. - A DELETE statement without a WHERE clause will delete all rows from the table. - In PL/SQL, the SQL%ROWCOUNT attribute identifies the number of rows affected by DML statements like UPDATE and DELETE. - When no rows match the WHERE clause, like deleting from a table with no rows for a given department, SQL%ROWCOUNT will display 0.

Uploaded by

ashishishu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
259 views6 pages

Section 3 (Quiz)

The quiz covers SQL statements like INSERT, UPDATE, DELETE and the implicit cursor attributes in PL/SQL. Some key points: - When using INSERT...VALUES, you can insert multiple rows by separating the row values with commas, but the column values must match the column list. - A DELETE statement without a WHERE clause will delete all rows from the table. - In PL/SQL, the SQL%ROWCOUNT attribute identifies the number of rows affected by DML statements like UPDATE and DELETE. - When no rows match the WHERE clause, like deleting from a table with no rows for a given department, SQL%ROWCOUNT will display 0.

Uploaded by

ashishishu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

SECTION 3 (QUIZ)

Section 3

1. 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, ....);

Mark for Review

(1) Points
Nothing is wrong, the statement will execute correctly.
The SET clause is trying to update the source table from the target table. (*)
The UPDATE clause must include the target table name: UPDATE emps SET ....
The INSERT clause must include a column list as well as a list of column values.
Correct

2. Is it possible to insert more than one row at a time using an INSERT statement with a
VALUES clause?
Mark for Review

(1) Points
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.
No, there is no such thing as INSERT ... VALUES.
Incorrect. Refer to Section 3 Lesson 1.

3. What would be the result of the following statement: DELETE FROM employees;
Mark for Review

(1) Points
The row with EMPOYEE_ID=100 will be deleted.
Nothing, no data will be changed.
The statement will fail because it contains a syntax error.
All rows in the employees table will be deleted. (*)
Incorrect. Refer to Section 3 Lesson 1.

4. To modify an existing row in a table, you can use the ________ statement.
Mark for Review

(1) Points
ALTER
MODIFY
UPDATE (*)
INSERT
Incorrect. Refer to Section 3 Lesson 1.

5. The following table has been created:

CREATE TABLE student_table


(stud_id NUMBER(6),
last_name VARCHAR2(20),
first_name VARCHAR2(20),
lunch_num NUMBER(4));
Which one of the following INSERT statements will fail?

Mark for Review

(1) Points
INSERT INTO student_table (stud_id, last_name, lunch_num)
VALUES (143354, 'Roberts', 6543, 'Cameron'); (*)
INSERT INTO student_table (stud_id, last_name, first_name, lunch_num)
VALUES (143354, 'Roberts', 'Cameron', 6543);
INSERT INTO student_table
VALUES (143354, 'Roberts', 'Cameron', 6543);
INSERT INTO student_table (stud_id, lunch_num, first_name, last_name)
VALUES (143352, 6543, 'Cameron', 'Roberts');
Incorrect. Refer to Section 3 Lesson 1.

6. The following anonymous block of code is run:

BEGIN
INSERT INTO countries (id, name)
VALUES ('XA', 'Xanadu');
INSERT INTO countries (id, name)
VALUES ('NV','Neverland');
COMMIT;
COMMIT;
ROLLBACK;
END;

What happens when the block of code finishes?

Mark for Review

(1) Points
You get an error; you cannot COMMIT twice in a row.
You have the rows added twice; there are four new rows.
You have the two new rows added. (*)
You have nothing new; the last ROLLBACK undid the INSERTs.
Incorrect. Refer to Section 3 Lesson 4.

7. How many INSERTs can you have in one transaction?


Mark for Review

(1) Points
One
As many as you can execute before the database does an AUTOSAVE.
As many as you want until a different DML statement (UPDATE, DELETE or MERGE) is
executed.
As many as you want until you do a COMMIT or ROLLBACK. (*)
Correct

8. Which of the following is NOT a good guideline for retrieving data in PL/SQL?
Mark for Review

(1) Points
The WHERE clause is optional in nearly all cases. (*)
Specify the same number of variables in the INTO clause as database columns in the
SELECT clause.
Declare the receiving variables using %TYPE
THE SELECT statement should fetch exactly one row.
Incorrect. Refer to Section 3 Lesson 2.

9. It is good programming practice to create identifiers having the same name as column
names. True or False?
Mark for Review

(1) Points
True
False (*)
Incorrect. Refer to Section 3 Lesson 2.

10. 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;

Mark for Review

(1) Points
All rows whose SALARY column value is greater than 12000.
No rows. (*)
All rows whose SALARY column value is equal to 12000.
All rows in the table.
Incorrect. Refer to Section 3 Lesson 2.

11. 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?

Mark for Review

(1) Points
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;
SELECT *
INTO v_holdit
FROM employees;
Incorrect. Refer to Section 3 Lesson 2.

12. Which one of these SQL statements can be directly included in a PL/SQL executable
block?
Mark for Review

(1) Points
UPDATE employees
SET last_name='Smith'; (*)
DESCRIBE employees;
DROP TABLE employees;
SELECT last_name FROM employees
WHERE employee_id=100;
Incorrect. Refer to Section 3 Lesson 2.

13. Which implicit cursor attribute identifies the number of rows updated in the following
statement?


DBMS_OUTPUT.PUT_LINE(__________ || ' rows updated.');

Mark for Review

(1) Points
SQL%COUNT
SQLROW%COUNT
SQL%ROWCOUNT (*)
SQL%NUMBER
Incorrect. Refer to Section 3 Lesson 3.

14. Assume there are 5 employees in Department 10. What happens when the following
statement is executed?

UPDATE employees
SET salary=salary*1.1;

Mark for Review


(1) Points
All employees get a 10% salary increase. (*)
A TOO_MANY_ROWS exception is raised.
No rows are modified because you did not specify "WHERE department_id=10"
An error message is displayed because you must use the INTO clause to hold the new salary.

Incorrect. Refer to Section 3 Lesson 3.

15. 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;

Mark for Review

(1) Points
A NULL is displayed.
An exception is raised because the block does not contain a COMMIT statement.
A NO_DATA_FOUND exception is raised.
A zero (0) is displayed. (*)
Incorrect. Refer to Section 3 Lesson 3.

You might also like