PL/SQL Sample code and error handling mechanism

SAMPLE PL/SQL


CREATE TABLE dummy
( dummy_value       VARCHAR2(1));
DECLARE
  -- Define local variable.
  my_string VARCHAR2(1) := ' ';
  my_number NUMBER;
BEGIN
  -- Select a white space into a local variable.
  SELECT ' ' INTO my_string FROM dummy;
  -- Attempt to assign a single white space to a number.
  my_number := TO_NUMBER(my_string);
EXCEPTION
 WHEN no_data_found THEN
   dbms_output.put_line('SELECT-INTO'||CHR(10)||SQLERRM);
END;
/

Output and Error:
The program returns the following output, which illustrates formatting user- defined exceptions. 

The CHR(10) inserts a line return and provides a clean break between the program's SQLCODE and SQLERRM messages:

RAISE my_error SQLCODE [1] 
SQLERRM [User-Defined Exception]

Comments

Popular Posts

How to Fix Python Syntax Errors Quickly

7 AWS Interview Questions asked in Infosys, TCS

Python 'getsizeof' Command the Real Purpose

How to Decode TLV Quickly

Hyperledger Fabric: 20 Real Interview Questions

AWS Vs Azure Load Balancers Top Insights

Oozie - Concepts And Architecture

QlikView Server vs Publisher Top Differences Really Useful to Your Project

Telecom Domain Knowledge Useful For a Data Analyst

Payment Cards Complete List