SlideShare a Scribd company logo
1 of 3
Create Or Replace Package Assert Authid Definer 
/* 
Assertion Package 
Provides a set of procedures you can use to *assert* 
that a required condition is met. If not, an 
error is raised, stopping execution of the block. 
Author: Steven Feuerstein Technology: Oracle PL/SQL 
Author: Steven Feuerstein, steven@stevenfeuerstein.com 
You have permission to use and alter this code 
without any restrictions. 
Example: 
PROCEDURE calc_totals ( 
dept_in IN INTEGER, 
date_in IN DATE 
) 
IS 
bad_date EXCEPTION; 
BEGIN 
assert.is_null (dept_in, 'Department ID'); 
assert.inrange ( 
date_in, 
ADD_MONTHS (SYSDATE, -60), 
SYSDATE 
); 
-- Everything's fine. Code in confidence... 
END; 
*/ 
Is 
Procedure Assert(Condition_In In Boolean, 
Msg_In In Varchar2, 
Display_Call_Stack_In In Boolean Default False, 
Null_Means_Failure_In In Boolean Default True); 
Procedure Is_Null(Val_In In Varchar2, 
Msg_In In Varchar2, 
Display_Call_Stack_In In Boolean Default False); 
Procedure Is_Not_Null(Val_In In Varchar2, 
Msg_In In Varchar2, 
Display_Call_Stack_In In Boolean Default False); 
Procedure Is_True(Condition_In In Boolean, 
Msg_In In Varchar2, 
Display_Call_Stack_In In Boolean Default False); 
Procedure Is_False(Condition_In In Boolean, 
Msg_In In Varchar2, 
Display_Call_Stack_In In Boolean Default False); 
Procedure Is_In_Range(Date_In In Date, 
Low_Date_In In Date, 
High_Date_In In Date, 
Msg_In In Varchar2, 
Display_Call_Stack_In In Boolean Default False); 
Function Is_Correct_Date(p_Str In Varchar2, 
Format_Picture In Out Nocopy Varchar2)
Return Boolean; 
End Assert; 
/ 
SHOW ERRORS PACKAGE ASSERT 
Create Or Replace Package Body Assert Is 
Procedure Assert(Condition_In In Boolean, 
Msg_In In Varchar2, 
Display_Call_Stack_In In Boolean Default False, 
Null_Means_Failure_In In Boolean Default True) Is 
Begin 
If Not Condition_In Or (Null_Means_Failure_In And Condition_In Is Null) Then 
If Display_Call_Stack_In Then 
Dbms_Output.Put_Line('ASSERTION VIOLATION! ' || Msg_In); 
Dbms_Output.Put_Line('Path taken to assertion violation:'); 
Dbms_Output.Put_Line(Dbms_Utility.Format_Call_Stack); 
End If; 
Raise_Application_Error(-20000, 'ASSERTION VIOLATION! ' || Msg_In); 
End If; 
End; 
Procedure Is_Null(Val_In In Varchar2, 
Msg_In In Varchar2, 
Display_Call_Stack_In In Boolean Default False) Is 
Begin 
Assert(Val_In Is Null, 
Msg_In, 
Display_Call_Stack_In, 
Null_Means_Failure_In => False); 
End Is_Null; 
Procedure Is_Not_Null(Val_In In Varchar2, 
Msg_In In Varchar2, 
Display_Call_Stack_In In Boolean Default False) Is 
Begin 
Assert(Val_In Is Not Null, Msg_In, Display_Call_Stack_In); 
End Is_Not_Null; 
Procedure Is_True(Condition_In In Boolean, 
Msg_In In Varchar2, 
Display_Call_Stack_In In Boolean Default False) Is 
Begin 
Assert(Condition_In, Msg_In, Display_Call_Stack_In); 
End Is_True; 
Procedure Is_False(Condition_In In Boolean, 
Msg_In In Varchar2, 
Display_Call_Stack_In In Boolean Default False) Is 
Begin 
Assert(Not Condition_In, Msg_In, Display_Call_Stack_In); 
End Is_False; 
Procedure Is_In_Range(Date_In In Date, 
Low_Date_In In Date, 
High_Date_In In Date, 
Msg_In In Varchar2, 
Display_Call_Stack_In In Boolean Default False) Is 
Begin 
Assert(Trunc(Date_In) Between Trunc(Low_Date_In) And 
Trunc(High_Date_In), 
Msg_In, 
Display_Call_Stack_In); 
End Is_In_Range; 
Function Is_Correct_Date(p_Str In Varchar2,
Format_Picture In Out Nocopy Varchar2) 
Return Boolean As 
l_Date Date; 
Begin 
If Format_Picture Is Null Then 
Format_Picture := 'FXYYYYMMDD'; 
End If; 
l_Date := To_Date(p_Str, Format_Picture); 
Return True; 
Exception 
When Others Then 
Return False; 
End Is_Correct_Date; 
End Assert; 
/ 
SHOW ERRORS PACKAGE BODY ASSERT

