I want to write an exception for the Check
column. If 'Ok' or 'Not Ok' have not been entered i want to raise an application error. How would i go about writing this?
Unsure how to phrase plsql exception
49 views Asked by Mike Dark At
2
There are 2 answers
0

This is the simplest way to raise a bespoke PL/SQL exception:
begin
if p_check not in ('Ok', 'Not Ok') then
raise_application_error(-20999,
'Invalid value for CHECK '|| p_check);
end if;
....
Numbers for user-defined exceptions must be in the range -20999 to -20000.
Incidentally, you describe check
as a "column". PL/SQL exceptions are for variables and parameters. If what you mean really is validating a table column you need a check constraint:
alter table whatever
add constraint col23_ck
check ( col23 in ('Ok', 'Not Ok'));
Something like the following?
This will raise a DB error if any other value is input into the column,
More information here: https://www.w3schools.com/sql/sql_check.asp