@@ -116,7 +116,7 @@ END test_pragma_init;
116116/
117117CREATE OR REPLACE PACKAGE BODY test_pragma_init IS
118118 my_exception EXCEPTION;
119- PRAGMA EXCEPTION_INIT(my_exception, 20001);
119+ PRAGMA EXCEPTION_INIT(my_exception, - 20001);
120120 PROCEDURE test_basic_pragma IS
121121 BEGIN
122122 RAISE INFO 'PRAGMA EXCEPTION_INIT compiled successfully';
@@ -144,7 +144,7 @@ END test_pragma_raise;
144144/
145145CREATE OR REPLACE PACKAGE BODY test_pragma_raise IS
146146 custom_exc EXCEPTION;
147- PRAGMA EXCEPTION_INIT(custom_exc, 20002);
147+ PRAGMA EXCEPTION_INIT(custom_exc, - 20002);
148148 PROCEDURE test_pragma_exception IS
149149 BEGIN
150150 RAISE custom_exc;
@@ -165,7 +165,7 @@ INFO: Caught exception with PRAGMA EXCEPTION_INIT
165165--
166166CREATE OR REPLACE PROCEDURE test_pragma_proc IS
167167 my_exc EXCEPTION;
168- PRAGMA EXCEPTION_INIT(my_exc, 20003);
168+ PRAGMA EXCEPTION_INIT(my_exc, - 20003);
169169BEGIN
170170 RAISE INFO 'PRAGMA EXCEPTION_INIT in procedure works';
171171 RAISE my_exc;
@@ -196,11 +196,11 @@ END test_multi_pragma;
196196/
197197CREATE OR REPLACE PACKAGE BODY test_multi_pragma IS
198198 exc1 EXCEPTION;
199- PRAGMA EXCEPTION_INIT(exc1, 20011);
199+ PRAGMA EXCEPTION_INIT(exc1, - 20011);
200200 exc2 EXCEPTION;
201- PRAGMA EXCEPTION_INIT(exc2, 20012);
201+ PRAGMA EXCEPTION_INIT(exc2, - 20012);
202202 exc3 EXCEPTION;
203- PRAGMA EXCEPTION_INIT(exc3, 20013);
203+ PRAGMA EXCEPTION_INIT(exc3, - 20013);
204204 PROCEDURE test_multiple IS
205205 BEGIN
206206 RAISE INFO 'Multiple PRAGMA EXCEPTION_INIT declarations work';
@@ -218,6 +218,128 @@ SELECT 'Multiple PRAGMA EXCEPTION_INIT test passed' AS result;
218218 Multiple PRAGMA EXCEPTION_INIT test passed
219219(1 row)
220220
221+ --
222+ -- Test 10: PRAGMA EXCEPTION_INIT with positive error codes
223+ -- Oracle documentation: Valid codes are 100 or any negative integer >= -1000000 (except -1403)
224+ -- This test verifies positive error codes: only 100 is accepted, all others are rejected.
225+ --
226+ -- Test 10a: Valid positive error code 100 (should succeed)
227+ CREATE OR REPLACE PACKAGE test_pragma_positive_100 IS
228+ PROCEDURE test_positive;
229+ END test_pragma_positive_100;
230+ /
231+ CREATE OR REPLACE PACKAGE BODY test_pragma_positive_100 IS
232+ exc_100 EXCEPTION;
233+ PRAGMA EXCEPTION_INIT(exc_100, 100); -- Oracle accepts: ANSI NO_DATA_FOUND
234+ PROCEDURE test_positive IS
235+ BEGIN
236+ RAISE INFO 'Error code 100 accepted (ANSI NO_DATA_FOUND)';
237+ END test_positive;
238+ END test_pragma_positive_100;
239+ /
240+ BEGIN
241+ test_pragma_positive_100.test_positive();
242+ END;
243+ /
244+ INFO: Error code 100 accepted (ANSI NO_DATA_FOUND)
245+ DROP PACKAGE test_pragma_positive_100;
246+ -- Test 10b: Invalid positive error code 1 (should fail with PLS-00701)
247+ CREATE OR REPLACE PACKAGE test_pragma_positive_1 IS
248+ exc_1 EXCEPTION;
249+ PRAGMA EXCEPTION_INIT(exc_1, 1); -- Oracle rejects: positive except 100
250+ END test_pragma_positive_1;
251+ /
252+ ERROR: illegal ORACLE error number 1 for PRAGMA EXCEPTION_INIT
253+ LINE 2: PRAGMA EXCEPTION_INIT(exc_1, 1); -- Oracle rejects: posit...
254+ ^
255+ QUERY: exc_1 EXCEPTION;
256+ PRAGMA EXCEPTION_INIT(exc_1, 1); -- Oracle rejects: positive except 100
257+ END test_pragma_positive_1
258+ -- Test 10c: Invalid positive error code 1000000 (should fail with PLS-00701)
259+ CREATE OR REPLACE PACKAGE test_pragma_positive_1000000 IS
260+ exc_1000000 EXCEPTION;
261+ PRAGMA EXCEPTION_INIT(exc_1000000, 1000000); -- Oracle rejects: positive except 100
262+ END test_pragma_positive_1000000;
263+ /
264+ ERROR: illegal ORACLE error number 1000000 for PRAGMA EXCEPTION_INIT
265+ LINE 2: PRAGMA EXCEPTION_INIT(exc_1000000, 1000000); -- Oracle re...
266+ ^
267+ QUERY: exc_1000000 EXCEPTION;
268+ PRAGMA EXCEPTION_INIT(exc_1000000, 1000000); -- Oracle rejects: positive except 100
269+ END test_pragma_positive_1000000
270+ SELECT 'PRAGMA EXCEPTION_INIT positive error code tests completed' AS result;
271+ result
272+ -----------------------------------------------------------
273+ PRAGMA EXCEPTION_INIT positive error code tests completed
274+ (1 row)
275+
276+ --
277+ -- Test 11: PRAGMA EXCEPTION_INIT with negative error codes and boundary
278+ -- Oracle documentation: Valid codes are 100 or any negative integer >= -1000000 (except -1403)
279+ -- This test verifies the -1000000 boundary and specifically rejected negative codes.
280+ --
281+ -- Test 11a: Valid error code -1000000 (should succeed - at boundary)
282+ CREATE OR REPLACE PACKAGE test_pragma_minus_1000000 IS
283+ PROCEDURE test_boundary;
284+ END test_pragma_minus_1000000;
285+ /
286+ CREATE OR REPLACE PACKAGE BODY test_pragma_minus_1000000 IS
287+ exc_boundary EXCEPTION;
288+ PRAGMA EXCEPTION_INIT(exc_boundary, -1000000); -- At the boundary
289+ PROCEDURE test_boundary IS
290+ BEGIN
291+ RAISE INFO 'Error code -1000000 accepted (at boundary)';
292+ END test_boundary;
293+ END test_pragma_minus_1000000;
294+ /
295+ BEGIN
296+ test_pragma_minus_1000000.test_boundary();
297+ END;
298+ /
299+ INFO: Error code -1000000 accepted (at boundary)
300+ DROP PACKAGE test_pragma_minus_1000000;
301+ -- Test 11b: Invalid error code -1000001 (should fail with PLS-00701 - beyond boundary)
302+ CREATE OR REPLACE PACKAGE test_pragma_minus_1000001 IS
303+ exc_beyond EXCEPTION;
304+ PRAGMA EXCEPTION_INIT(exc_beyond, -1000001); -- Beyond boundary
305+ END test_pragma_minus_1000001;
306+ /
307+ ERROR: illegal ORACLE error number -1000001 for PRAGMA EXCEPTION_INIT
308+ LINE 2: PRAGMA EXCEPTION_INIT(exc_beyond, -1000001); -- Beyond bo...
309+ ^
310+ QUERY: exc_beyond EXCEPTION;
311+ PRAGMA EXCEPTION_INIT(exc_beyond, -1000001); -- Beyond boundary
312+ END test_pragma_minus_1000001
313+ -- Test 11c: Invalid error code -1403 (should fail with PLS-00701)
314+ CREATE OR REPLACE PACKAGE test_pragma_minus_1403 IS
315+ exc_1403 EXCEPTION;
316+ PRAGMA EXCEPTION_INIT(exc_1403, -1403); -- Oracle-specific NO_DATA_FOUND, must use 100
317+ END test_pragma_minus_1403;
318+ /
319+ ERROR: illegal ORACLE error number -1403 for PRAGMA EXCEPTION_INIT
320+ LINE 2: PRAGMA EXCEPTION_INIT(exc_1403, -1403); -- Oracle-specifi...
321+ ^
322+ QUERY: exc_1403 EXCEPTION;
323+ PRAGMA EXCEPTION_INIT(exc_1403, -1403); -- Oracle-specific NO_DATA_FOUND, must use 100
324+ END test_pragma_minus_1403
325+ -- Test 11d: Invalid error code 0 (should fail with PLS-00701)
326+ CREATE OR REPLACE PACKAGE test_pragma_zero IS
327+ exc_zero EXCEPTION;
328+ PRAGMA EXCEPTION_INIT(exc_zero, 0); -- Zero is rejected by Oracle
329+ END test_pragma_zero;
330+ /
331+ ERROR: illegal ORACLE error number 0 for PRAGMA EXCEPTION_INIT
332+ LINE 2: PRAGMA EXCEPTION_INIT(exc_zero, 0); -- Zero is rejected b...
333+ ^
334+ QUERY: exc_zero EXCEPTION;
335+ PRAGMA EXCEPTION_INIT(exc_zero, 0); -- Zero is rejected by Oracle
336+ END test_pragma_zero
337+ SELECT 'PRAGMA EXCEPTION_INIT negative error code tests completed' AS result;
338+ result
339+ -----------------------------------------------------------
340+ PRAGMA EXCEPTION_INIT negative error code tests completed
341+ (1 row)
342+
221343-- Cleanup
222344DROP PACKAGE test_pragma_init;
223345DROP PACKAGE test_pragma_raise;
0 commit comments