This document discusses handling exceptions in PL/SQL. It defines exceptions as identifiers raised during execution due to Oracle errors or being explicitly raised. Exceptions can be trapped with handlers or propagated. There are predefined Oracle exceptions as well as user-defined exceptions. Handlers use an EXCEPTION WHEN clause and can trap specific or all exceptions. Functions like SQLCODE and SQLERRM provide error details. The RAISE_APPLICATION_ERROR procedure issues user errors. Exceptions propagate to calling environments if unhandled.
Abstract: Developers - If you are not using Bulk Binds you are not writing PL/SQL efficiently!
Bulk binding has been around for a long time, yet there are sites out there that don't utilise this feature to its full extent, if at all. Every release of Oracle improves on this functionality so obviously it's a topic worthy of consistent awareness.
In PL/SQL and SQL, there are a few nifty features related to bulk binding you may not have seen - it's not all about BULK COLLECT. Whether you're on 8i, 11g or anything in between, you'll benefit from the concepts described in this seminar and become a Bulk Binding Baron!
PL/SQL is a combination of SQL along with the procedural features of programming languages.
It provides specific syntax for this purpose and supports exactly the same datatypes as SQL.
After completing this lesson, you should be able to do the following:
Define PL/SQL exceptions
Recognize unhandled exceptions
List and use different types of PL/SQL exception handlers
Trap unanticipated errors
Describe the effect of exception propagation in nested blocks
Customize PL/SQL exception messages
Abstract: Developers - If you are not using Bulk Binds you are not writing PL/SQL efficiently!
Bulk binding has been around for a long time, yet there are sites out there that don't utilise this feature to its full extent, if at all. Every release of Oracle improves on this functionality so obviously it's a topic worthy of consistent awareness.
In PL/SQL and SQL, there are a few nifty features related to bulk binding you may not have seen - it's not all about BULK COLLECT. Whether you're on 8i, 11g or anything in between, you'll benefit from the concepts described in this seminar and become a Bulk Binding Baron!
PL/SQL is a combination of SQL along with the procedural features of programming languages.
It provides specific syntax for this purpose and supports exactly the same datatypes as SQL.
After completing this lesson, you should be able to do the following:
Define PL/SQL exceptions
Recognize unhandled exceptions
List and use different types of PL/SQL exception handlers
Trap unanticipated errors
Describe the effect of exception propagation in nested blocks
Customize PL/SQL exception messages
Introduction to PL/SQL exceptions
Oracle error codes
Pragmas
User Defined Exception and Pragma EXCEPTION_INIT
DBMS_UTILITY package
Guidelines for exception handling
Guidelines for exception handling - FORALL
Foolproof your PL/SQL programs – Standalone procs and functions
Foolproof your PL/SQL programs - packages
Foolproof your PL/SQL programs - Assumptions
Foolproof your PL/SQL programs - Tracing
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
In today's fast-changing business world, Companies that adapt and embrace new ideas often need help to keep up with the competition. However, fostering a culture of innovation takes much work. It takes vision, leadership and willingness to take risks in the right proportion. Sachin Dev Duggal, co-founder of Builder.ai, has perfected the art of this balance, creating a company culture where creativity and growth are nurtured at each stage.
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
Are you looking to streamline your workflows and boost your projects’ efficiency? Do you find yourself searching for ways to add flexibility and control over your FME workflows? If so, you’re in the right place.
Join us for an insightful dive into the world of FME parameters, a critical element in optimizing workflow efficiency. This webinar marks the beginning of our three-part “Essentials of Automation” series. This first webinar is designed to equip you with the knowledge and skills to utilize parameters effectively: enhancing the flexibility, maintainability, and user control of your FME projects.
Here’s what you’ll gain:
- Essentials of FME Parameters: Understand the pivotal role of parameters, including Reader/Writer, Transformer, User, and FME Flow categories. Discover how they are the key to unlocking automation and optimization within your workflows.
- Practical Applications in FME Form: Delve into key user parameter types including choice, connections, and file URLs. Allow users to control how a workflow runs, making your workflows more reusable. Learn to import values and deliver the best user experience for your workflows while enhancing accuracy.
- Optimization Strategies in FME Flow: Explore the creation and strategic deployment of parameters in FME Flow, including the use of deployment and geometry parameters, to maximize workflow efficiency.
- Pro Tips for Success: Gain insights on parameterizing connections and leveraging new features like Conditional Visibility for clarity and simplicity.
We’ll wrap up with a glimpse into future webinars, followed by a Q&A session to address your specific questions surrounding this topic.
Don’t miss this opportunity to elevate your FME expertise and drive your projects to new heights of efficiency.
DevOps and Testing slides at DASA ConnectKari Kakkonen
My and Rik Marselis slides at 30.5.2024 DASA Connect conference. We discuss about what is testing, then what is agile testing and finally what is Testing in DevOps. Finally we had lovely workshop with the participants trying to find out different ways to think about quality and testing in different parts of the DevOps infinity loop.
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfPaige Cruz
Monitoring and observability aren’t traditionally found in software curriculums and many of us cobble this knowledge together from whatever vendor or ecosystem we were first introduced to and whatever is a part of your current company’s observability stack.
While the dev and ops silo continues to crumble….many organizations still relegate monitoring & observability as the purview of ops, infra and SRE teams. This is a mistake - achieving a highly observable system requires collaboration up and down the stack.
I, a former op, would like to extend an invitation to all application developers to join the observability party will share these foundational concepts to build on:
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™UiPathCommunity
In questo evento online gratuito, organizzato dalla Community Italiana di UiPath, potrai esplorare le nuove funzionalità di Autopilot, il tool che integra l'Intelligenza Artificiale nei processi di sviluppo e utilizzo delle Automazioni.
📕 Vedremo insieme alcuni esempi dell'utilizzo di Autopilot in diversi tool della Suite UiPath:
Autopilot per Studio Web
Autopilot per Studio
Autopilot per Apps
Clipboard AI
GenAI applicata alla Document Understanding
👨🏫👨💻 Speakers:
Stefano Negro, UiPath MVPx3, RPA Tech Lead @ BSP Consultant
Flavio Martinelli, UiPath MVP 2023, Technical Account Manager @UiPath
Andrei Tasca, RPA Solutions Team Lead @NTT Data
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
20. RAISE_APPLICATION_ERROR set serveroutput on DECLARE e_name EXCEPTION; PRAGMA EXCEPTION_INIT (e_name, -20999); --Executable section : BEGIN DELETE FROM employees WHERE last_name = 'Higginss'; IF SQL%NOTFOUND THEN RAISE_APPLICATION_ERROR(-20999,'This is not a valid last name'); END IF; -- Exception section : EXCEPTION WHEN e_name THEN dbms_output.put_line('handle the error'); END; /
21.
22.
23.
Editor's Notes
Schedule: Timing Topic 60 minutes Lecture 30 minutes Practice 90 minutes Total
Lesson Aim In this lesson, you learn what PL/SQL exceptions are and how to deal with them using predefined, nonpredefined, and user-defined exception handlers.
Overview An exception is an identifier in PL/SQL that is raised during the execution of a block that terminates its main body of actions. A block always terminates when PL/SQL raises an exception, but can you specify an exception handler to perform final actions. Two Methods for Raising an Exception • An Oracle error occurs and the associated exception is raised automatically. For example, if the error ORA-01403 occurs when no rows are retrieved from the database in a SELECT statement, then PL/SQL raises the exception NO_DATA_FOUND. • You raise an exception explicitly by issuing the RAISE statement within the block. The exception being raised may be either user-defined or predefined.
Trapping an Exception If the exception is raised in the executable section of the block, processing branches to the corresponding exception handler in the exception section of the block. If PL/SQL successfully handles the exception, then the exception does not propagate to the enclosing block or environment. The PL/SQL block terminates successfully. Propagating an Exception If the exception is raised in the executable section of the block and there is no corresponding exception handler, the PL/SQL block terminates with failure and the exception is propagated to the calling environment.
Exception Types You can program for exceptions to avoid disruption at run time. There are three types of exceptions. Note: Some application tools with client-side PL/SQL, such as Oracle Developer Forms, have their own exceptions. Exception Description Directions for Handling Predefined Oracle Server error One of approximately 20 errors that occur most often in PL/SQL code Do not declare and allow the Oracle server to raise them implicitly Nonpredefined Oracle Server error Any other standard Oracle Server error Declare within the declarative section and allow the Oracle Server to raise them implicitly User-defined error A condition that the developer determines is abnormal Declare within the declarative section, and raise explicitly
Trapping Exceptions You can trap any error by including a corresponding routine within the exception handling section of the PL/SQL block. Each handler consists of a WHEN clause, which specifies an exception, followed by a sequence of statements to be executed when that exception is raised. In the syntax: WHEN OTHERS Exception Handler The exception-handling section traps only those exceptions that are specified; any other exceptions are not trapped unless you use the OTHERS exception handler. This traps any exception not yet handled. For this reason, OTHERS is the last exception handler that is defined. The OTHERS handler traps all exceptions not already trapped. Some Oracle tools have their own predefined exceptions that you can raise to cause events in the application. The OTHERS handler also traps these exceptions. exception is the standard name of a predefined exception or the name of a userdefined exception declared within the declarative section. statement is one or more PL/SQL or SQL statements. OTHERS is an optional exception-handling clause that traps unspecified exceptions.
Guidelines • Begin the exception-handling section of the block with the EXCEPTION keyword. • Define several exception handlers, each with its own set of actions, for the block. • When an exception occurs, PL/SQL processes only one handler before leaving the block. • PlacetheOTHERS clause after all other exception-handling clauses. • You can have only one OTHERS clause. • Exceptions cannot appear in assignment statements or SQL statements.
Trapping Predefined Oracle Server Errors Trap a predefined Oracle Server error by referencing its standard name within the corresponding exception-handling routine. For a complete list of predefined exceptions, see PL/SQL User’s Guide and Reference, “Error Handling.” Note: PL/SQL declares predefined exceptions in the STANDARD package. It is a good idea to always handle the NO_DATA_FOUND and TOO_MANY_ROWS exceptions, which are the most common. Predefined Exceptions Exception Name Oracle Server Error Number Description ACCESS_INTO_NULL ORA- 06530 Attempted to assign values to the attributes of an uninitialized object CASE_NOT_FOUND ORA- 06592 None of the choices in the WHEN clauses of a CASE statement is selected, and there is no ELSE clause. COLLECTION_IS_NULL ORA- 06531 Attempted to apply collection methods other than EXISTS to an uninitialized nested table or varray CURSOR_ALREADY_OPEN ORA- 06511 Attempted to open an already open cursor DUP_VAL_ON_INDEX ORA- 00001 Attempted to insert a duplicate value INVALID_CURSOR ORA- 01001 Illegal cursor operation occurred INVALID_NUMBER ORA- 01722 Conversion of character string to number fails LOGIN_DENIED ORA- 01017 Logging on to Oracle with an invalid username or password NO_DATA_FOUND ORA- 01403 Single row SELECT returned no data NOT_LOGGED_ON ORA- 01012 PL/SQL program issues a database call without being connected to Oracle PROGRAM_ERROR ORA- 06501 PL/SQL has an internal problem ROWTYPE_MISMATCH ORA- 06504 Host cursor variable and PL/SQL cursor variable involved in an assignment have incompatible return types Predefined Exceptions (continued) Exception Name Oracle Server Error Number Description STORAGE_ERROR ORA- 06500 PL/SQL ran out of memory or memory is corrupted. SUBSCRIPT_BEYOND_COUNT ORA- 06533 Referenced a nested table or varray element using an index number larger than the number of elements in the collection. SUBSCRIPT_OUTSIDE_LIMIT ORA- 06532 Referenced a nested table or varray element using an index number that is outside the legal range (–1 for example) SYS_INVALID_ROWID ORA- 01410 The conversion of a character string into a universal ROWID fails because the character string does not represent a valid ROWID. TIMEOUT_ON_RESOURCE ORA- 00051 Time-out occurred while Oracle is waiting for a resource. TOO_MANY_ROWS ORA- 01422 Single-row SELECT returned more than one row. VALUE_ERROR ORA- 06502 Arithmetic, conversion, truncation, or sizeconstraint error occurred. ZERO_DIVIDE ORA- 01476 Attempted to divide by zero
Trapping Predefined Oracle Server Exceptions When an exception is raised, normal execution of your PL/SQL block or subprogram stops and control transfers to its exception-handling part, which is formatted as shown on the slide. To catch raised exceptions, you write exception handlers. Each handler consists of a WHEN clause, which specifies an exception, followed by a sequence of statements to be executed when that exception is raised. These statements complete execution of the block or subprogram; control does not return to where the exception was raised. In other words, you cannot resume processing where you left off. The optional OTHERS exception handler, which, if present, is always the last handler in a block or subprogram, acts as the handler for all exceptions that are not named specifically. Thus, a block or subprogram can have only one OTHERS handler. As the following example shows, use of the OTHERS handler guarantees that no exception will go unhandled: EXCEPTION WHEN ... THEN -- handle the error WHEN ... THEN -- handle the error WHEN OTHERS THEN -- handle all other errors END;
Trapping Nonpredefined Oracle Server Errors You trap a nonpredefined Oracle server error by declaring it first, or by using the OTHERS handler. The declared exception is raised implicitly. In PL/SQL, the PRAGMA EXCEPTION_INIT tells the compiler to associate an exception name with an Oracle error number. That allows you to refer to any internal exception by name and to write a specific handler for it. Note: PRAGMA (also called pseudoinstructions ) is the keyword that signifies that the statement is a compiler directive, which is not processed when the PL/SQL block is executed. Rather, it directs the PL/SQL compiler to interpret all occurrences of the exception name within the block as the associated Oracle server error number.
Trapping a Nonpredefined Oracle Server Exception 1. Declare the name for the exception within the declarative section. Syntax exception EXCEPTION; where: exception is the name of the exception. 2. Associate the declared exception with the standard Oracle server error number using the PRAGMA EXCEPTION_INIT statement. Syntax PRAGMA EXCEPTION_INIT( exception, error_number) ; where: exception is the previously declared exception. error_number is a standard Oracle Server error number. 3. Reference the declared exception within the corresponding exception-handling routine. Example If there are employees in a department, print a message to the user that the department cannot be removed.
Error-Trapping Functions When an exception occurs, you can identify the associated error code or error message by using two functions. Based on the values of the code or message, you can decide which subsequent action to take based on the error. SQLCODE returns the number of the Oracle error for internal exceptions. You can pass an error number to SQLERRM, which then returns the message associated with the error number. Example SQLCODE Values Function Description SQLCODE Returns the numeric value for the error code (You can assign it to a NUMBER variable.) SQLERRM Returns character data containing the message associated with the error number SQLCODE Value Description 0 No exception encountered 1 User-defined exception +100 NO_DATA_FOUND exception negative number Another Oracle server error number
Error-Trapping Functions (continued) When an exception is trapped in the WHEN OTHERS exception handler, you can use a set of generic functions to identify those errors. The example on the slide illustrates the values of SQLCODE and SQLERRM being assigned to variables and then those variables being used in a SQL statement. You cannot use SQLCODE or SQLERRM directly in a SQL statement. Instead, you must assign their values to local variables, then use the variables in the SQL statement, as shown in the following example: DECLARE err_num NUMBER; err_msg VARCHAR2(100); BEGIN ... EXCEPTION ... WHEN OTHERS THEN err_num := SQLCODE; err_msg := SUBSTR(SQLERRM, 1, 100); INSERT INTO errors VALUES (err_num, err_msg); END;
Trapping User-Defined Exceptions PL/SQL allows you to define your own exceptions. User-defined PL/SQL exceptions must be: • Declared in the declare section of a PL/SQL block • Raised explicitly with RAISE statements …
Trapping User-Defined Exceptions (continued) You trap a user-defined exception by declaring it and raising it explicitly. 1. Declare the name for the user-defined exception within the declarative section. Syntax: exception EXCEPTION; where: exception is the name of the exception 2. Use the RAISE statement to raise the exception explicitly within the executable section. Syntax: RAISE exception ; where: exception is the previously declared exception 3. Reference the declared exception within the corresponding exception-handling routine. Example This block updates the description of a department. The user supplies the department number and the new name. If the user enters a department number that does not exist, no rows will be updated in the DEPARTMENTS table. Raise an exception and print a message for the user that an invalid department number was entered. Note: Use the RAISE statement by itself within an exception handler to raise the same exception back to the calling environment.
Propagating Exceptions Instead of trapping an exception within the PL/SQL block, propagate the exception to allow the calling environment to handle it. Each calling environment has its own way of displaying and accessing errors.
Propagating an Exception in a Subblock When a subblock handles an exception, it terminates normally, and control resumes in the enclosing block immediately after the subblock END statement. However, if PL/SQL raises an exception and the current block does not have a handler for that exception, the exception propagates in successive enclosing blocks until it finds a handler. If none of these blocks handle the exception, an unhandled exception in the host environment results. When the exception propagates to an enclosing block, the remaining executable actions in that block are bypassed. One advantage of this behavior is that you can enclose statements that require their own exclusive error handling in their own block, while leaving more general exception handling to the enclosing block. Observe in the example that the exceptions, e_no_rows and e_integrity, are declared in the outer block. In the inner block, when the e_no_rows exception is raised, PL/SQL looks for the exception in the sub block. Because the exception is not declared in the subblock, the exception propagates to the outer block, where PL/SQL finds the declaration.
The RAISE_APPLICATION_ERROR Procedure Use the RAISE_APPLICATION_ERROR procedure to communicate a predefined exception interactively by returning a nonstandard error code and error message. With RAISE_APPLICATION_ERROR, you can report errors to your application and avoid returning unhandled exceptions. In the syntax: error_number is a user-specified number for the exception between –20000 and – 20999. message is the user-specified message for the exception. It is a character string up to 2,048 bytes long. TRUE | FALSE is an optional Boolean parameter (If TRUE, the error is placed on the stack of previous errors. If FALSE, the default, the error replaces all previous errors.)
The RAISE_APPLICATION_ERROR Procedure (continued) RAISE_APPLICATION_ERROR can be used in either (or both) the executable section and the exception section of a PL/SQL program. The returned error is consistent with how the Oracle server produces a predefined, nonpredefined, or user-defined error. The error number and message is displayed to the user.
Example The slide shows that the RAISE_APPLICATION_ERROR procedure can be used in both the executable and exception sections of a PL/SQL program. Here is another example of a RAISE_APPLICATION_ERROR procedure that can be used in both the executable and exception sections of a PL/SQL program: DECLARE e_name EXCEPTION; PRAGMA EXCEPTION_INIT (e_name, -20999); BEGIN ... DELETE FROM employees WHERE last_name = 'Higgins'; IF SQL%NOTFOUND THEN RAISE_APPLICATION_ERROR(-20999,'This is not a valid last name'); END IF; EXCEPTION WHEN e_name THEN -- handle the error ... END; /
Summary In PL/SQL, a warning or error condition is called an exception. Predefined exceptions are error conditions that are defined by the Oracle server. Nonpredefined exceptions are any other standard Oracle Server Error. User-defined exceptions are exceptions specific to your application. Examples of predefined exceptions include division by zero (ZERO_DIVIDE) and out of memory (STORAGE_ERROR). Exceptions without defined names can be assigned names, using the PRAGMA EXCEPTION_INIT statement. You can define exceptions of your own in the declarative part of any PL/SQL block, subprogram, or package. For example, you can define an exception named INSUFFICIENT_FUNDS to flag overdrawn bank accounts. User-defined exceptions must be given names. When an error occurs, an exception is raised. That is, normal execution stops and control transfers to the exception-handling part of your PL/SQL block or subprogram. Internal exceptions are raised implicitly (automatically) by the run-time system. User-defined exceptions must be raised explicitly by RAISE statements, which can also raise predefined exceptions. To handle raised exceptions, you write separate routines called exception handlers. After an exception handler runs, the current block stops executing and the enclosing block resumes with the next statement. If there is no enclosing block, control returns to the host environment.
Practice 8 Overview In this practice, you create exception handlers for specific situations.