1Z0-149 Sample Questions & Answers
Tests your grasp of control structures, composite data types and explicit cursors, the three heaviest topics, plus declaring variables, handling exceptions, writing SQL, triggers and dependencies, dynamic SQL, and building procedures, functions and packages.
Launch the full 1Z0-149 simulator →Showing 10 of 20 free samples.
- Question 1AdvancedSelect 2
Design Considerations for PL/SQL Code · Autonomous Transactions
A developer is writing a procedure to archive old orders. The procedure must perform two main tasks: copy order data to an archive table and then delete the original orders. It is critical that the logging of the archive operation succeeds and is committed, even if the subsequent deletion of the original orders fails and is rolled back. Which two PL/SQL features should be combined to achieve this? (Select TWO)
Show answer & explanation
Correct answers: A, C
Creating a separate, local procedure for the logging action encapsulates the logic cleanly.
This pragma declares that the logging procedure runs in its own independent transaction. It can commit its work (the log entry) without affecting the main transaction (the data archiving and deletion). This ensures the log is saved even if the main transaction is later rolled back.
- Question 2Advanced
Design Considerations for PL/SQL Code · Autonomous Transactions and Bulk Binding
Case Study:
A logistics company, ShipFast Inc., is developing a new package,
TRACKING_PKG, to manage shipment statuses. The package needs to provide a procedure,UPDATE_STATUS, that takes a tracking number and a new status. A key requirement is that every status update attempt, whether successful or not, must be recorded in anAUDIT_LOGtable for compliance reasons. The audit record must be saved permanently, even if the main transaction that calledUPDATE_STATUSis later rolled back by the calling application.Furthermore, the
UPDATE_STATUSprocedure will be part of a large, complex transaction and must not issue its ownCOMMITorROLLBACK, as this would interfere with the calling application's transaction control. The audit logging, however, must be self-contained. The development team has decided to use a private procedure within the package body,LOG_AUDIT_ATTEMPT, to handle the insertion into theAUDIT_LOGtable.To optimize performance, another procedure,
BULK_UPDATE_STATUSES, is required. This procedure will accept a collection of tracking numbers and statuses and update them all. The team wants to minimize context switching between the PL/SQL and SQL engines during this bulk operation.Which package body implementation correctly satisfies all the requirements for both transactional integrity and performance optimization?
Show answer & explanation
Correct answer: B
This solution correctly addresses all requirements. Using
PRAGMA AUTONOMOUS_TRANSACTIONin the private logging procedure allows it to commit its own transaction independently, ensuring audit records are saved regardless of the main transaction's outcome. Using theFORALLstatement for the bulk update is the most performant method, as it sends all DML statements to the SQL engine in a single call, minimizing context switching. - Question 3Beginner
Working with Packages · Package State
True or False: An
INDEX BYtable (associative array) defined within a PL/SQL package specification persists for the duration of the database session.Show answer & explanation
Correct answer: A
Variables, cursors, and types declared in a package specification or body (outside of a specific subprogram) are part of the package's state. This state is initialized when the package is first referenced in a session and persists for the entire duration of that database session, allowing data to be maintained across multiple calls to the package's subprograms within the same session.
- Question 4Intermediate
Design Considerations for PL/SQL Code · Bulk Binding
A developer needs to process a result set of employee records. The number of employees is large but manageable within session memory. For each employee, multiple DML operations are required. To improve performance, the developer wants to fetch all employee records from the
EMPLOYEEStable into a PL/SQL collection in a single database round-trip. Which SQL statement clause should be used?Show answer & explanation
Correct answer: C
The
BULK COLLECT INTOclause is used withSELECT,FETCH, andRETURNINGclauses to retrieve multiple rows of data into one or more collections with a single call to the SQL engine. This dramatically reduces context switching and improves performance compared to fetching one row at a time in a loop. - Question 5Intermediate
Handling Exceptions · Predefined Exceptions (TOO_MANY_ROWS)
Examine the following code:
DECLARE TYPE t_emp_rec IS RECORD ( employee_id employees.employee_id%TYPE, salary employees.salary%TYPE ); v_emp_rec t_emp_rec; BEGIN SELECT employee_id, salary INTO v_emp_rec FROM employees WHERE department_id = 90; DBMS_OUTPUT.PUT_LINE('Employees found: ' || SQL%ROWCOUNT); END;The
employeestable has three employees in department 90. What is the result when this block is executed?Show answer & explanation
Correct answer: C
A
SELECT ... INTOstatement is designed to fetch exactly one row. If theWHEREclause results in the query returning more than one row, Oracle raises the predefinedTOO_MANY_ROWSexception. Since the block does not have an exception handler for this, the block will terminate and propagate the unhandled exception. - Question 6Intermediate
Managing Dependencies · Dependency Tracking and Invalidation
A PL/SQL procedure is created to update a table. Later, a column in that table is dropped. What happens the next time the procedure is invoked?
Show answer & explanation
Correct answer: C
When a DDL operation (like dropping a column) affects a dependent object, Oracle marks the dependent object (the procedure) as INVALID. The next time the procedure is called, the PL/SQL engine attempts to recompile it automatically. Because the procedure's code references a column that no longer exists, this recompilation will fail, and Oracle will return a compilation error to the calling application.
- Question 7IntermediateSelect 2
Using Explicit Cursors · Cursors for Update
A developer is writing a cursor
FORloop to process employee data. Inside the loop, they need to perform an update on the exact row currently being processed by the cursor. Which two clauses are required to achieve this efficiently and safely? (Select TWO)sequenceDiagram participant PLSQL as PL/SQL Engine participant SQL as SQL Engine PLSQL->>SQL: OPEN CURSOR c_emp FOR SELECT ... FOR UPDATE; SQL-->>PLSQL: Lock rows and return cursor handle loop For each row PLSQL->>SQL: FETCH c_emp SQL-->>PLSQL: Return current row data PLSQL->>SQL: UPDATE employees SET ... WHERE CURRENT OF c_emp; SQL-->>PLSQL: Update locked row end PLSQL->>SQL: CLOSE c_emp SQL-->>PLSQL: Release locksShow answer & explanation
Correct answers: A, B
The
FOR UPDATEclause in the cursor's SELECT statement instructs the database to place exclusive locks on all rows identified by the query, preventing other sessions from modifying them until the current transaction is committed or rolled back.The
WHERE CURRENT OF cursor_nameclause is used in anUPDATEorDELETEstatement inside a cursor loop. It provides a direct pointer to the most recently fetched row from the cursor, ensuring that the DML operation targets exactly that row without needing to re-specify the primary key. - Question 8Intermediate
Creating Functions · Differentiating Procedures and Functions
A junior developer has written the following procedure to grant a bonus, but it fails to compile.
CREATE OR REPLACE PROCEDURE grant_bonus ( p_emp_id IN employees.employee_id%TYPE, p_bonus_pct IN NUMBER ) IS v_current_salary employees.salary%TYPE; v_new_salary v_current_salary%TYPE; BEGIN SELECT salary INTO v_current_salary FROM employees WHERE employee_id = p_emp_id; v_new_salary := v_current_salary * (1 + p_bonus_pct); UPDATE employees SET salary = v_new_salary WHERE employee_id = p_emp_id; COMMIT; END grant_bonus;A senior developer reviews the code and recommends creating it as a function instead of a procedure. What is the primary reason for this recommendation?
Show answer & explanation
Correct answer: B
The core purpose of a function is to compute and return a single value. In this scenario, the procedure calculates a new salary. By converting it to a function that returns the new salary, the logic becomes more modular and reusable. The calling program can then decide whether to use that returned value in an
UPDATEstatement, a report, or another calculation. Procedures are primarily for performing actions. - Question 9Intermediate
Creating Packages · Forward Declarations
A developer needs to create two procedures,
proc_Aandproc_B, within the same package body.proc_Aneeds to callproc_B, andproc_Bneeds to callproc_A. This creates a mutual dependency. Ifproc_Ais defined beforeproc_Bin the package body, what will happen when the package body is compiled?Show answer & explanation
Correct answer: B
The PL/SQL compiler processes code sequentially. When it compiles
proc_A, it will encounter a call toproc_B, which has not yet been defined later in the package body. This results in a compilation error. To solve this, a forward declaration forproc_Bmust be placed at the top of the package body beforeproc_Ais defined. - Question 10Advanced
Creating Compound, DDL, and Event Database Triggers · DML Triggers and User-Defined Exceptions
Case Study:
A healthcare provider is building a system to manage patient appointments. They have a
PATIENTStable and anAPPOINTMENTStable. A new requirement is to create a trigger that prevents a new appointment from being scheduled if the patient has more than three outstanding unpaid bills in theBILLStable.The trigger must fire before a new row is inserted into the
APPOINTMENTStable. It needs to check the bill count for the specificpatient_idbeing inserted. If the count of unpaid bills is greater than three, the trigger should prevent the insertion and return a clear, user-friendly error message to the application.The development team wants to ensure the solution is efficient and handles the error condition gracefully.
Which trigger implementation best satisfies these requirements?
Show answer & explanation
Correct answer: B
This is the correct approach. A
BEFORE INSERTtrigger allows the business rule to be checked before the DML operation occurs. The:NEW.patient_idcan be used to efficiently query theBILLStable for the specific patient. UsingRAISE_APPLICATION_ERRORis the standard and best practice for returning custom errors from the database to a client application. It stops the DML operation and provides a meaningful error message.
Ready for the real thing?
The full 1Z0-149 simulator has every exam-style question, timed mode, and instant scoring.