1Z0-149 Sample Questions

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.

  1. 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.

  2. 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 an AUDIT_LOG table for compliance reasons. The audit record must be saved permanently, even if the main transaction that called UPDATE_STATUS is later rolled back by the calling application.

    Furthermore, the UPDATE_STATUS procedure will be part of a large, complex transaction and must not issue its own COMMIT or ROLLBACK, 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 the AUDIT_LOG table.

    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_TRANSACTION in 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 the FORALL statement 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.

  3. Question 3Beginner

    Working with Packages · Package State

    True or False: An INDEX BY table (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.

  4. 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 EMPLOYEES table 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 INTO clause is used with SELECT, FETCH, and RETURNING clauses 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.

  5. 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 employees table has three employees in department 90. What is the result when this block is executed?

    Show answer & explanation

    Correct answer: C

    A SELECT ... INTO statement is designed to fetch exactly one row. If the WHERE clause results in the query returning more than one row, Oracle raises the predefined TOO_MANY_ROWS exception. Since the block does not have an exception handler for this, the block will terminate and propagate the unhandled exception.

  6. 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.

  7. Question 7IntermediateSelect 2

    Using Explicit Cursors · Cursors for Update

    A developer is writing a cursor FOR loop 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 locks

    Show answer & explanation

    Correct answers: A, B

    The FOR UPDATE clause 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_name clause is used in an UPDATE or DELETE statement 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.

  8. 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 UPDATE statement, a report, or another calculation. Procedures are primarily for performing actions.

  9. Question 9Intermediate

    Creating Packages · Forward Declarations

    A developer needs to create two procedures, proc_A and proc_B, within the same package body. proc_A needs to call proc_B, and proc_B needs to call proc_A. This creates a mutual dependency. If proc_A is defined before proc_B in 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 to proc_B, which has not yet been defined later in the package body. This results in a compilation error. To solve this, a forward declaration for proc_B must be placed at the top of the package body before proc_A is defined.

  10. 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 PATIENTS table and an APPOINTMENTS table. 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 the BILLS table.

    The trigger must fire before a new row is inserted into the APPOINTMENTS table. It needs to check the bill count for the specific patient_id being 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 INSERT trigger allows the business rule to be checked before the DML operation occurs. The :NEW.patient_id can be used to efficiently query the BILLS table for the specific patient. Using RAISE_APPLICATION_ERROR is 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.