PL/SQL Programms: WRITE A Program To Display The Multiplication Tables
PL/SQL Programms: WRITE A Program To Display The Multiplication Tables
PL/SQL Programms: WRITE A Program To Display The Multiplication Tables
DECLARE
E_NO EMP.EMPNO%TYPE;
D_NO E_NO%TYPE;
BEGIN
SELECT EMPNO,DEPTNO INTO E_NO,D_NO FROM EMP where
empno=7369;
DBMS_OUTPUT.PUT_LINE(E_NO||' AND HIS NAME ' ||D_NO);
END;
/
DECLARE
TYPE E_REC_T IS RECORD
(EMPNO EMP.EMPNO%TYPE,
ENAME EMP.ENAME%TYPE,
JOB EMP.JOB%TYPE,
SAL EMP.SAL%TYPE);
EMP_REC E_REC_T;
BEGIN
SELECT EMPNO,ENAME,JOB,SAL INTO EMP_REC FROM EMP
WHERE EMPNO=7369;
DBMS_OUTPUT.PUT_LINE( EMP_REC.EMPNO ||' ' ||
EMP_REC.ENAME ||' ' ||EMP_REC.JOB ||' ' ||
EMP_REC.SAL );
END;
/
DECLARE
V_DATE VARCHAR2(10);
BEGIN
V_DATE := SYSDATE;
DBMS_OUTPUT.PUT_LINE(V_DATE);
END;
/
DECLARE
V_NO NUMBER(2) :=10;
V_NAME VARCHAR2(10) DEFAULT 'SAIBABA';
V_SAL NUMBER(5) NOT NULL := 5000;
V_JOB CONSTANT VARCHAR2(100) := 'MANAGING DIRECTOR OF ORACLE';
BEGIN
DBMS_OUTPUT.PUT_LINE(V_NO);
DBMS_OUTPUT.PUT_LINE(V_NAME);
DBMS_OUTPUT.PUT_LINE(V_SAL);
DBMS_OUTPUT.PUT_LINE(V_JOB);
END;
DECLARE
V_MESSAGE VARCHAR2(100) := 'WELCOME TO PL/SQL PROGRAMMING';
BEGIN
DBMS_OUTPUT.PUT_LINE(V_MESSAGE);
V_MESSAGE := 'WILSHIRE SOFTWARE TECHNOLOGIES';
DBMS_OUTPUT.PUT_LINE(V_MESSAGE);
DBMS_OUTPUT.PUT_LINE('HAI ');
END;
/
DECLARE
C NUMBER := &C;
F NUMBER;
BEGIN
F := C*1.8+32;
DBMS_OUTPUT.PUT_LINE('FARENHEIT=' || F);
END;
/
DECLARE
STR VARCHAR2(100) := '&STR';
I NUMBER;
BEGIN
I := INSTR(STR,'.');
I := LENGTH(STR);
END;
6)WAP TO ACCEPT THE TWO STRINGS AND CONCAT THE TWO STRINGS
DECLARE
BEGIN
DBMS_OUTPUT.PUT_LINE(V);
END;
7) WAP TO ACCEPT THE MGR AND FIND HOW MANY EMPS ARE WORKING UNDER THAT
MGR
DECLARE
N NUMBER :=0;
BEGIN
SELECT COUNT(*)
INTO N
FROM EMP
WHERE MGR=V_MGR;
END;
8) WAP TO ACCEPT 2 NO.S FIND THE REMAINDER WHEN THE FIRST NUMBER IS
DIVIDED BY THE SECOND NUMBER
DON'T USE THE MOD FUNCTION
DECLARE
A NUMBER := &A;
B NUMBER := &B;
C NUMBER ;
M NUMBER ;
BEGIN
C := TRUNC (A/B);
M := A-C*B;
END;
DECLARE
A NUMBER := &A;
B NUMBER := &B;
C NUMBER;
BEGIN
C := MOD(A,B);
END;
/
10) WAP TO ACCEPT THE TIME IN HH,MIN FORMAT AND FIND THE TOTAL SECONDS
DECLARE
H NUMBER := &HOUR;
M NUMBER := &MINUTE;
S NUMBER(10);
BEGIN
S := (H*60*60)+(M*60);
END;
11) GO TO STATEMENT
BEGIN
GOTO SECOND_OUTPUT;
DBMS_OUTPUT.PUT_LINE(' THIS LINE WILL NEVER EXECUTE');
<<SECOND_OUTPUT>>
END;
12) GO TO STATEMENT
BEGIN
GOTO SECOND_OUTPUT;
<<SECOND_OUTPUT>>
END;
/
13) NULL STATMENT
BEGIN
NULL;
END;
DECLARE
BEGIN
IF V_NAME='BOND' THEN
DBMS_OUTPUT.PUT_LINE('007');
ELSE
NULL;
END IF;
END;
/
15) LOOPS
DECLARE
BEGIN
LOOP
V_C := V_C+1;
--DBMS_OUTPUT.PUT_LINE(V_NAME);
--DBMS_OUTPUT.PUT_LINE(V_NAME);
END LOOP;
DBMS_OUTPUT.PUT_LINE(V_NAME);
END;
DECLARE
v_N NUMBER(3):= 1;
v_V VARCHAR2(100) ;
BEGIN
v_N :=v_N+1;
DBMS_OUTPUT.PUT_LINE(v_V);
END LOOP;
END;
DBMS_OUTPUT.PUT_LINE('HELLO');
END LOOP;
END;
/
18) FOR LOOP EXAMPLE
DECLARE
BEGIN
DBMS_OUTPUT.PUT_LINE('HELLO');
END LOOP;
END;
/
19) FOR LOOP EXAMPLE WITH BOND VALUE CHANGING
DECLARE
BEGIN
DBMS_OUTPUT.PUT_LINE('HELLO');
V_L :=20;
V_H :=40;
END LOOP;
END;
DBMS_OUTPUT.PUT_LINE(I || 'HELLO');
END LOOP;
END;
21) %TYPE
SYNTAX:
IDENTIFIER TABLE.COLUMN_NAME%TYPE;
DECLARE
V_SAL EMP.SAL%TYPE;
V_ENAME EMP.ENAME%TYPE;
BEGIN
SELECT SAL,ENAME
INTO V_SAL,V_ENAME
FROM EMP
WHERE EMPNO=7369;
DBMS_OUTPUT.PUT_LINE(V_ENAME || ' AND HIS SALARY IS ' || V_SAL);
END;
/
22) WITH OUT USING %TYPE
DECLARE
V_SAL NUMBER(2);
BEGIN
DBMS_OUTPUT.PUT_LINE(V_SAL);
END;
/
23) WITH OUT USING %TYPE
DECLARE
V_SAL VARCHAR2(10);
BEGIN
FROM EMP
WHERE EMPNO=7369;
DBMS_OUTPUT.PUT_LINE(V_SAL);
END;
DECLARE
V_ENAME EMP.ENAME%TYPE;
V_JOB V_ENAME%TYPE;
BEGIN
SELECT ENAME,JOB
INTO V_ENAME,V_JOB
FROM EMP
WHERE EMPNO=7369;
DBMS_OUTPUT.PUT_LINE(V_ENAME);
END;
DECLARE
IDENTFIER REFERENCE%ROWTYPE;
WHERE
FOR EXAMPLE:
RECORD_NAME.FIELD_NAME;
FOR EXAMPLE, YOU REFERENCE THE ENAME FIELD IN THE EMP_RECORD RECORD AS
FOLLOWS
EMP_RECORD.ENAME;
EMP_RECORD.ENAME:='BOND';
DEPT_RECORD DEPT%ROWTYPE;
EMP_RECORD EMP%ROWTYPE;
THE NUMBER AND DATA TYPES OF THE UNDERLYING COLUMNS NEED NOT BE KNOWN.
THE NUMBER AND DATA TYPES OF THE UNDERLYING DATABASE COLUMNS MAY CHANGE
AT RUNTIME.
DECLARE
DEPT_RECORD DEPT%ROWTYPE;
BEGIN
SELECT * INTO DEPT_RECORD
FROM DEPT
WHERE DEPTNO=10;
DBMS_OUTPUT.PUT_LINE(DEPT_RECORD.DNAME);
DBMS_OUTPUT.PUT_LINE(DEPT_RECORD.LOC);
DBMS_OUTPUT.PUT_LINE(DEPT_RECORD.DEPTNO);
END;
/
29) %ROWTYPE GETTING THE VALUES FROM OTHER TABLE CONCEPT
DECLARE
EMP_RECORD EMP%ROWTYPE;
BEGIN
SELECT *
INTO EMP_RECORD
FROM EMP1
WHERE EMPNO=7369;
DBMS_OUTPUT.PUT_LINE(EMP_RECORD.ENAME);
END;
/
30) CREATING A PL/SQL RECORD
SYNTAX:
(field_declaration ...........);
identifier type_name;
WHERE field_declration is
where
DECLARE
(ENAME VARCHAR2(10),
JOB ENAME%TYPE,
SAL NUMBER(7,2),
EMPNO SAL%TYPE);
EMP_RECORD EMP_RECORD_TYPE;
BEGIN
SELECT ENAME,JOB,SAL,EMPNO
INTO EMP_RECORD
FROM EMP
WHERE EMPNO=7369;
DBMS_OUTPUT.PUT_LINE(EMP_RECORD.ENAME);
DBMS_OUTPUT.PUT_LINE(EMP_RECORD.EMPNO);
END;
DECLARE
(EMPNO EMP.EMPNO%TYPE,
ENAME EMP.ENAME%TYPE);
EMP_RECORD EMP_RECORD_TYPE;
BEGIN
SELECT EMPNO,ENAME
INTO EMP_RECORD
FROM EMP
WHERE EMPNO=7369;
DBMS_OUTPUT.PUT_LINE(emp_record.ENAME);
END;
/
33) PL/SQL RECORD WITH %TYPE
DECLARE
( SAL EMP.SAL%TYPE,
EMPNO SAL%TYPE);
EMP_RECORD EMP_RECORD_TYPE;
BEGIN
SELECT SAL,EMPNO
INTO EMP_RECORD
FROM EMP
WHERE EMPNO=7369;
DBMS_OUTPUT.PUT_LINE(EMP_RECORD.SAL);
DBMS_OUTPUT.PUT_LINE(EMP_RECORD.EMPNO);
END;
DECLARE
(E1 EMP%ROWTYPE);
EMP_RECORD EMP_RECORD_TYPE;
BEGIN
DBMS_OUTPUT.PUT_LINE(EMP_RECORD.ENAME);
DBMS_OUTPUT.PUT_LINE('GOOD MORNING');
END;
NOTE:-
3) THEY ARE MODELED AS (BUT NOT THE SAME AS) DATABASE TABLES
36) - SYNTAX:
INDEX BY BINARY_INTEGER;
IDENTIFIER TYPE_NAME;
1 JONES
2 SMITH
3 MADURO
BINARY_INTEGER SCALAR
NOTE:-
DECLARE
MY_EMP_TABLE EMP_TABLE_TYPE;
V_COUNT NUMBER(2) :=4;
BEGIN
SELECT * INTO
MY_EMP_TABLE(I)
FROM EMPLOYEES
WHERE EMPNO=I;
dbms_output.put_line(my_emp_table(i).ename);
END LOOP;
--DBMS_OUTPUT.PUT_LINE(MY_EMP_TABLE(I).ENAME);
--DBMS_OUTPUT.PUT_LINE(MY_EMP_TABLE.COUNT);
--DBMS_OUTPUT.PUT_LINE(MY_EMP_TABLE.NEXT(1);
--DBMS_OUTPUT.PUT_LINE(MY_EMP_TABLE.PRIOR(3);
--END LOOP;
IF MY_EMP_TABLE.EXISTS(1) THEN
DBMS_OUTPUT.PUT_LINE('FIRST RECORD IS EXISTING');
END IF;
END;
DECLARE
INDEX BY BINARY_INTEGER;
ENAME_TABLE ENAME_TABLE_TYPE;
BEGIN
END LOOP;
IF ENAME_TABLE.EXISTS(1) THEN
DBMS_OUTPUT.PUT_LINE('IT EXISTS');
END IF;
END;
DECLARE
EMPLOYEES.ENAME%TYPE
INDEX BY BINARY_INTEGER;
ENAME_TABLE ENAME_TABLE_TYPE;
BEGIN
END LOOP;
IF ENAME_TABLE.EXISTS(1) THEN
DBMS_OUTPUT.PUT_LINE('IT EXISTS');
END IF;
END;
/
40) INDEX BY TABLE METHODS
THE FOLLOWING METHODS MAKE INDEX BY TABLES EASIER TO USE
EXISTS
COUNT
NEXT
TRIM
FIRST AND LAST
DELETE
PRIOR
SYNTAX:-
TABLE_NAME.METHODS_NAME(PARAMETERS)
FIRST LAST:- RETURNS THE FIRST AND LAST(SMALLEST AND LARGEST) INDEX
NUMBERS
IN A PL/SQL TABLE .
RETURNS NULL IF THE PL/SQL TABLE IS EMPTY
TRIM:- TRIM REMOVES ONE ELEMENT FROM THE END OF A PL/SAL TABLE
41) CURSORS
CLASSIFICATION OF CURSORS
1) IMPLICIT CURSORS
2) EXPLICIT CURSORS
NOTE:- THE ORACLE SERVER USES WORK AREAS, CALLED PRIVATE SQL AREAS,
TO EXECUTE SQL STATEMENTS AND TO STORE PROCESSING INFORMATION
YOU CAN USE PL/SQL CURSORS TO NAME A PRIVATE SQL AREA AND
ACCESS ITS STORED INFORMATION
EXPLICIT CURSORS:- FOR QUERIES THAT RETURN MORE THAN ONE ROW, EXPLICIT
CURSORS
ARE DECLARED AND NAMED BY THE PROGRAMMER AND MANIPULATED
THROUGH SPECIFIC STATEMENTS IN THE BLOCK'S EXECUTABLE
ACTIONS
ATTRIBUTES:-
%ISOPEN BOOLEAN
%NOTFOUND BOOLEAN
%FOUND BOOLEAN
%ROWCOUNT NUMBER
THE OPEN STATEMENT EXECUTES THE QUERY ASSOCIATED WITH THE CURSOR,
IDENTIFIES
THE RESULT SET(ACTIVE SET) AND POSITIONS THE CURSOR BEFORE THE FIRST ROW
2) FETCH A ROW:-
THE FETCH STATEMENT RETRIEVES THE CURRENT ROW AND ADVANCES THE CURSOR TO
THE
NEXT ROW UNTILE EITHER THERE ARE NO MORE ROWS OR UNTILL THE SPECIFIED
CONDITION IS MET
NOTE:- IF THE QUERY RETURNS NO ROWS WHEN THE CURSOR IS OPENED, PL/SQL
DOES NOT
RAISE AN EXCEPTION(ERROR).
SYNTAX:
LOOP
FETCH STATEMENT;
EXIT CONDITION;
END LOOP;
DECLARE
CURSOR EMP_CURSOR IS SELECT EMPNO,ENAME FROM EMP;
V_EMPNO EMP.EMPNO%TYPE;
V_ENAME EMP.ENAME%TYPE;
BEGIN
OPEN EMP_CURSOR;
LOOP
FETCH EMP_CURSOR INTO V_EMPNO,V_ENAME;
EXIT WHEN EMP_CURSOR%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(V_EMPNO||' NAME IS ' || V_ENAME);
END LOOP;
CLOSE EMP_CURSOR;
END;
/
43) -EXAMPLE ON %ROWCOUNT ATTRIBUTE
DECLARE
CURSOR EMP_CURSOR IS SELECT EMPNO,ENAME FROM EMP;
V_EMPNO EMP.EMPNO%TYPE;
V_ENAME EMP.ENAME%TYPE;
BEGIN
OPEN EMP_CURSOR;
LOOP
FETCH EMP_CURSOR INTO V_EMPNO,V_ENAME;
--DBMS_OUTPUT.PUT_LINE(V_ENAME);
EXIT WHEN EMP_CURSOR%ROWCOUNT>5;
dbms_output.put_line(v_ename);
END LOOP;
CLOSE EMP_CURSOR;
END;
DECLARE
CURSOR EMP_CURSOR IS SELECT ENAME FROM EMP;
V_ENAME EMP.ENAME%TYPE;
BEGIN
OPEN EMP_CURSOR;
LOOP
FETCH EMP_CURSOR INTO V_ENAME;
DBMS_OUTPUT.PUT_LINE(V_ENAME);
EXIT WHEN EMP_CURSOR%FOUND;
END LOOP;
CLOSE EMP_CURSOR;
END;
/
45) %IS OPEN ATTRIBUTE
DECLARE
CURSOR EMP_CURSOR IS SELECT EMPNO FROM EMP;
V_EMPNO EMP.EMPNO%TYPE;
BEGIN
LOOP
DBMS_OUTPUT.PUT_LINE(V_EMPNO);
END LOOP;
END;
/
46) CURSORS AND RECORDS
DECLARE
CURSOR EMP_CURSOR IS SELECT * FROM EMP;
EMP_RECORD EMP_CURSOR%ROWTYPE;
BEGIN
OPEN EMP_CURSOR;
LOOP
END LOOP;
CLOSE EMP_CURSOR;
END;
/
SYNTAX:-
NOTE:-
DECLARE
CURSOR EMP_CURSOR IS SELECT ENAME,DEPTNO FROM EMP;
BEGIN
FOR EMP_RECORD IN EMP_CURSOR LOOP
IF EMP_RECORD.DEPTNO=10 THEN
DBMS_OUTPUT.PUT_LINE(EMP_RECORD.ENAME);
END IF;
END LOOP;
END;
/
BEGIN
IF EMP_RECORD.DEPTNO=10 THEN
DBMS_OUTPUT.PUT_LINE(EMP_RECORD.ENAME);
END IF;
END LOOP;
END;
/
50) ADVANCED EXPLICIT CURSOR CONCEPTS
SYNTAX:-
PASS PARAMETER VALUES TO A CURSOR WHEN THE CURSOR IS OPENED AND THE
QUERY
IS EXECUTED
OPEN AN EXPLICIT CURSOR SEVERAL TIMES WITH A DIFFERENT ACTIVE SET EACH
TIME
NOTEPOINT:-
DECLARE
CURSOR EMP_CURSOR IS
SELECT * FROM EMP
WHERE DEPTNO=10;
EMP_RECORD EMP_CURSOR%ROWTYPE;
BEGIN
OPEN EMP_CURSOR;
LOOP
FETCH EMP_CURSOR INTO EMP_RECORD;
DBMS_OUTPUT.PUT_LINE(EMP_RECORD.ENAME);
EXIT WHEN EMP_CURSOR%NOTFOUND;
END LOOP;
CLOSE EMP_CURSOR;
END;
/
DECLARE
EMP_RECORD EMP_CURSOR%ROWTYPE;
BEGIN
OPEN EMP_CURSOR(10);
LOOP
FETCH EMP_CURSOR INTO EMP_RECORD;
DBMS_OUTPUT.PUT_LINE('THESE EMPLOYEES ARE WORKING IN DEPT10');
DBMS_OUTPUT.PUT_LINE(EMP_RECORD.ENAME);
DBMS_OUTPUT.PUT_LINE('----------------------------');
EXIT WHEN EMP_CURSOR%NOTFOUND;
END LOOP;
CLOSE EMP_CURSOR;
OPEN EMP_CURSOR(20);
LOOP
FETCH EMP_CURSOR INTO EMP_RECORD;
DBMS_OUTPUT.PUT_LINE('THESE EMPLOYEES ARE WORKING IN DEPT20');
DBMS_OUTPUT.PUT_LINE(EMP_RECORD.ENAME);
EXIT WHEN EMP_CURSOR%NOTFOUND;
END LOOP;
CLOSE EMP_CURSOR;
END;
/
53) THE FOR UPDATE CLAUSE
SYNTAX:-
SELECT ........
FROM
FOR UPDATE [OF COLUMN_REFERENCE] [NOWAIT];
COLUMN_REFERENCE:-
1) IS A COLUMN IN THE TABLE AGAINST THE QUERY IS PROCESSED
2) A LIST OF COLUMNS MAY ALSO BE USED
NOWAIT:- RETURNS AN ORACLE ERROR IF THE ROWS ARE LOCKED BY ANOTHER
SESSION
NOTE:- FOR UPDATE CLAUSE IS THE LAST CLAUSE IN A SELECT STATEMENT, EVEN
AFTER THE ORDER BY, IF ONE EXISTS.
FOR UPDATE OF COL_NAMES(S) LOCKS ROWS ONLY IN TABLES THAT CONTAIN THE
COL_NAMES(S)
NOWAIT:- IT TELLS ORACLE NOT TO WAIT IF REQUESTED ROWS HAVE BEEN LOCKED
BY
ANOTHER USER
IF YOU OMIT THE NOWAIT KEYWORD, ORACLE WAITS UNTIL THE ROWS ARE
AVAILABLE
NOTE:- IF THE ORACLE SERVER CANNOT ACQUIRE THE LOCKS ON THE ROWS IT
NEEDS IN A
SELECT FOR UPDATE, IT WAITS INDEFINITELY.
54) THE WHERE CURRENT OF CLAUSE
SYNTAX :-
INCLUDE THE FOR UPDATE CLAUSE IN THE CURSOR QUERY TO LOCK THE ROWS FIRST
USE THE WHERE CURRENT OF CLAUSE TO REFERENCE THE CURRENT ROW FROM AN
EXPLICIT CURSOR
CURSOR:- IS THE NAME OF A DECLARE CURSOR (THE CURSOR MUST HAVE BEEN
DECLARED
WITH THE FOR UPDATE CLAUSE)
55) EXAMPLE
DECLARE
CURSOR SAL_CURSOR IS
SELECT SAL FROM EMP
WHERE DEPTNO=10
FOR UPDATE OF SAL NOWAIT;
BEGIN
FOR EMP_RECORD IN SAL_CURSOR LOOP
END LOOP;
END;
HANDLING EXCEPTIONS
A BLOCK ALWAYS TERMINATES WHEN PL/SQL RAISES AN EXCEPTION , BUT YOU CAN
SPECIFY AN EXCEPTION HANDLER TO PERFORM FINAL ACTIONS
HOW IT IS RAISED?
EXCEPTION TYPES
TRAPPING EXCEPTIONS
SYNTAX:
EXCEPTION
NOTE:- 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 CAN ALSO TRAP THESE EXCEPTION
NO_DATA_FOUND
TOO_MANY_ROWS
INVALID_CURSOR
ZERO_DIVIDE
DUP_VAL_ON_INDEX
DECLARE
V_NAME VARCHAR2(25);
BEGIN
SELECT ENAME
INTO V_NAME
FROM EMP
WHERE EMPNO=2;
END;
/
57) NO_DATA_FOUND EXCEPTION HANDLING
DECLARE
V_NAME VARCHAR2(20);
V_NO NUMBER(10);
BEGIN
SELECT ENAME
INTO V_NAME
FROM EMP
WHERE EMPNO=2;
EXCEPTION
v_no := 10000;
DBMS_OUTPUT.PUT_LINE(V_NO);
END;
58) TOO_MANY_ROWS
DECLARE
V_ENAME VARCHAR2(10);
BEGIN
EXCEPTION
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE('A VARIABLE CAN HOLD ONLY SINGLE VALUE AT A TIME');
END;
/
59) ZERO_DIVIDE
DECLARE
V_RES NUMBER(5);
BEGIN
V_RES := (V_NO/V_NO1);
EXCEPTION
DBMS_OUTPUT.PUT_LINE('UNDEFINED VALUE');
END;
DECLARE
EMP_RECORD EMP_CURSOR%ROWTYPE;
BEGIN
--LOOP
CLOSE EMP_CURSOR;
EXCEPTION
END;
BEGIN
INSERT INTO A
VALUES
(1);
EXCEPTION
END;
DECLARE
V_SAL NUMBER(2);
BEGIN
FROM EMP
WHERE EMPNO=7369;
DBMS_OUTPUT.PUT_LINE(V_SAL);
END;
63) TRAP FOR ORACLE SERVER ERROR NUMBER -6502, AN VALUE TOO LARGE
DECLARE
V_SAL NUMBER(2);
E_HIGH EXCEPTION;
PRAGMA EXCEPTION_INIT(E_HIGH,-6502);
BEGIN
SELECT SAL
INTO V_SAL
FROM EMP
WHERE EMPNO=7369;
EXCEPTION
END;
/
64) TRAP FOR ORACLE SERVER ERROR NUMBER -2292 , AN INTEGRITY CONSTRAINT
-- VIOLATION
0 NO EXCEPTION ENCOUNTERED
1 USER-DEFINED EXCEPTION
DECLARE
V_ERROR_NUMBER NUMBER;
V_ERROR_MESSAGE VARCHAR2(255);
V_SAL NUMBER(9);
v_high exception;
pragma exception_init(v_high,-6502);
BEGIN
v_error_number := sqlcode;
v_error_message := sqlerrm;
dbms_output.put_line(v_error_number);
EXCEPTION
V_ERROR_NUMBER := SQLCODE;
V_ERROR_MESSAGE := SQLERRM;
DBMS_OUTPUT.PUT_LINE(V_ERROR_NUMBER);
DBMS_OUTPUT.PUT_LINE(V_ERROR_MESSAGE);
END;