More Related Content

Viewers also liked

Oracle contract by desing la gestione errori
Oracle contract by desing la gestione erroriOracle contract by desing la gestione errori
Oracle contract by desing la gestione erroriCarlo Ticozzi
 
Pl sql contract_desing
Pl sql contract_desingPl sql contract_desing
Pl sql contract_desingCarlo Ticozzi
 
Bank po modelpaper
Bank po modelpaperBank po modelpaper
Bank po modelpaperAkella Murty
 
Sviluppo software - Il contract design
Sviluppo software - Il contract designSviluppo software - Il contract design
Sviluppo software - Il contract designCarlo Ticozzi
 
Lic of india apprentice development officers
Lic of india apprentice development officersLic of india apprentice development officers
Lic of india apprentice development officersAkella Murty
 
Case Study - Project Management
Case Study - Project Management Case Study - Project Management
Case Study - Project Management Jimmy Horn
 
Big Data in E-commerce
Big Data in E-commerceBig Data in E-commerce
Big Data in E-commerceJimmy Horn
 
Blue Bottle Café
Blue Bottle CaféBlue Bottle Café
Blue Bottle CaféJimmy Horn
 

Viewers also liked (16)

Clothes Review
Clothes ReviewClothes Review
Clothes Review
 
Oracle contract by desing la gestione errori
Oracle contract by desing la gestione erroriOracle contract by desing la gestione errori
Oracle contract by desing la gestione errori
 
Pl sql contract_desing
Pl sql contract_desingPl sql contract_desing
Pl sql contract_desing
 
Roald Dhal
Roald Dhal Roald Dhal
Roald Dhal
 
Bank po modelpaper
Bank po modelpaperBank po modelpaper
Bank po modelpaper
 
Sbi modal paper
Sbi modal paperSbi modal paper
Sbi modal paper
 
Sviluppo software - Il contract design
Sviluppo software - Il contract designSviluppo software - Il contract design
Sviluppo software - Il contract design
 
Lic of india apprentice development officers
Lic of india apprentice development officersLic of india apprentice development officers
Lic of india apprentice development officers
 
Pegasus Airlines
Pegasus AirlinesPegasus Airlines
Pegasus Airlines
 
An Inspector Calls
An Inspector CallsAn Inspector Calls
An Inspector Calls
 
Just Jogging!
Just Jogging!Just Jogging!
Just Jogging!
 
Mozbii
MozbiiMozbii
Mozbii
 
Poetry: Limericks
Poetry: Limericks Poetry: Limericks
Poetry: Limericks
 
Case Study - Project Management
Case Study - Project Management Case Study - Project Management
Case Study - Project Management
 
Big Data in E-commerce
Big Data in E-commerceBig Data in E-commerce
Big Data in E-commerce
 
Blue Bottle Café
Blue Bottle CaféBlue Bottle Café
Blue Bottle Café
 

Similar to Package assert

How to transfer bad PLSQL into good (AAAPEKS23)
How to transfer bad PLSQL into good (AAAPEKS23)How to transfer bad PLSQL into good (AAAPEKS23)
How to transfer bad PLSQL into good (AAAPEKS23)Maik Becker
 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Aaron Gustafson
 
Modernising Legacy Code
Modernising Legacy CodeModernising Legacy Code
Modernising Legacy CodeSamThePHPDev
 
Using of TDD practices for Magento
Using of TDD practices for MagentoUsing of TDD practices for Magento
Using of TDD practices for MagentoIvan Chepurnyi
 
Exception Handling - The Good, the Bad and the Maybe (APEXCONN23)
Exception Handling - The Good, the Bad and the Maybe (APEXCONN23)Exception Handling - The Good, the Bad and the Maybe (APEXCONN23)
Exception Handling - The Good, the Bad and the Maybe (APEXCONN23)Maik Becker
 
Creating "Secure" PHP Applications, Part 1, Explicit Code & QA
Creating "Secure" PHP Applications, Part 1, Explicit Code & QACreating "Secure" PHP Applications, Part 1, Explicit Code & QA
Creating "Secure" PHP Applications, Part 1, Explicit Code & QAarchwisp
 
