Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Maybe the name <code>RAISE_APPLICATION_ERROR</code> is misleading for you. It will not pop up something onto your GUI. That you program yourself depending on what client you are using. Put you can use <code>RAISE_APPLICATION_ERROR</code> to create your own SQL errors on which you act upon.</p> <p>Example</p> <pre><code>-- a example table create table mytest (col_a number, col_b char(20)); -- a example trigger CREATE OR REPLACE TRIGGER mytest_before BEFORE UPDATE ON mytest FOR EACH ROW DECLARE BEGIN if :new.col_a &lt; 0 then RAISE_APPLICATION_ERROR(-20299, 'negative value not allowed for column A'); end if; END; insert into mytest values (1,'hallo'); set serveroutput on DECLARE negative_value EXCEPTION; -- declare exception PRAGMA EXCEPTION_INIT (negative_value, -20299); -- assign error code to exception BEGIN update mytest set col_a = -1 where col_b = 'hallo'; EXCEPTION WHEN negative_value THEN -- handle exception -- do whatever you need to do to bring the error to the user DBMS_OUTPUT.PUT_LINE(TO_CHAR(SQLERRM(-20299))); END; / </code></pre> <p>The above will bring you the output in SQL*Plus or SQL Developer of that sort. </p> <pre><code>table MYTEST created. TRIGGER mytest_before compiled 1 rows inserted. anonymous block completed ORA-20299: negative value not allowed for column A ORA-06512: at "DEMO.MYTEST_BEFORE", line 4 ORA-04088: error during execution of trigger 'DEMO.MYTEST_BEFORE </code></pre> <p>Instead of DBMS_OUTPUT.PUT_LINE you can do whatever you need to do to show the user whatever you want him to show.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload