You are on page 1of 3

3/10/2021 ORACLE SQL, PL/SQL: Handling BULK EXCEPTION

More

Select Language Powered by Translate

ORACLE Topics
Handling BULK EXCEPTION COLLECTIONS and TYPES of COLLECTI
How BULK COLLECT is used with FORALL SAVE EXCEPTIONS? (Handling Exception with BULK Collect) Which Collection type should be used?
PL/SQL provides the different ways of handling exceptions. The Bulk Exceptions are used to save the exception information and continue Examples of COLLECTIONS and
processing. COLLECTION Methods
All exceptions raised during execution are saved in %BULK_EXCEPTION attribute. It also stores a collection of records similar to BULK COLLECT. DATABASE Normalization Techniques
PACKAGE Overloading
• %BULK_EXCEPTIONS(i).ERROR_CODE holds the corresponding Oracle error code.
Creating PACKAGES and Call it's Metho
• %BULK_EXCEPTIONS(i).ERROR_INDEX holds the iteration number of the FORALL statement.
ORACLE 11g Features
• %BULK_EXCEPTIONS.COUNT holds total number of exceptions encountered.
CONTINUE and CONTINUE WHEN
Statement
In order to bulk collect exceptions, we have to use FORALL clause with SAVE EXCEPTIONS keyword.
Passing parameters in
Functions/Procedures
• Connect to SQL*Plus with proper credentials and run following query to create the table and populate it with some data.
CREATE TABLE TEST Stored Procedure Vs. Functions
( SQL Query Order Execution
Test_ID NUMBER(9) NOT NULL PRIMARY KEY, DWH(OLAP) Vs. Operational DB(OLTP)
Test_Desc VARCHAR(15), Data Migration Steps and SCD Changes
New_Desc VARCHAR(15) ROLLBACK behaviour when FOR ALL is
) used
Handling BULK Exception using SAVE
EXCEPTION
> DESC TEST;
Name Null? Type BULK Collect with NATIVE Dynamic SQ
----------------------------------------- -------- ---------------------------- BULK Collect and Collection of Record
TEST_ID NOT NULL NUMBER(9)
Using BULK Collect and BULK Binds
TEST_DESC VARCHAR2(15)
NEW_DESC VARCHAR2(15) ORACLE Table Locking
How to kill ORACLE Session?
SQL> SELECT * FROM TEST;
Handling PL/SQL Errors(Exception
TEST_ID TEST_DESC NEW_DESC Handling)
---------- --------------- --------------- RAISE_APPLICATION_ERROR Built-IN
101 Selecting Procedure
102 Inserting Data
103 Delete Records Exception Trapping Functions
104 Trigger Records WHERE and HAVING clause Alternative
105 Create View
TRIGGER and Types of TRIGGERS
Identify Columns having all NULLS
Run following PL/SQL block to populate the table and later on update it to see the exception behaviour. TABLE Vs. MATERIALIZED View
VIEWS in ORACLE
SYNONYMS in ORACLE
DECLARE How INDEXES stored in DB
Local and Global Indexes
TYPE Test_ID IS TABLE OF TEST.TEST_Id%TYPE;
CLUSTERED and NON-CLUSTERED Inde
TYPE Test_Desc IS TABLE OF TEST.TEST_DESC%TYPE; INDEXES in ORACLE
Opening Parameterized Cursor in
v_Test_ID Test_ID; Different ways
Sub-Queries-And-Types-of-Sub-Querie
v_Test_Desc Test_Desc;
COMMIT inside Trigger
v_Err_count NUMBER; Difference between Primary and Uniq
Key
BEGIN Difference between %TYPE Vs.
%ROWTYPE
SELECT Test_ID, Test_Desc WITH Clause in ORACLE
DECODE Vs. CASE
BULK COLLECT INTO v_Test_ID, v_Test_Desc
ROWNUM Vs. ROW_NUMBER()
FROM Test; ROWNUM Vs. ROWID
INSERT and DELETE Execution Plan
FORALL i IN v_test_ID.FIRST..v_test_ID.LAST SAVE EXCEPTIONS
Different types of JOINs in ORACLE
UPDATE TEST NOT IN Vs. NOT EXISTS Operator

