postgresql Database Quiz Questions

Course Name:postgresql
Chapter Name:Chapter 9 - Advanced Topics
Lesson Content Link:postgresql Stored Procedure
Current Quiz Count:30
Progress
0%
Q1
True / False

In postgresql, a stored procedure is a named PL/SQL block that performs one or more specific tasks.

Q2
True / False

In postgresql, stored procedures can accept input parameters.

Q3
True / False

In postgresql, stored procedures can be called from within other stored procedures.

Q4
True / False

In postgresql, a stored procedure cannot return a value to the caller.

Q5
True / False

In postgresql, stored procedures must be compiled before they can be executed.

Q6
True / False

In postgresql, you can create a stored procedure that performs a DML operation without committing the transaction.

Q7
True / False

In postgresql, stored procedures can handle exceptions using the EXCEPTION block.

Q8
True / False

In postgresql, stored procedures can be created within packages for better organization and encapsulation.

Q9
True / False

In postgresql, you can create a stored procedure to execute dynamic SQL statements.

Q10
True / False

In postgresql, a stored procedure with an IN OUT parameter allows the caller to pass a value to the procedure and get an updated value back.

Q11
Multiple Choice

Identify the SQL statements that correctly create a basic stored procedure in postgresql.

SQL Code
CREATE OR REPLACE PROCEDURE increase_salary
(p_employee_id NUMBER, p_increment NUMBER)
IS BEGIN
 UPDATE employees
 SET salary = salary + p_increment
 WHERE employee_id = p_employee_id;
END;
Q12
Multiple Choice

Select the SQL statements that correctly create a stored procedure with output parameters in postgresql.

Q13
Multiple Choice

Determine the SQL statements that demonstrate the creation of a stored procedure with an IN OUT parameter in postgresql.

Q14
Multiple Choice

Identify the SQL statements that correctly demonstrate exception handling within a stored procedure in postgresql.

Q15
Multiple Choice

Choose the SQL statements that correctly create a stored procedure with a cursor in postgresql.

Q16
Multiple Choice

Which SQL statements demonstrate the creation of an autonomous transaction in a stored procedure in postgresql?

Q17
Multiple Choice

Determine the SQL statements that correctly create a stored procedure with a dynamic SQL query in postgresql.

Q18
Multiple Choice

Identify the SQL statements that correctly create a stored procedure with a nested procedure in postgresql.

Q19
Multiple Choice

Choose the SQL statements that correctly create a stored procedure with a loop in postgresql.

Q20
Multiple Choice

Select the SQL statements that demonstrate the creation of a stored procedure with conditional logic in postgresql.

Q21
Single Choice

How would you create a stored procedure in postgresql to update the salary of an employee?

SQL Code
CREATE OR REPLACE PROCEDURE update_salary (
 emp_id IN NUMBER,
 new_salary IN NUMBER
) IS
BEGIN
 UPDATE employees SET salary = new_salary WHERE employee_id = emp_id;
END;
Q22
Single Choice

Which keyword is used to pass a parameter by reference in an postgresql stored procedure?

SQL Code
CREATE OR REPLACE PROCEDURE update_bonus (
 emp_id IN NUMBER,
 bonus OUT NUMBER
) IS
BEGIN
 SELECT bonus INTO bonus FROM employees WHERE employee_id = emp_id;
END;
Q23
Single Choice

How would you handle exceptions in an postgresql stored procedure?

SQL Code
CREATE OR REPLACE PROCEDURE handle_error (
 emp_id IN NUMBER
) IS
BEGIN
 UPDATE employees SET salary = salary * 1.10 WHERE employee_id = emp_id;
EXCEPTION
 WHEN NO_DATA_FOUND THEN
 DBMS_OUTPUT.PUT_LINE('Employee not found');
END;
Q24
Single Choice

What is the purpose of the RETURN clause in a stored procedure?

SQL Code
CREATE OR REPLACE FUNCTION calculate_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;
END;
Q25
Single Choice

How would you create a stored procedure that includes a cursor to iterate over multiple rows?

SQL Code
CREATE OR REPLACE PROCEDURE update_all_salaries IS
 CURSOR emp_cursor IS SELECT employee_id, salary FROM employees;
BEGIN
 FOR emp_record IN emp_cursor LOOP
 UPDATE employees SET salary = salary * 1.05 WHERE employee_id = emp_record.employee_id;
 END LOOP;
END;
Q26
Single Choice

How can you modify an existing stored procedure to add an additional parameter?

SQL Code
CREATE OR REPLACE PROCEDURE update_employee_details (
 emp_id IN NUMBER,
 new_name IN VARCHAR2,
 new_salary IN NUMBER
) IS
BEGIN
 UPDATE employees SET employee_name = new_name, salary = new_salary WHERE employee_id = emp_id;
END;
Q27
Single Choice

What is the purpose of using the IN OUT parameter in a stored procedure?

SQL Code
CREATE OR REPLACE PROCEDURE adjust_salary (
 emp_id IN NUMBER,
 salary_adjustment IN OUT NUMBER
) IS
BEGIN
 SELECT salary INTO salary_adjustment FROM employees WHERE employee_id = emp_id;
 salary_adjustment := salary_adjustment * 1.10;
END;
Q28
Single Choice

How would you create a stored procedure to delete a record from a table based on a condition?

SQL Code
CREATE OR REPLACE PROCEDURE delete_employee (
 emp_id IN NUMBER
) IS
BEGIN
 DELETE FROM employees WHERE employee_id = emp_id;
END;
Q29
Single Choice

What is the best way to handle transactions within a stored procedure?

SQL Code
CREATE OR REPLACE PROCEDURE process_order (
 order_id IN NUMBER
) IS
BEGIN
 UPDATE orders SET status = 'Processed' WHERE order_id = order_id;
 COMMIT;
EXCEPTION
 WHEN OTHERS THEN
 ROLLBACK;
END;
Q30
Single Choice

How would you create a stored procedure that accepts multiple parameters and returns a result set?

SQL Code
CREATE OR REPLACE PROCEDURE get_employee_details (
 emp_id IN NUMBER,
 emp_name OUT VARCHAR2,
 emp_salary OUT NUMBER
) IS
BEGIN
 SELECT employee_name, salary INTO emp_name, emp_salary FROM employees WHERE employee_id = emp_id;
END;