1Z0-149 Oracle Database Program with PL/SQL Practice Questions
Prepare for 1Z0-149 with more than an answer.
Unlock the full exam and previous versions
- v1Version 1 246 questions Current
- 1z0-148Legacy Oracle Database 12c: Advanced PL/SQL 74 questions Locked
- Exam fee
- $245 USD
- Level
- Professional
- Valid for
- Lifetime (no recertification required)
Domains covered on the exam 18
- Declaring PL/SQL Variables8%
- Writing Executable Statements10%
- Writing SQL in PL/SQL8%
- Writing Control Structures12%
- Working with Composite Data Types12%
- Using Explicit Cursors12%
- Handling Exceptions10%
- Using PL/SQL Subprograms6%
- Creating Procedures and Using Parameters8%
- Creating Functions6%
- Creating Packages8%
- Working with Packages6%
- Using Dynamic SQL6%
- Design Considerations for PL/SQL Code8%
- Creating Compound, DDL, and Event Database Triggers6%
- Using the PL/SQL Compiler4%
- Managing PL/SQL Code4%
- Managing Dependencies2%
- 1
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 details
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. - 2
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 details
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. - 3
A developer needs to execute a DDL statement, such as
TRUNCATE TABLE, from within a PL/SQL procedure. The name of the table to be truncated is passed as a parameter to the procedure. Which method should be used to execute the DDL statement?Show answer details
Correct answer: C
DDL statements cannot be executed using static SQL in PL/SQL because the objects they reference must exist at compile time. When the object name is dynamic (passed as a parameter), Native Dynamic SQL (NDS) with
EXECUTE IMMEDIATEis the required method. The entire DDL command must be constructed as a string and then executed. - 4
A PL/SQL procedure is defined with
AUTHID CURRENT_USER. The procedure updates theSALEStable. UserSCOTT, who owns the procedure, grantsEXECUTEprivilege on it to userJANE. UserJANEdoes not have any direct privileges on theSALEStable. What happens whenJANEexecutes the procedure?Show answer details
Correct answer: B
AUTHID CURRENT_USERspecifies that the procedure executes with the privileges of the user who invokes it (the invoker), not the user who owns it (the definer). In this case,JANEis the invoker. SinceJANElacks the necessaryUPDATEprivilege on theSALEStable, the SQL statement within the procedure will fail due to insufficient privileges. - 5
What is the primary purpose of enabling compile-time warnings using
ALTER SESSION SET PLSQL_WARNINGS='ENABLE:ALL'?Show answer details
Correct answer: C
PL/SQL compile-time warnings identify conditions that are not syntax errors but could lead to runtime errors or poor performance. Examples include unreachable code, subprograms that don't return a value on all paths, or severe performance warnings like passing a
NOT NULLparameter to a subprogram that declares it without the constraint. Enabling warnings is a best practice for improving code quality and robustness. - 6
True or False: A user-defined PL/SQL record type can be used as a column data type in a database table.
Show answer details
Correct answer: B
A record type defined within a PL/SQL block or package (
TYPE ... IS RECORD) is a PL/SQL-only construct and cannot be used as a data type for a table column. To store a composite structure in a table column, you must create a SQLOBJECTtype using theCREATE TYPE ... AS OBJECTDDL statement. - 7
A procedure processes a large set of rows fetched using
BULK COLLECT. After processing, it needs to insert the modified data into a history table. Which statement provides the most performant way to insert all the records from the collection into the history table?Show answer details
Correct answer: C
FORALLis the companion toBULK COLLECT. It takes an entire collection and sends all the DML operations (likeINSERT,UPDATE, orDELETE) to the SQL engine in a single call. This bulk binding approach drastically reduces the performance overhead of context switching that occurs when executing DML inside a regular loop. - 8
A financial services application uses a PL/SQL package to calculate loan eligibility. To improve performance for frequently called scenarios, the lead developer decides to use a result-cached function. The function takes a customer ID and loan amount as input. During testing, it's discovered that the function returns stale data if the customer's credit score, stored in a separate
CREDIT_SCOREStable, is updated. Which clause must be added to the function definition to ensure the cache is invalidated when theCREDIT_SCOREStable changes?Show answer details
Correct answer: B
The
RELIES_ONclause is specifically designed for result-cached functions to declare their dependency on database objects. When data in theCREDIT_SCOREStable changes, the database automatically invalidates the function's result cache, ensuring subsequent calls re-execute the function and fetch fresh data.DETERMINISTICis for functions that always return the same result for the same inputs, but it doesn't manage dependencies on table data.PARALLEL_ENABLEis for parallel query execution, andAUTONOMOUS_TRANSACTIONis for independent transactions. - 9
A DBA is reviewing a large PL/SQL package and notices several procedures pass a large record type (defined with %ROWTYPE from a table with 50 columns) as an
IN OUTparameter. The DBA suspects this is causing performance degradation due to excessive copying of the record's data. Which compiler hint should be used in the procedure definition to request pass-by-reference semantics and potentially improve performance?Show answer details
Correct answer: A
The
NOCOPYhint is used in a subprogram's parameter list to request that the compiler pass the corresponding actual parameter by reference instead of by value. This is particularly effective for large composite types like records or collections passed asOUTorIN OUTparameters, as it avoids the overhead of creating a temporary copy of the data. - 10
A developer needs to create a PL/SQL package that will be deployed across different customer environments running Oracle Database 12c, 18c, and 19c. The package should use a new feature available only in 19c when possible, but fall back to an older implementation on earlier database versions. Which PL/SQL feature allows for this version-specific code implementation within a single source file?
Show answer details
Correct answer: C
Conditional compilation allows the PL/SQL compiler to selectively include or exclude code based on conditions evaluated at compile time. By using the
$IFdirective with theDBMS_DB_VERSION.VERSIONinquiry directive, a developer can write code blocks that are only compiled and included in the final package if the database version meets a certain criterion (e.g., is 19c or higher), providing a clean way to manage version-specific logic.