Oracle PL/SQL - Creative Conditional Compilation
Oracle PL/SQL - Creative Conditional CompilationOracle PL/SQL - Creative Conditional Compilation
Oracle PL/SQL - Creative Conditional CompilationScott Wesley
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitMichelangelo van Dam
 
Presentation slides: "How to get 100% code coverage"
Presentation slides: "How to get 100% code coverage" Presentation slides: "How to get 100% code coverage"
Presentation slides: "How to get 100% code coverage" Rapita Systems Ltd
 
Cursor injection
Cursor injectionCursor injection
Cursor injectionfangjiafu
 
Oracle APEX Performance
Oracle APEX PerformanceOracle APEX Performance
Oracle APEX PerformanceScott Wesley
 
What We Talk About When We Talk About Unit Testing
What We Talk About When We Talk About Unit TestingWhat We Talk About When We Talk About Unit Testing
What We Talk About When We Talk About Unit TestingKevlin Henney
 
MT_01_unittest_python.pdf
MT_01_unittest_python.pdfMT_01_unittest_python.pdf
MT_01_unittest_python.pdfHans Jones
 
The Magic of Advanced Debugging
The Magic of Advanced DebuggingThe Magic of Advanced Debugging
The Magic of Advanced DebuggingIvelina Dimova
 
JavaScript Proven Practises
JavaScript Proven PractisesJavaScript Proven Practises
JavaScript Proven PractisesRobert MacLean
 

Similar to Package assert (20)

How to transfer bad PLSQL into good (AAAPEKS23)
How to transfer bad PLSQL into good (AAAPEKS23)How to transfer bad PLSQL into good (AAAPEKS23)
How to transfer bad PLSQL into good (AAAPEKS23)
 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]
 
Modernising Legacy Code
Modernising Legacy CodeModernising Legacy Code
Modernising Legacy Code
 
Using of TDD practices for Magento
Using of TDD practices for MagentoUsing of TDD practices for Magento
Using of TDD practices for Magento
 
Exception Handling - The Good, the Bad and the Maybe (APEXCONN23)
Exception Handling - The Good, the Bad and the Maybe (APEXCONN23)Exception Handling - The Good, the Bad and the Maybe (APEXCONN23)
Exception Handling - The Good, the Bad and the Maybe (APEXCONN23)
 
Creating "Secure" PHP Applications, Part 1, Explicit Code & QA
Creating "Secure" PHP Applications, Part 1, Explicit Code & QACreating "Secure" PHP Applications, Part 1, Explicit Code & QA
Creating "Secure" PHP Applications, Part 1, Explicit Code & QA
 
Oracle PL/SQL - Creative Conditional Compilation
Oracle PL/SQL - Creative Conditional CompilationOracle PL/SQL - Creative Conditional Compilation
Oracle PL/SQL - Creative Conditional Compilation
 
PHPUnit testing to Zend_Test
PHPUnit testing to Zend_TestPHPUnit testing to Zend_Test
PHPUnit testing to Zend_Test
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnit
 
Stored procedure
Stored procedureStored procedure
Stored procedure
 
Test driven development_for_php
Test driven development_for_phpTest driven development_for_php
Test driven development_for_php
 
Presentation slides: "How to get 100% code coverage"
Presentation slides: "How to get 100% code coverage" Presentation slides: "How to get 100% code coverage"
Presentation slides: "How to get 100% code coverage"
 
Cursor injection
Cursor injectionCursor injection
Cursor injection
 
Oracle APEX Performance
Oracle APEX PerformanceOracle APEX Performance
Oracle APEX Performance
 
What We Talk About When We Talk About Unit Testing
What We Talk About When We Talk About Unit TestingWhat We Talk About When We Talk About Unit Testing
What We Talk About When We Talk About Unit Testing
 
ES2015 workflows
ES2015 workflowsES2015 workflows
ES2015 workflows
 
MT_01_unittest_python.pdf
MT_01_unittest_python.pdfMT_01_unittest_python.pdf
MT_01_unittest_python.pdf
 
PHP Unit Testing
PHP Unit TestingPHP Unit Testing
PHP Unit Testing
 
The Magic of Advanced Debugging
The Magic of Advanced DebuggingThe Magic of Advanced Debugging
The Magic of Advanced Debugging
 
JavaScript Proven Practises
JavaScript Proven PractisesJavaScript Proven Practises
JavaScript Proven Practises
 

