1. What does PL/SQL stand for?
ANS : (a) PL/SQL is an extension of SQL that includes procedural programming constructs like loops, conditions, and exception handling.
2. Which of the following is NOT a PL/SQL unit?
ANS : (c) Cursors are used to fetch query results row by row but are not standalone PL/SQL units like procedures, triggers, and functions.
3. Which of the following is a valid PL/SQL data type?
ANS : (d) PL/SQL supports various data types, including CHAR for character data, BOOLEAN for true/false values, and NUMBER for numeric data.
4. What is the default mode of a parameter in a PL/SQL procedure?
ANS : (a) The default mode of a parameter in a PL/SQL procedure is IN, meaning the parameter is passed as an input and cannot be modified inside the procedure.
5. What is the purpose of %TYPE in PL/SQL?
ANS : (a) %TYPE allows a variable to inherit the data type of a database column, ensuring consistency.
6. Which SQL statement is used to execute a stored procedure in PL/SQL?
ANS : (d) In PL/SQL, both EXEC procedure_name and CALL procedure_name can be used to execute a stored procedure.
7. Which section of a PL/SQL block is optional?
ANS : (a) Declaration and (c) Exception Handling are optional. The execution section is mandatory.
8. What is a trigger in PL/SQL?
ANS : (c) A trigger is a special type of stored procedure that runs automatically when a specific event occurs in a database.
9. How do you handle exceptions in PL/SQL?
ANS : (b) PL/SQL uses the EXCEPTION section to handle errors and exceptions.
10. Which of the following is a valid loop in PL/SQL?
ANS : (d) PL/SQL supports FOR, WHILE, and LOOP constructs for iteration.
11. Which keyword is used to exit a loop in PL/SQL?
ANS : (a) The EXIT keyword is used to terminate a loop in PL/SQL.
12. What is the function of a cursor in PL/SQL?
ANS : (b) A cursor is used to retrieve and process multiple rows returned by a query.
13. What is the difference between an implicit and an explicit cursor?
ANS : (b) Implicit cursors are created automatically for SQL statements, whereas explicit cursors are declared by the user for better control.
14. Which keyword is used to assign values to variables in PL/SQL?
ANS : (b) The := operator is used in PL/SQL to assign values to variables.
15. What is the use of the RAISE statement in PL/SQL?
ANS : (b) The RAISE statement is used to explicitly trigger an exception.
16. What is a package in PL/SQL?
ANS : (a) A package groups related PL/SQL procedures, functions, and other components for better modularity.
17. What does the pragma AUTONOMOUS_TRANSACTION do in PL/SQL?
ANS : (b) This pragma enables a PL/SQL block to execute as a separate transaction, independent of the main transaction.
18. How can you check if a cursor has fetched any rows?
ANS : (a) %FOUND returns TRUE if the cursor fetches at least one row.
19. What is the default value of an uninitialized variable in PL/SQL?
ANS : (a) In PL/SQL, uninitialized variables have a default value of NULL.
20. How do you terminate a stored procedure in PL/SQL?
ANS : (a) A stored procedure is terminated using the END; keyword.
21. What is a trigger in PL/SQL?
ANS : (b) A trigger is a stored procedure that automatically executes when a specific event occurs in the database.
22. Which keyword is used to declare a constant in PL/SQL?
ANS : (c) The keyword CONSTANT is used to declare a constant in PL/SQL.
23. What is the purpose of the %TYPE attribute in PL/SQL?
ANS : (a) %TYPE is used to declare a variable with the same data type as a column in a table or another variable.
24. What is a cursor in PL/SQL?
ANS : (b) A cursor is a pointer to the context area that stores the result set of a query.
25. What does the %ROWTYPE attribute do in PL/SQL?
ANS : (b) %ROWTYPE allows you to declare a variable that represents a row in a table.
26. Which of the following is used to handle exceptions in PL/SQL?
ANS : (b) The WHEN-THEN block is used to handle exceptions in PL/SQL.
27. What is the scope of a variable declared in a PL/SQL block?
ANS : (c) A variable in PL/SQL is local to the block in which it is declared.
28. Which section of PL/SQL is mandatory in a block?
ANS : (b) BEGIN section is mandatory in a PL/SQL block.
29. What is the correct order of a PL/SQL block?
ANS : (c) The correct order is DECLARE, BEGIN, EXCEPTION, END.
30. What is the purpose of the RETURN statement in PL/SQL functions?
ANS : (c) RETURN is used to specify the value that the function returns.
31. What is a trigger in PL/SQL?
ANS : (c) A trigger is a stored procedure that executes automatically in response to a specific event on a table or view.
32. What is the purpose of the RAISE statement in PL/SQL?
ANS : (a) The RAISE statement is used to explicitly raise an exception in PL/SQL.
33. Which keyword is used to define a constant in PL/SQL?
ANS : (c) The CONSTANT keyword is used to declare a constant in PL/SQL.
34. Which SQL command is used inside PL/SQL to assign a value from a query?
ANS : (a) SELECT INTO is used to assign query results to a variable in PL/SQL.
35. What is the use of %TYPE in PL/SQL?
ANS : (b) %TYPE allows you to declare a variable with the same data type as a table column.
36. Which of the following is true about nested blocks in PL/SQL?
ANS : (b) Nested blocks are allowed, and you can define one block inside another.
37. What is the default mode of parameters in PL/SQL procedures?
ANS : (b) The default parameter mode in PL/SQL is IN.
38. What happens if no exception is handled in a PL/SQL block?
ANS : (b) If no exception is handled, PL/SQL raises an error and terminates the block execution.
39. Which is a user-defined exception in PL/SQL?
ANS : (c) ACCESS_DENIED can be a user-defined exception, while the others are predefined.
40. Which PL/SQL keyword is used to declare a record?
ANS : (c) TYPE is used to define a record type in PL/SQL.
41. Which cursor is automatically created by Oracle for DML operations?
ANS : (c) Oracle automatically creates an implicit cursor for DML operations like INSERT, UPDATE, DELETE.
42. Which attribute returns the number of rows affected by a DML statement?
ANS : (a) SQL%ROWCOUNT returns the number of rows affected by the last DML operation.
43. What does the %FOUND attribute return?
ANS : (a) %FOUND returns TRUE if a DML statement affected one or more rows.
44. Which section in PL/SQL is optional?
ANS : (d) DECLARE and EXCEPTION sections are optional, only BEGIN...END is mandatory.
45. Which one is NOT a valid loop in PL/SQL?
ANS : (b) REPEAT UNTIL is not a valid loop in PL/SQL.
46. Which of the following is a composite data type in PL/SQL?
ANS : (c) RECORD is a composite data type that can hold multiple values.
47. What does the NO_DATA_FOUND exception indicate?
ANS : (b) NO_DATA_FOUND is raised when a SELECT INTO statement does not return any rows.
48. How do you exit a loop in PL/SQL?
ANS : (a) EXIT is used to break a loop in PL/SQL.
49. Which clause is used in PL/SQL function to return a value?
ANS : (a) The RETURN clause is used to specify the return value in a PL/SQL function.
50. What does the %ISOPEN attribute check in PL/SQL?
ANS : (b) %ISOPEN returns TRUE if the cursor is currently open.