The RESETTABLE clause introduced in Oracle 26ai, it is beneficial to avoid -ORA04068 error when the existing state of the package has been discarded.
The RESETTABLE clause can be used in package or package body during the creation. But note that users cannot be able to use RESETTABLE clause in combination with the SERIALLY_REUSABLE pragma.
Syntax: - CREATE OR REPLACE PACKAGE [BODY] RESETTABLE
Using below sample package and package body for demonstration
SQL> CREATE OR REPLACE PACKAGE sales_pkg AS
g_total_sales NUMBER := 0;
PROCEDURE add_sale;
END sales_pkg;
/
Package created
SQL> CREATE OR REPLACE PACKAGE BODY sales_pkg AS
PROCEDURE add_sale IS
BEGIN
g_total_sales := g_total_sales + 100; -- adds a fixed sale amount
DBMS_OUTPUT.PUT_LINE('Total Sales = ' || g_total_sales);
END;
END sales_pkg;
/
Package body created
We will use two different sessions for demonstration
Session 1: execute the package
SQL> EXEC sales_pkg.add_sale;
Total Sales = 100
Session 2: recompile the package
SQL> ALTER PACKAGE sales_pkg COMPILE;
Package altered
Return to Session 1:
SQL> EXEC sales_pkg.add_sale;
ORA-04068: existing state of packages has been discarded
ORA-04061: existing state of package "SALES_PKG.ADD_SALE" has been invalidated
ORA-04065: not executed, altered or dropped package "SALES_PKG.ADD_SALE"
ORA-06508: PL/SQL: could not find program unit being called: "SALES_PKG.ADD_SALE"
Session 2: recompile the package
SQL> ALTER PACKAGE sales_pkg COMPILE;
Package altered
Return to Session 1:
SQL> EXEC sales_pkg.add_sale;
ORA-04068: existing state of packages has been discarded
ORA-04061: existing state of package "SALES_PKG.ADD_SALE" has been invalidated
ORA-04065: not executed, altered or dropped package "SALES_PKG.ADD_SALE"
ORA-06508: PL/SQL: could not find program unit being called: "SALES_PKG.ADD_SALE"
....
The main reason you are receiving this error because Oracle discards the package state when it is recompiled. When user run next time, it will reinitialize the package.
SQL> EXEC sales_pkg.add_sale;
Total Sales = 100
SQL> EXEC sales_pkg.add_sale;
Total Sales = 200
Now we will modify our sample code with RESETTABLE clause
The main reason you are receiving this error because Oracle discards the package state when it is recompiled. When user run next time, it will reinitialize the package.
SQL> EXEC sales_pkg.add_sale;
Total Sales = 100
SQL> EXEC sales_pkg.add_sale;
Total Sales = 200
Now we will modify our sample code with RESETTABLE clause
SQL> CREATE OR REPLACE PACKAGE sales_pkg RESETTABLE AS
g_total_sales NUMBER := 0;
PROCEDURE add_sale;
END sales_pkg;
/
Package created
g_total_sales NUMBER := 0;
PROCEDURE add_sale;
END sales_pkg;
/
Package created
SQL> CREATE OR REPLACE PACKAGE BODY sales_pkg RESETTABLE AS
PROCEDURE add_sale IS
BEGIN
g_total_sales := g_total_sales + 100; -- adds a fixed sale amount
DBMS_OUTPUT.PUT_LINE('Total Sales = ' || g_total_sales);
END;
END sales_pkg;
/
Package body created
We will repeat the same exercise to observe how the RESETTABLE clause affects the package’s behavior.
Session 1: execute the package
SQL> EXEC sales_pkg.add_sale;
Total Sales = 100
Session 2: recompile the package
SQL> ALTER PACKAGE sales_pkg COMPILE;
Package altered
Return to Session 1: execute the package again
SQL> EXEC sales_pkg.add_sale;
Total Sales = 100
SQL> EXEC sales_pkg.add_sale;
Total Sales = 200
In the second scenario, when Oracle detects that a package’s state is no longer valid, it automatically reinitializes the package instead of raising an ORA-04068 error. By using the RESETTABLE clause, the package can safely discard its state and reinitialize without causing any errors to user session.
PROCEDURE add_sale IS
BEGIN
g_total_sales := g_total_sales + 100; -- adds a fixed sale amount
DBMS_OUTPUT.PUT_LINE('Total Sales = ' || g_total_sales);
END;
END sales_pkg;
/
Package body created
We will repeat the same exercise to observe how the RESETTABLE clause affects the package’s behavior.
Session 1: execute the package
SQL> EXEC sales_pkg.add_sale;
Total Sales = 100
Session 2: recompile the package
SQL> ALTER PACKAGE sales_pkg COMPILE;
Package altered
Return to Session 1: execute the package again
SQL> EXEC sales_pkg.add_sale;
Total Sales = 100
SQL> EXEC sales_pkg.add_sale;
Total Sales = 200
In the second scenario, when Oracle detects that a package’s state is no longer valid, it automatically reinitializes the package instead of raising an ORA-04068 error. By using the RESETTABLE clause, the package can safely discard its state and reinitialize without causing any errors to user session.
When I first enrolled in my HNC program, I didn’t realize how demanding the assignments would be. Managing topics from different disciplines was extremely difficult and I often struggled to meet submission deadlines. After using HNC Assignment Help I noticed a significant change in my academic journey. The experts explained complex subjects in a simple way and taught me how to structure my reports efficiently. Rapid Assignment Help provided projects that were accurate, insightful, and aligned with my course requirements. Their professional guidance helped me gain a better grasp of key concepts and achieve higher marks in my assessments.
ReplyDeleteChoosing the right mill machine is one of the most important decisions for any manufacturing or processing plant. Heico Dynamics explores the top factors to consider before buying a mill machine.
ReplyDeleteMany students face challenges when dealing with Python programming assignments that require strong analytical and problem-solving skills. Professional academic experts provide step-by-step solutions that follow university guidelines and marking criteria. Using a trusted Python Assignment Writing Service midway through your coursework helps manage workload effectively while ensuring quality outcomes. From basic scripts to advanced AI-based projects, expert writers handle everything with precision. Clear explanations, error-free code, and on-time delivery make this support valuable for students aiming to balance studies, part-time work, and personal commitments without sacrificing academic performance.
ReplyDeleteGet expert-led Pega training online with real-time project exposure.
ReplyDeleteThe course covers core and advanced Pega concepts.
Industry use cases improve practical understanding.
A smart choice for remote learners.
Nice overview of mobile development.This Android training focuses on real apps.
ReplyDelete"Boost your career with our salesforce admin coursedesigned for beginners and professionals alike. Learn to manage Salesforce efficiently and unlock high-demand admin skills."
ReplyDelete