Recently uploaded

chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 

Recently uploaded (20)

chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 

Package assert

  • 1. Create Or Replace Package Assert Authid Definer /* Assertion Package Provides a set of procedures you can use to *assert* that a required condition is met. If not, an error is raised, stopping execution of the block. Author: Steven Feuerstein Technology: Oracle PL/SQL Author: Steven Feuerstein, steven@stevenfeuerstein.com You have permission to use and alter this code without any restrictions. Example: PROCEDURE calc_totals ( dept_in IN INTEGER, date_in IN DATE ) IS bad_date EXCEPTION; BEGIN assert.is_null (dept_in, 'Department ID'); assert.inrange ( date_in, ADD_MONTHS (SYSDATE, -60), SYSDATE ); -- Everything's fine. Code in confidence... END; */ Is Procedure Assert(Condition_In In Boolean, Msg_In In Varchar2, Display_Call_Stack_In In Boolean Default False, Null_Means_Failure_In In Boolean Default True); Procedure Is_Null(Val_In In Varchar2, Msg_In In Varchar2, Display_Call_Stack_In In Boolean Default False); Procedure Is_Not_Null(Val_In In Varchar2, Msg_In In Varchar2, Display_Call_Stack_In In Boolean Default False); Procedure Is_True(Condition_In In Boolean, Msg_In In Varchar2, Display_Call_Stack_In In Boolean Default False); Procedure Is_False(Condition_In In Boolean, Msg_In In Varchar2, Display_Call_Stack_In In Boolean Default False); Procedure Is_In_Range(Date_In In Date, Low_Date_In In Date, High_Date_In In Date, Msg_In In Varchar2, Display_Call_Stack_In In Boolean Default False); Function Is_Correct_Date(p_Str In Varchar2, Format_Picture In Out Nocopy Varchar2)
  • 2. Return Boolean; End Assert; / SHOW ERRORS PACKAGE ASSERT Create Or Replace Package Body Assert Is Procedure Assert(Condition_In In Boolean, Msg_In In Varchar2, Display_Call_Stack_In In Boolean Default False, Null_Means_Failure_In In Boolean Default True) Is Begin If Not Condition_In Or (Null_Means_Failure_In And Condition_In Is Null) Then If Display_Call_Stack_In Then Dbms_Output.Put_Line('ASSERTION VIOLATION! ' || Msg_In); Dbms_Output.Put_Line('Path taken to assertion violation:'); Dbms_Output.Put_Line(Dbms_Utility.Format_Call_Stack); End If; Raise_Application_Error(-20000, 'ASSERTION VIOLATION! ' || Msg_In); End If; End; Procedure Is_Null(Val_In In Varchar2, Msg_In In Varchar2, Display_Call_Stack_In In Boolean Default False) Is Begin Assert(Val_In Is Null, Msg_In, Display_Call_Stack_In, Null_Means_Failure_In => False); End Is_Null; Procedure Is_Not_Null(Val_In In Varchar2, Msg_In In Varchar2, Display_Call_Stack_In In Boolean Default False) Is Begin Assert(Val_In Is Not Null, Msg_In, Display_Call_Stack_In); End Is_Not_Null; Procedure Is_True(Condition_In In Boolean, Msg_In In Varchar2, Display_Call_Stack_In In Boolean Default False) Is Begin Assert(Condition_In, Msg_In, Display_Call_Stack_In); End Is_True; Procedure Is_False(Condition_In In Boolean, Msg_In In Varchar2, Display_Call_Stack_In In Boolean Default False) Is Begin Assert(Not Condition_In, Msg_In, Display_Call_Stack_In); End Is_False; Procedure Is_In_Range(Date_In In Date, Low_Date_In In Date, High_Date_In In Date, Msg_In In Varchar2, Display_Call_Stack_In In Boolean Default False) Is Begin Assert(Trunc(Date_In) Between Trunc(Low_Date_In) And Trunc(High_Date_In), Msg_In, Display_Call_Stack_In); End Is_In_Range; Function Is_Correct_Date(p_Str In Varchar2,
  • 3. Format_Picture In Out Nocopy Varchar2) Return Boolean As l_Date Date; Begin If Format_Picture Is Null Then Format_Picture := 'FXYYYYMMDD'; End If; l_Date := To_Date(p_Str, Format_Picture); Return True; Exception When Others Then Return False; End Is_Correct_Date; End Assert; / SHOW ERRORS PACKAGE BODY ASSERT