-3

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?

Mike Dark
  • 1
  • 4

2 Answers2

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'));
APC
  • 144,005
  • 19
  • 170
  • 281
0

Something like the following?

ALTER TABLE [TableName]
ADD CONSTRAINT [CheckName] CHECK (Check IN ('Ok', 'Not Ok'));

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

Dan Armour
  • 11
  • 1
  • 2