sql - Can I call a user-defined function from a column CHECK constraint? -
I have a user-deficient SQL function that gives 1 or 0 and I want to call it with column check bar . / P>
Yes SQL is not a boolean data type anywhere, so you can create real, false or unknown sources A verdict has to be codeed. In other words, if your function returns 1 or 0 to pass or fail, then you have to code the obligation as check (F () = 1).
Note that both "correct" and "unknown"; Only one wrong result causes the investigation to fail.
The following sample shows how to replace a table already present in the data to add a column with such a check barrier.
Breck
create table (Paki pomegranate is not the primary key); INSERT T VALUES (1); COMMIT; Function I_filled_in (IN @value VARCHAR (100)) Return Tintin if COALESCE (@value, '') & lt; & Gt; '' Then return 1; Return 0; end if; End; Optional table T ADD C VARCHAR (3) DEFAULT 'xxx' check (is_filled_in (c) = 1); - Works fine ... Insert T values (2, 'yyy'); COMMIT; - SQLCODE-209 throws in table 'T' Invalid value for column 'C' ... INSERT T VALUES (3, ''); COMMIT; Choose from * to;
Comments
Post a Comment