https://tipsfororacle.blogspot.com/2016/10/handling-bulk-exception.html 1/3
3/10/2021 ORACLE SQL, PL/SQL: Handling BULK EXCEPTION
SET NEW_DESC = TO_CHAR(TEST_ID)||TEST_DESC IN Vs. EXISTS Operator
How Count Function behaves with
WHERE TEST_ID = v_test_ID(i); different operators
DELETE Vs. TRUNCATE Vs. DROP
Commit;
Find Highest/Minimum Salary and
EXCEPTION
Employee Information
Identify and Remove DUPLICATE Recor
WHEN OTHERS THEN MUTATING Table Error and How to Avo
It.
v_Err_Count := SQL%BULK_EXCEPTIONS.COUNT; GLOBAL TEMPORARY Tables in ORACLE
CHAR-NCHAR-VARCHAR-VARCHAR2-
DBMS_OUTPUT.PUT_LINE('Number of statements that failed: ' || v_Err_Count);
NVARCHAR

FOR i IN 1..v_Err_Count UNION Vs. UNION ALL(SET OPERATORS


How CURSOR works Internally?
LOOP ORACLE Cursors and its Types
Separate NUMERIC/NON-NUMERIC/DAT
DBMS_OUTPUT.PUT_LINE('Error #' || i || ' occurred during '||'Iteration #' || SQL%BULK_EXCEPTIONS(i).ERROR_INDEX);
values From a Column

DBMS_OUTPUT.PUT_LINE('Error message is ' ||


ANALYTICAL Vs. AGGREGATE Function
DBMS_PROFILER Installation Steps
SQLERRM(-SQL%BULK_EXCEPTIONS(i).ERROR_CODE)); How DBMS_PROFILER helps in identify
long running SQL's
END LOOP;
ORACLE SQL Tuning Tips
Dynamic Where Clause
END;
ORACLE SQL EXECUTION PLAN
COLLECTION having NULL Values
If you execute above PL/SQL block, it will display following information based on Data inserted into your table. ORACLE SQL* Loader
ORACLE External Tables
SQL> DECLARE
2 TYPE Test_ID IS TABLE OF TEST.TEST_Id%TYPE; RULE BASED and COST BASED OPTIMIZ
3 TYPE Test_Desc IS TABLE OF TEST.TEST_DESC%TYPE; OPTIMIZER Modes in ORACLE
4 v_Test_ID Test_ID;
5 v_Test_Desc Test_Desc; ORACLE Driving Tables
6 v_Err_count NUMBER; EXECUTION PLAN and It's Components
7
CURSOR_SHARING in ORACLE
8 BEGIN
9 SELECT Test_ID, Test_Desc INDEX Usage with LIKE Operator and
10 BULK COLLECT INTO v_Test_ID, v_Test_Desc FROM Test; DOMAIN Index
11 FORALL i IN v_test_ID.FIRST..v_test_ID.LAST SAVE EXCEPTIONS DYNAMIC_SAMPLING and its Impact on
12 UPDATE TEST OPTIMIZER
13 SET NEW_DESC = TO_CHAR(TEST_ID)||TEST_DESC
14 WHERE TEST_ID = v_test_ID(i); NOT NULL and Indexed Column
15 Commit; ORACLE AUTOTRACE Utility
16
17 EXCEPTION Pass COMMA Separated Value to IN
18 WHEN OTHERS THEN Operator
19 v_Err_Count := SQL%BULK_EXCEPTIONS.COUNT; ANALYTICAL & AGGREGATE Functions
20 DBMS_OUTPUT.PUT_LINE('Number of statements that failed: ' || v_Err_Count); Examples
21
ORACLE UTL_FILE Package
22 FOR i IN 1..v_Err_Count
23 LOOP ORACLE UTL_FILE Exceptions
24 DBMS_OUTPUT.PUT_LINE('Error #' || i || ' occurred during '||'Iteration #' || SQL%BULK_EXCEPTIONS(i).ERROR_INDE UTL_FILE Operations and Functions
25 DBMS_OUTPUT.PUT_LINE('Error message is ' ||
26 SQLERRM(-SQL%BULK_EXCEPTIONS(i).ERROR_CODE)); Comma Separated Values
27 END LOOP; RETURNING Table From a Function
28 END;
29 / REGULAR Expressions in ORACLE
Number of statements that failed: 3 RESTRICT DROP/TRUNCATE on TABLE
Error #1 occurred during Iteration #2
Export Table Data to CSV
Error message is ORA-12899: value too large for column (actual: , maximum: )
Error #2 occurred during Iteration #3 IMPORT Data from Flat Files to ORACL
Error message is ORA-12899: value too large for column (actual: , maximum: ) Tables
Error #3 occurred during Iteration #4
ORACLE PIVOT/UNPIVOT
Error message is ORA-12899: value too large for column (actual: , maximum: )
PARTITIONING IN ORACLE
PL/SQL procedure successfully completed. Equality Test of Two COLLECTION Type
Compare and Merge COLLECTION Obje
NESTED Table Functions
Check the Table Data-
DETERMINISTIC FUNCTIONS

> SELECT * FROM TEST; HANDLING CURSOR Exceptions


When CROSS JOIN Will Be Useful?
TEST_ID TEST_DESC NEW_DESC
DML Error Logging
---------- --------------- ---------------
101 Selecting 101Selecting Handle CONCURRENT Updates
102 Inserting Data
Pessimistic and Optimistic Oracle Lock
103 Delete Records
104 Trigger Records Returning REF CURSOR From a Proced
105 Create View 105Create View Prevent VALUE_ERROR Exception
SYS_REFCURSOR Vs. REF CURSOR

Popular Posts
It's RUDE to Read and Run!
Analytic Functions Vs. Aggregate
Get involved and leave your Comments in the Box Below. The more people get involved, the more we all bene it. So, l eave your thoughts
Functions
before you l eave the page.

https://tipsfororacle.blogspot.com/2016/10/handling-bulk-exception.html 2/3
3/10/2021 ORACLE SQL, PL/SQL: Handling BULK EXCEPTION

Difference Between %TYPE and


%ROWTYPE

3 comments: DECODE Vs. CASE

ROWNUM Vs. ROW_NUMBER()


Rifath August 25, 2019 at 12:45 AM
ORACLE COLLECTIONS
Nice blog, Thanks For Sharing This Informative Article.
Oracle Fusion SCM Online Training
HANDLE EXCEPTIONS INSIDE CURSOR
Oracle Fusion Financials Online Training LOOP
Reply
UTL_FILE Import Data into ORACLE TA

EXPORT TABLE Data to Flat Files


Rainbow Training Institute September 15, 2019 at 4:04 AM
SYS_REFCURSOR Vs. REF CURSOR
Such a nice blog, I really like what you write in this blog, I also have some relevant information about if you want more
information.
ORACLE SQL* Loader

Oracle Fusion HCM Online Training


Reply

yoyo December 5, 2020 at 2:27 AM


Thanks for another excellent post. Where else could anybody get that type of info in such an ideal way of writing? In my
opinion, my seeking has ended now. handling equipment
Reply

Enter your comment...

Comment as: Google Accou

Publish Preview

Newer Post Home Older Post

Subscribe to: Post Comments (Atom)

BaluniGroups. Travel theme. Powered by Blogger.

https://tipsfororacle.blogspot.com/2016/10/handling-bulk-exception.html 3/3

You might also like