Oracle Database Quiz Questions

Course Name:Oracle
Chapter Name:Chapter 9 - Advanced Topics
Lesson Content Link:DB Function
Current Quiz Count:30
Progress
0%
Q1
True / False

In ORACLE, a function is a named PL/SQL block that returns a single value.

Q2
True / False

In ORACLE, functions can be used in SQL statements, such as SELECT or WHERE clauses.

Q3
True / False

In ORACLE, functions cannot accept parameters.

Q4
True / False

In ORACLE, a function must include a RETURN clause that specifies the data type of the returned value.

Q5
True / False

In ORACLE, functions can only perform read operations and cannot modify database data.

Q6
True / False

In ORACLE, functions can be used to encapsulate reusable logic and improve code modularity.

Q7
True / False

In ORACLE, a function can be part of a package to group related functions together.

Q8
True / False

In ORACLE, a function can be overloaded, meaning multiple functions can have the same name but different parameters.

Q9
True / False

In ORACLE, a function that modifies data must be declared with the PRAGMA AUTONOMOUS_TRANSACTION directive to avoid affecting the calling transaction.

Q10
True / False

In ORACLE, a function used in a SELECT statement should not perform DML operations to ensure it does not cause side effects.

Q11
Multiple Choice

Identify the SQL statements that correctly create a basic function in Oracle.

SQL Code
CREATE OR REPLACE FUNCTION calculate_bonus
(p_salary NUMBER)
RETURN NUMBER
IS BEGIN
 RETURN p_salary * 0.10;
END;
Q12
Multiple Choice

Select the SQL statements that correctly create a function with input parameters in Oracle.

Q13
Multiple Choice

Determine the SQL statements that demonstrate the creation of a function with a SELECT statement in Oracle.

Q14
Multiple Choice

Identify the SQL statements that correctly demonstrate exception handling within a function in Oracle.

Q15
Multiple Choice

Choose the SQL statements that correctly create a function with a cursor in Oracle.

Q16
Multiple Choice

Which SQL statements demonstrate the creation of a function that returns a PL/SQL collection in Oracle?

Q17
Multiple Choice

Determine the SQL statements that correctly create a function with dynamic SQL in Oracle.

Q18
Multiple Choice

Identify the SQL statements that correctly create a recursive function in Oracle.

Q19
Multiple Choice

Choose the SQL statements that correctly create a function with a PRAGMA AUTONOMOUS_TRANSACTION directive in Oracle.

Q20
Multiple Choice

Select the SQL statements that demonstrate the creation of a function that performs a complex calculation in Oracle.

Q21
Single Choice

How would you create a DB function to calculate the annual salary of an employee based on their monthly salary?

SQL Code
CREATE OR REPLACE FUNCTION calculate_annual_salary (
 monthly_salary IN NUMBER
) RETURN NUMBER IS
BEGIN
 RETURN monthly_salary * 12;
END;
Q22
Single Choice

Which clause is mandatory in a DB function to specify the datatype of the returned value?

SQL Code
CREATE OR REPLACE FUNCTION get_employee_name (
 emp_id IN NUMBER
) RETURN VARCHAR2 IS
 emp_name VARCHAR2(100);
BEGIN
 SELECT employee_name INTO emp_name FROM employees WHERE employee_id = emp_id;
 RETURN emp_name;
END;
Q23
Single Choice

How would you handle an exception within a DB function?

SQL Code
CREATE OR REPLACE FUNCTION get_bonus (
 emp_id IN NUMBER
) RETURN NUMBER IS
 bonus NUMBER;
BEGIN
 SELECT salary * 0.10 INTO bonus FROM employees WHERE employee_id = emp_id;
 RETURN bonus;
EXCEPTION
 WHEN NO_DATA_FOUND THEN
 RETURN 0;
END;
Q24
Single Choice

Which of the following is true about a DB function that has OUT parameters?

SQL Code
CREATE OR REPLACE FUNCTION calculate_bonus (
 emp_id IN NUMBER, bonus OUT NUMBER
) RETURN NUMBER IS
 emp_salary NUMBER;
BEGIN
 SELECT salary INTO emp_salary FROM employees WHERE employee_id = emp_id;
 bonus := emp_salary * 0.10;
 RETURN emp_salary;
END;
Q25
Single Choice

How would you create a DB function that performs a calculation based on input parameters and returns the result?

SQL Code
CREATE OR REPLACE FUNCTION calculate_discount (
 original_price IN NUMBER, discount_rate IN NUMBER
) RETURN NUMBER IS
BEGIN
 RETURN original_price * (1 - discount_rate/100);
END;
Q26
Single Choice

How would you create a DB function that can be used in a SELECT statement?

SQL Code
CREATE OR REPLACE FUNCTION get_employee_department (
 emp_id IN NUMBER
) RETURN VARCHAR2 IS
 dept_name VARCHAR2(50);
BEGIN
 SELECT department_name INTO dept_name FROM departments d JOIN employees e ON d.department_id = e.department_id WHERE e.employee_id = emp_id;
 RETURN dept_name;
END;
Q27
Single Choice

What is the best way to ensure that a DB function executes only if a certain condition is met?

SQL Code
CREATE OR REPLACE FUNCTION get_manager_name (
 emp_id IN NUMBER
) RETURN VARCHAR2 IS
 manager_name VARCHAR2(100);
BEGIN
 IF emp_id IS NOT NULL THEN
 SELECT e.manager_name INTO manager_name FROM employees e WHERE e.employee_id = emp_id;
 ELSE
 RETURN 'Unknown';
 END IF;
 RETURN manager_name;
END;
Q28
Single Choice

How would you return multiple values from a DB function?

SQL Code
CREATE OR REPLACE FUNCTION get_employee_details (
 emp_id IN NUMBER
) RETURN employee_record IS
 emp_details employee_record;
BEGIN
 SELECT employee_name, salary INTO emp_details.employee_name, emp_details.salary FROM employees WHERE employee_id = emp_id;
 RETURN emp_details;
END;
Q29
Single Choice

How can a DB function be used to perform a complex calculation involving multiple steps?

SQL Code
CREATE OR REPLACE FUNCTION calculate_final_grade (
 exam_score IN NUMBER, project_score IN NUMBER
) RETURN NUMBER IS
 total_score NUMBER;
 final_grade NUMBER;
BEGIN
 total_score := exam_score + project_score;
 IF total_score >= 90 THEN
 final_grade := 'A';
 ELSIF total_score >= 80 THEN
 final_grade := 'B';
 ELSE
 final_grade := 'C';
 END IF;
 RETURN final_grade;
END;
Q30
Single Choice

What is the purpose of using a deterministic DB function in Oracle?

SQL Code
CREATE OR REPLACE FUNCTION get_tax_rate (
 region IN VARCHAR2
) RETURN NUMBER DETERMINISTIC IS
BEGIN
 RETURN CASE region WHEN 'US' THEN 0.07 WHEN 'EU' THEN 0.20 ELSE 0.15 END;
END;