This quiz explores practical PL/SQL use cases found in banking and e-commerce systems, focusing on concepts like transactions, triggers, stored procedures, exception handling, and data validation. Sharpen your understanding of real-world PL/SQL applications relevant to financial and online retail workflows.
In a banking application, which PL/SQL statement ensures that a funds transfer between two accounts is treated as a single, atomic operation?
Explanation: COMMIT makes a transaction permanent, ensuring that both debit and credit operations are saved together, which is essential for atomicity in banking scenarios. WHEN OTHERS is used for exception handling, not transaction control. DECLARE is for defining variables and cursors, not for managing transactions. CURSOR is used for retrieving data row by row, unrelated to transaction atomicity.
Which PL/SQL feature would you use to automatically record every deletion of a customer order in an e-commerce system for auditing purposes?
Explanation: An AFTER DELETE trigger automatically executes after a row is deleted and is ideal for logging deletions in audit tables. SAVEPOINT marks a point within a transaction for partial rollbacks, not for automatic actions. ROLLBACK undoes changes without logging. FOR UPDATE is used for locking records during queries and does not handle auditing.
A PL/SQL stored procedure is most suitable for which banking scenario?
Explanation: Stored procedures are ideal for encapsulating complex logic like batch processing multiple payments, ensuring code reusability and transaction integrity. Displaying a single address is a simple query, not requiring a procedure. Formatting a report header is best done in reporting software. Defining a variable is done within blocks, not as a stored procedure.
In an e-commerce PL/SQL block, which construct gracefully handles an invalid product ID error during checkout?
Explanation: The EXCEPTION block in PL/SQL is used to handle errors such as invalid product IDs, allowing alternative actions or error messages without crashing the process. OPEN is for cursors, not for error handling. RENAME is used to rename objects like tables, which is unrelated to error handling. SAVE is not a PL/SQL statement.
Which PL/SQL technique would you use to ensure that a customer's withdrawal does not exceed their bank account balance before updating the record?
Explanation: IF-THEN-ELSE logic lets you compare the withdrawal amount with the account balance and prevent invalid transactions. EXISTS is a SQL operator, not a PL/SQL constraint. CURSOR FOR LOOP can retrieve data but does not enforce validation by itself. ALTER TABLE is for changing table structures, not runtime validation.
How can you automatically update inventory counts after every successful purchase transaction in an e-commerce database?
Explanation: An AFTER INSERT trigger on the purchases table allows automatic updates to the inventory whenever a new purchase is made. SELECT statements only retrieve data and cannot make automatic changes. INDEX is used for faster data retrieval, not for automatic updates. SESSION relates to user connections, not inventory management.
In banking systems, which PL/SQL element allows you to retrieve and process multiple unpaid invoices for a customer one by one?
Explanation: Explicit cursors are defined by PL/SQL programmers to fetch and process multiple rows, such as unpaid invoices, record by record. CONSTRAINT is for enforcing rules like uniqueness. PRIMARY KEY ensures unique values but does not process rows. ANALYZE is a command to gather statistics, not for processing result sets.
Which PL/SQL feature efficiently updates the shipping status for hundreds of e-commerce orders in a single execution?
Explanation: The FORALL statement lets you perform bulk DML operations, like updating many shipping statuses at once, improving performance. ROWNUM assigns row numbers, not for bulk operations. ORDER BY is for sorting results, and FETCH FIRST limits rowsets but doesn't update multiple records efficiently.
What method can a PL/SQL developer use to avoid double-charging a customer during online payment processing?
Explanation: Verifying for existing payments before inserting is a reliable way to prevent duplicate transactions and ensure data integrity. Adding NULL values does not help avoid duplicates. Increasing payment amounts is illogical and could harm customers. Removing COMMIT leads to uncommitted transactions and doesn't prevent duplicates.
How can PL/SQL functions help generate a customer's total monthly spend in an e-commerce portal?
Explanation: A PL/SQL function can compute and return the total spend by aggregating order amounts, aiding monthly reporting. Modifying table structures is for schema management, not calculations. Rolling back transactions would undo valid purchases. Truncating the database erases data and is never suitable for reporting.