Test: Quiz: Using Functions in SQL Statements: Section 1
Test: Quiz: Using Functions in SQL Statements: Section 1
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 1
(Answer all questions in this section) 1. User-defined functions can extend the power of SQL statements where Oracle does not provide ready-made functions such as UPPER and LOWER. True or False? True (*) False Correct 2. Function DOUBLE_SAL has been created as follows: CREATE OR REPLACE FUNCTION double_sal (p_salary IN employees.salary%TYPE) RETURN NUMBER IS BEGIN RETURN(p_salary * 2); END; Which of the following calls to DOUBLE_SAL will NOT work? SELECT * FROM employees WHERE double_sal(salary) > 20000; SELECT * FROM employees ORDER BY double_sal(salary) DESC; UPDATE employees SET salary = double_sal(salary); SELECT last_name, double_sal(salary) FROM employees; None of the above; they will all work (*) Correct 3. Which of the following is NOT a legal location for a function call in a SQL statement? FROM clause of a SELECT statement (*) WHERE clause in a DELETE statement SET clause of an UPDATE statement VALUES clause of an INSERT statement Correct 4. The following function has been created: CREATE OR REPLACE FUNCTION upd_dept (p_dept_id IN departments.department_id%TYPE) RETURN NUMBER IS BEGIN UPDATE departments SET department_name = 'Accounting' WHERE department_id = p_dept_id; RETURN p_dept_id; Mark for Review (1) Points Mark for Review (1) Points Mark for Review (1) Points Mark for Review (1) Points
END; Which of the following will execute successfully? DELETE FROM departments WHERE department_id = upd_dept(department_id); SELECT upd_dept(department_id) FROM employees; DELETE FROM employees WHERE department_id = upd_dept(80); (*) SELECT upd_dept(80) FROM dual; Correct 5. Which of the following is NOT a benefit of user-defined functions? Mark for Review (1) Points
They can add business rules to the database and can be reused many times. They can be used in a WHERE clause to filter data. They can do the same job as built-in system functions such as UPPER and ROUND. (*) They can often be used inside SQL statements. Correct 6. You want to create a function which can be used in a SQL statement. Which one of the following can be coded within your function? RETURN BOOLEAN One or more IN parameters (*) An OUT parameter COMMIT; Correct Page 1 of 1 Mark for Review (1) Points