Limited-Time Offer: Enjoy 50% Savings! Coupon code: 50OFF Use it at checkout
Skip to content

Free Oracle Database 19c: Program with PL/SQL 1Z0-149 Exam Questions

Last updated: · 14 practice questions with answers and explanations

Page: 1 / 7 Total 65 questions

Want more questions? Get Premium Access.

Question 1

New Single answer

Topic: Declaring PL/SQL Variables

Skill tested: Declare a variable with %TYPE and initialize it from a table column.

A billing procedure must retain the current value of `ACCOUNT_BALANCE` for one account before applying a set of adjustments. The balance column is `NUMBER(12,2)`, and the development team wants the PL/SQL variable to track future changes to the column's declared type without duplicating its definition. The procedure receives `p_account_id`; the account is guaranteed to exist. Which declaration and initialization correctly capture the value at the start of the executable section?

Correct Answer: C. Declare `v_balance accounts.account_balance%TYPE;` and assign it with `SELECT account_balance INTO v_balance FROM accounts WHERE account_id = p_account_id;`.
Explanation:

A variable declared as `accounts.account_balance%TYPE` inherits the column's datatype and precision, so it remains aligned if the column definition changes. The `SELECT ... INTO` statement retrieves the value for the specified account and assigns it to the variable. A names a column as if it were a PL/SQL expression and hard-codes the type. C uses invalid attribute syntax and does not retrieve the balance. D declares a constant without an initialization value; constants must be initialized at declaration and cannot later receive a SELECT result.

Question 2

New Single answer

Topic: Writing Executable Statements

Skill tested: Use a sequence value in an expression within a nested PL/SQL block.

A nightly job creates a transaction record and then calculates a tracking value that combines the newly allocated transaction identifier with a caller-supplied offset. The team wants the sequence reference and calculation scoped to a nested block because the calculation is temporary. The transaction sequence is `txn_seq`, and `p_offset` is a NUMBER parameter. Which nested-block statement correctly obtains a sequence value and stores the calculated result in the outer variable `v_tracking`?

Correct Answer: B. `DECLARE v_id NUMBER; BEGIN v_id := txn_seq.NEXTVAL; v_tracking := v_id + p_offset; END;`
Explanation:

A nested PL/SQL block can declare a local variable, assign `txn_seq.NEXTVAL` in its executable section, and use the value in an expression that assigns an outer-scope variable. This avoids relying on `CURRVAL`, which requires a prior `NEXTVAL` in the session. B is not valid because an ordinary PL/SQL variable declaration cannot use a sequence pseudocolumn as its initialization expression. D uses nonexistent function-call syntax for sequence access.

Question 3

New Single answer

Topic: Writing SQL in PL/SQL

Skill tested: Capture a single-row SQL query result with PL/SQL SELECT INTO.

An application routine must retrieve a customer's status and credit limit before deciding whether to release an order. `customers.customer_id` is a primary key, so the query returns exactly one row for the supplied `p_customer_id`. The procedure already declares `v_status` and `v_limit` with suitable datatypes. Which statement assigns both results correctly and avoids an unnecessary intermediate record?

Correct Answer: A. `SELECT status, credit_limit INTO v_status, v_limit FROM customers WHERE customer_id = p_customer_id;`
Explanation:

In static SQL inside PL/SQL, `INTO` follows the select list and precedes the `FROM` clause. Each selected expression maps positionally to its corresponding target, so the status and limit populate the two variables in order. A places `INTO` in invalid SQL syntax. C can perform a dynamic query but is unnecessary for a fixed statement and uses a less suitable construct. D attempts to use two `INTO` clauses; a single `INTO` clause accepts the full target list.

Question 4

New Multiple answers

Topic: Writing Control Structures

Skill tested: Choose PL/SQL branching and loop constructs for ordered business rules.

A claims processor receives an integer rating from 1 through 5 and must apply one of three outcomes: ratings 1 or 2 are rejected, rating 3 is sent for manual review, and ratings 4 or 5 are approved. A separate processing stage must then examine every eligible claim in a cursor until no rows remain. The code must make the mutually exclusive outcomes clear and avoid manually managing cursor fetch status. Which two implementation choices best meet these requirements? Select TWO.

Correct Answer: A. Use a cursor `FOR` loop to process each eligible claim; PL/SQL opens, fetches, and closes the cursor for the loop.; C. Use a searched `CASE` expression or statement with conditions for rating ranges and an `ELSE` for the remaining valid values.
Explanation:

A searched `CASE` supports range conditions such as `rating

Question 5

New Multiple answers

Topic: Working with Composite Data Types

Skill tested: Define and initialize an associative array of records, then access its fields.

A PL/SQL routine builds an in-memory collection of department summaries indexed by department ID. Each element must hold the department name and a headcount, and the data is assembled from a small fixed set of departments before a reporting procedure reads individual fields. The collection must be associative rather than densely numbered from 1, and its record structure should not duplicate the source table's column datatypes. Which TWO code-design choices satisfy these requirements? Select TWO.

Correct Answer: A. Assign the fields of an element using `summary(dept_id).dept_name := ...` and `summary(dept_id).head_count := ...` after setting `dept_id`.; D. Declare a record type with fields based on appropriate column `%TYPE` attributes, then define a table type `INDEX BY PLS_INTEGER` of that record type.
Explanation:

An associative array can be declared with `INDEX BY PLS_INTEGER` and an element type that is a user-defined record. Defining record fields with suitable `%TYPE` anchors avoids duplicating column datatype declarations; E shows field-by-field element access after the index is available. A incorrectly anchors a headcount to the department ID column, which may not be the intended datatype. B uses an invalid associative-array index datatype declaration for this use and stores an entire row rather than the requested summary. D references an unset index and does not meet the initialization sequence.

Question 6

New Single answer

Topic: Using Explicit Cursors

Skill tested: Use a parameterized cursor FOR UPDATE and update its current row.

A maintenance procedure processes only employees in a caller-selected department. For each fetched employee, it must increase the salary in the same row and ensure that the update targets the row currently fetched, rather than reconstructing a key-based predicate. The procedure may use row locking during the cursor's work. Which cursor and update approach is appropriate?

Correct Answer: B. Declare a parameterized cursor with `WHERE department_id = p_dept FOR UPDATE`; in a cursor FOR loop, issue `UPDATE employees SET salary = salary * 1.05 WHERE CURRENT OF c_emp`.
Explanation:

`WHERE CURRENT OF` requires a cursor that is positioned on a current row and declared `FOR UPDATE`. A cursor FOR loop implicitly fetches each row while the loop body executes, so the update can target the current row using the cursor name. A lacks the required update lock. C confuses the cursor name with its parameter. D names the cursor correctly but attempts the update after the loop, when it is no longer positioned on the row to be updated.

Question 7

New Single answer

Topic: Handling Exceptions

Skill tested: Declare and raise a user-defined exception when a business condition is met.

A payroll routine computes a proposed payment and must abort processing when the amount is negative. The application requires a named exception that can be handled by the caller's exception section, and the routine must raise it explicitly when the condition is detected rather than relying on an unrelated Oracle error. Which implementation is valid?

Correct Answer: A. Declare `e_negative_payment EXCEPTION;` in the block's declarative section, then execute `RAISE e_negative_payment;` when `v_payment < 0`.
Explanation:

A user-defined exception is declared in a declarative section and raised by name with the `RAISE` statement when the business condition occurs. An enclosing block can then handle that named exception. B declares a number, not an exception. `RAISE_APPLICATION_ERROR` requires a numeric error number in the permitted application-error range, not an exception identifier, so C is invalid. D places the declaration in the wrong section; declarations must precede the executable section.

Question 8

New Single answer

Topic: Using PL/SQL Subprograms

Skill tested: Call a stored procedure from an anonymous block with positional parameters.

A deployment script must invoke the stored procedure `rebuild_region_summary`, which accepts two IN parameters in this order: a region code and an as-of date. The procedure is already compiled, the caller needs no returned value, and the script should be a straightforward anonymous PL/SQL block. Which call is valid when using positional notation?

Correct Answer: A. `BEGIN rebuild_region_summary('NW', DATE '2025-01-31'); END;`
Explanation:

A procedure call belongs in the executable section of an anonymous block. Positional notation supplies actual parameters in the declared order, so the region code precedes the date. A uses named notation, not positional notation, and the supplied parameter names might not match the procedure declaration. C places a call where declarations belong. D treats a procedure as a function that returns a value; procedures do not provide a function return value for assignment.

Question 9

New Multiple answers

Topic: Creating Procedures and Using Parameters

Skill tested: Use named parameter notation and handle a raised exception inside a procedure.

A service procedure accepts an account identifier and a requested credit increase, then performs a validation step that can raise `credit_limit_exceeded`. The service contract requires that the procedure handle this exception internally, write a diagnostic using the application's logging routine, and return normally so a batch caller can continue with the next account. The caller must not depend on the formal parameter order. Which TWO choices implement the requirements? Select TWO.

Correct Answer: A. Include a handler for `credit_limit_exceeded` in the procedure's exception section, call the logger there, and do not re-raise the exception.; E. Call the procedure with named association, such as `adjust_credit(p_increase => 500, p_account_id => 81)`.
Explanation:

Named notation associates each actual argument with its formal parameter explicitly, so callers are not dependent on declaration order. A procedure can handle an exception raised by its executable statements in its own exception section. Logging the specified error without re-raising allows the procedure to return normally, as the batch contract requires. Positional arguments cannot be reordered by referring to formal names. An exception raised within a procedure can be handled there, and an exception section follows the executable section rather than preceding it.

Question 10

New Single answer

Topic: Creating Functions

Skill tested: Create a scalar PL/SQL function suitable for invocation from a SQL query.

A reporting query must calculate a tax amount from each row's taxable base using a stored PL/SQL function. The function accepts and returns NUMBER, reads no tables, performs no DML, and raises no exceptions for the report's inputs. The report calls it in the select list of a SQL statement. Which function design is compatible with that use?

Correct Answer: B. Create a function that returns NUMBER and uses only its input parameter in a deterministic arithmetic calculation, then call it in the SELECT list.
Explanation:

A scalar function that computes its result from its input without side effects can be called as an expression in a SQL query. B returns a NUMBER and avoids database state changes, matching the report's requirement. A performs DML, which is not permitted when a stored function is invoked from a query in the ordinary manner. A procedure is not a SQL expression and cannot be selected as a scalar value. A PL/SQL record return type is not a scalar SQL result suitable for this select-list use.

Question 11

New Multiple answers

Topic: Creating Packages

Skill tested: Overload package subprograms and forward-declare a mutually referenced helper.

A package provides `format_key` for both numeric and character keys. Its body also contains two private helper procedures that call one another: `normalize_text` calls `validate_text`, and `validate_text` calls `normalize_text`. The package must expose only the overloaded `format_key` entry points; the helpers remain private. Which TWO implementation decisions satisfy the requirements? Select TWO.

Correct Answer: B. Declare two `format_key` specifications in the package specification with distinguishable parameter datatypes, then implement both signatures in the body.; E. Add a forward declaration for `validate_text` in the package body before the definition of `normalize_text`, then define both helpers in the body.
Explanation:

Package overloading requires declarations whose parameter profiles are distinguishable; return type alone cannot distinguish overloads. Declaring both public signatures in the package specification exposes the desired interface, while body-only helper declarations keep the helpers private. A forward declaration makes a later subprogram available to an earlier body definition, resolving the mutual reference without publishing either helper. Making helpers public is unnecessary. Package bodies have declarations, an optional initialization section, and definitions; they do not support separate body sections as described in E.

Question 12

New Single answer

Topic: Working with Packages

Skill tested: Restrict package subprogram callers with the ACCESSIBLE BY clause.

A database team exposes a package containing shared order-processing routines, but one maintenance subprogram must be callable only by the package `ORDER_MAINTENANCE`. The restriction is intended to limit which PL/SQL unit can invoke that subprogram; it is not a substitute for database grants on the package. Which declaration best expresses this restriction?

Correct Answer: D. Declare the subprogram with `ACCESSIBLE BY (ORDER_MAINTENANCE)` in its package specification.
Explanation:

The `ACCESSIBLE BY` clause can be associated with a subprogram declaration to control which named PL/SQL units may call it. Applying it to the targeted subprogram in the package specification expresses the requested restriction while leaving other package routines unaffected. Applying a restriction to the whole package is broader than required. A body-only private subprogram is not a public package interface, and the proposed clause placement does not meet the stated interface design. Object privileges govern database access but do not provide this subprogram-level PL/SQL caller restriction.

Question 13

New Single answer

Topic: Using Dynamic SQL

Skill tested: Bind PL/SQL variables in Native Dynamic SQL for a DML statement.

A generic loader receives a table name selected from a trusted allowlist and a numeric batch identifier. It must update a fixed column named `processed_flag` to `Y` for rows belonging to that batch. The table name cannot be bound because it is an identifier, but the batch identifier should not be concatenated into SQL text. Which Native Dynamic SQL approach is appropriate?

Correct Answer: D. Build the statement with the allowlisted table name and a `:batch_id` placeholder, then execute it with `USING p_batch_id`.
Explanation:

Native Dynamic SQL binds values, not SQL identifiers. The allowlisted table name must therefore be incorporated into the statement text, while the batch identifier remains a bind placeholder supplied through `USING`. This avoids value concatenation and its associated parsing and injection risks. B tries to bind an identifier, which SQL bind variables cannot represent. C needlessly embeds a value in the statement. D reverses the appropriate treatment by attempting to bind the table name and concatenating the data value.

Question 14

New Multiple answers

Topic: Design Considerations for PL/SQL Code

Skill tested: Apply NOCOPY to an OUT parameter and use FORALL for bulk DML.

A batch routine accumulates up to several thousand calculated adjustments in PL/SQL collections and then inserts them into a staging table. The routine also returns a large collection to its caller. Profiling shows context-switch overhead during row-by-row inserts, and copying the OUT collection is a concern. The team accepts that `NOCOPY` is a hint whose copy semantics are not guaranteed. Which TWO changes directly address these concerns? Select TWO.

Correct Answer: A. Declare the large OUT collection parameter with the `NOCOPY` hint to request pass-by-reference behavior.; C. Replace the row-by-row INSERT loop with `FORALL` using collection elements as bind values.
Explanation:

`NOCOPY` requests that the compiler pass a parameter by reference rather than making a potentially expensive copy, although it is a hint and not a guarantee. `FORALL` sends collection-driven DML in batches, reducing PL/SQL-to-SQL context-switch overhead compared with one INSERT per loop iteration. A cursor FOR loop does not bulk-bind DML. `BULK COLLECT` retrieves query rows into collections; it is not the mechanism for inserting collection values. `CONSTANT` is not a valid way to make an OUT parameter immutable.