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
84 Views Asked by Mike Dark At
2
There are 2 best solutions below
0
On
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
This is the simplest way to raise a bespoke PL/SQL exception:
Numbers for user-defined exceptions must be in the range -20999 to -20000.
Incidentally, you describe
checkas 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: