Using a CHECK constraint to check for minimum age

Is it possible to use a check constraint in a table to check whether a person meets a minimum age? For example, if a person is registering as a member, I want to make sure the person is at least 18 years old (contract age), so that a minor doesn't try to register as an adult.
From what I understand, I can't use SYSDATE in a check statement. Is there another way? What about using CURRENT_DATE and FLOOR to form a statement for this check?
Here's the DDL for the table (table is not fully decomposed to keep it simple; "dob" represents "Date of Birth" and "zipcode" is a FK to this table):
CREATE TABLE member     (
member_id     VARCHAR2(10)     NOT NULL,
fname          VARCHAR2(30)     NOT NULL,
lname          VARCHAR2(30)     NOT NULL,
address1     VARCHAR2(50),
address2     VARCHAR2(25),
zipcode     NUMBER(5)     NOT NULL,
phone          VARCHAR2(15)     NOT NULL,
dob          DATE          NOT NULL,
gender     CHAR(1)          NOT NULL,
CONSTRAINT ck_gender     gender IN ('M','F'),
CONSTRAINT pk_member     PRIMARY KEY (member_id),
CONSTRAINT fk_member_zipcode (zipcode) REFERENCES zipcode)
Thanks for your help.

Like SYSDATE, CURRENT_DATE is a non-deterministic function and so cannot be used in this context.
From the manual:
Restrictions on Check Constraints
You cannot specify a check constraint for a view. However, you can define the view using the WITH CHECK OPTION clause, which is equivalent to specifying a check constraint for the view.
The condition of a check constraint can refer to any column in the table, but it cannot refer to columns of other tables.
Conditions of check constraints cannot contain the following constructs:
Subqueries and scalar subquery expressions
Calls to the functions that are not deterministic (CURRENT_DATE, CURRENT_TIMESTAMP, DBTIMEZONE, LOCALTIMESTAMP, SESSIONTIMEZONE, SYSDATE, SYSTIMESTAMP, UID, USER, and USERENV)
Calls to user-defined functions
Dereferencing of REF columns (for example, using the DEREF function)
Nested table columns or attributes
The pseudocolumns CURRVAL, NEXTVAL, LEVEL, or ROWNUM
Date constants that are not fully specified
To achieve this sort of checking you will need to use a trigger

Similar Messages

  • How to use external functions in check constraints

    I created my own function:
    create or replace
    function if_num_get_num (inval in varchar2)
    return number
    is
    dummy number;
    Begin
    dummy := to_number(inval);
    return dummy;
    exception
    when others then return null;
    end;Can I use it in table check constraint?
    When I use standard function INSTR everything is OK.
    ALTER TABLE A_S
    ADD CONSTRAINT A_S_CHK1 CHECK
      (INSTR(NAZWA_ZA, ':') > 0)
    ENABLE;but when I try to create it with my function:
    ALTER TABLE A_S
    ADD CONSTRAINT A_S_CHK1 CHECK
      (IF_NUM_GET_NUM(INSTR(NAZWA_ZA, ':')) > 0)
    ENABLE;I get a message "Invalid column IF_NUM_GET_NUM"

    Read the restrictions.
    >
    Restrictions on CHECK Constraints
    A CHECK constraint requires that a condition be true or unknown for every row of the table. If a statement causes the condition to evaluate to false, then the statement is rolled back. The condition of a CHECK constraint has these limitations:
    * The condition must be a boolean expression that can be evaluated using the values in the row being inserted or updated.
    * The condition cannot contain subqueries or sequences.
    * The condition cannot include the SYSDATE, UID, USER, or USERENV SQL functions.
    * The condition cannot contain the pseudocolumns LEVEL or ROWNUM.
    * The condition cannot contain the PRIOR operator.
    ** The condition cannot contain a user-defined function.*
    >
    http://download.oracle.com/docs/cd/E11882_01/appdev.112/e17125/adfns_constraints.htm#ADFNS282

  • Check constraint generation in physical model in 3.1.1.

    My question: Is it possible to set Use Domain Constraints ticked as default (or another way to get them in DDL) if the Domain with Check constraint is set for the column. I assume it's logical as if I bind a column to the domain then use the domain constraint as default policy. It's not a big deal if you have a few but in my case I do re-modelling just for physical model level and I have tens column in the tables based on a domain. So, I have first to set the domain as a column type and then in another screen tick Use Domain Constraints
    Thank you

    Hi,
    Is it possible to set Use Domain Constraints ticked as default (or another way to get them in DDL) if the Domain with Check constraint is set for the column.No it's not possible I logged bug for that.
    So, I have first to set the domain as a column type How do you set domain as data type? Do you have more than one columns using the same domain? In such cases you can use domain dialog (in the browser) and "Used in" page in order to assign domain to several columns/attributes at once.
    You can use the script below to set use domain constraints on columns that use domain as data type
    Philip
    var model;
    tables = model.getTableSet().toArray();
    for (var t = 0; t<tables.length;t++){
    table = tables[t];
    columns = table.getElements();
    for (var i = 0; i < columns.length; i++) {
         column = columns;
         if(column.getUse() == 0 && column.getDomain()!=null){
              if(!column.getUseDomainConstraints()){
                   column.setUseDomainConstraints(true);
                   table.setDirty(true);

  • EA2: Code is generated for only one column with Domain check constraint.

    I created a Domain with a Value List (Y or N - Yes or No) and used that domain for two columns in the same table. But for only one column (the last one) the check appears in the generated DDL.
    After I enabled the "Use Domain Constraints" both checks appear in the DDL, but one as an inline check constraint and one as an "Alter table add contraint.."
    Once I changed the naming Template for the check constraint, both constraints are generated as an Alter table clause. The inline check constraint is only generated when the name of the constraint (according to the template) is too long. It would be nice if I could choose if I want an inline or a separate check constraint definition.
    Edited by: Roel on Nov 23, 2010 11:55 AM
    Edited by: Roel on Nov 23, 2010 12:02 PM

    I logged ER for that
    Philip

  • Can a constraint check two different tables for the existence of a parent item?

    My database has a table Message, and a table MessageReply.
    Each MessageReply has a ParentID and a MessageReplyType (Message, or Reply).
    When the MessageReplyType is a message, I would like to ensure the MessageReply.ParentID (MessageID) exists in the Message table.
    And when the MessageReplyType is a reply, I need to ensure the MessageReply.ParentID (MessageID) exists in the MessageReply table. 
    I am doing this through client code, but I would like the database to enforce this to protect the database from well intentioned programmers like me.
    Can it be done?
    Thank you

    There is a problem with your function and the whole idea of using a check constraint and a function to simulate a foreign key constraint is problematic.
    The problem with your function is when you do a statement like
    Set @ReturnValue = (Select MessageID From MessageReply Where MessageID = @ParentID);
    then if that row does not exist in MessageReply, @ReturnValue is set to NULL.  Then you are returning that NULL from the function and using the check constraint to test whether or not that returned NULL is > 0.  Comparing NULL to a value does
    not give you TRUE and it does not give you FALSE, instead you get a logical value called UNKNOWN.  Check constraints only reject a row if the resulting value is FALSE.  It allows the Insert or Update if the logical value is either TRUE or UNKNOWN. 
    So even if the parent row does not exist, that check constraint will allow the new row to be inserted.
    Second, using a function and check constraint to simulate a foreign key constraint always has a problem.  If you go with that (and you have written the function and constraint correctly) and you attempt to insert a row with a bad ParentID so that the
    ParentID does not exist in the appropriate table, you will get a check constraint error and the insert will be rejected.  That is good.  However, suppose you successfully insert a row in MessageReply. For example you insert a row in Message with
    MessageID = 1 and then insert a row in MessageReply with ParentID = 1 and ReplyType = 1.  That will work fine as it should.  But now suppose someone deletes the row in Message with MessageID = 1.  That delete won't fire the check constraint. 
    So it will allow the delete of the row in Message and now you have a row in MessageReply which doesn't have a parent.
    If you want a method that will work completely, you could do that by 1) doing all of your updates to those tables thought stored procedure(s) that check the data to be sure it is valid before inserting/updating/deleting, or 2) writing trigger(s) on both
    Message and MessageReply to make sure that any changes are valid, or 3) add computed columns to the MessageReply table so that you can write foreign key constraints. 
    I would go with method 3.  That would look something like changing your MessageReply table to look something like
    Create Table Message(MessageID int Primary Key
    -- other columns as needed
    Create Table MessageReply(MessageID int Primary Key
    ,ParentID int Not Null
    ,MessageReplyType int Not Null Check (MessageReplyType In (1,2))
    ,ParentMessageID As Case When MessageReplyType = 1 Then ParentID Else Null End Persisted
    ,ParentMessageReplyID As Case When MessageReplyType = 2 Then ParentID Else Null End Persisted
    -- other columns as needed
    Alter Table MessageReply
    add constraint chk_MessageParentExists Foreign Key(ParentMessageID) References Message;
    Alter Table MessageReply
    add constraint chk_MessageReplyParentExists Foreign Key(ParentMessageReplyID) References MessageReply;
    Tom

  • HT5035 I have a credit from an Apple gift card. I want to buy itunes. When I go to check out it asks for my credit card info. How do I use the credit I have?

    How do I use the itunes credit I have on my MAC? I received a gift card and loaded it on my MAC. I want to buy itunes. When I go to check out it asks for my credit card info. How do I use the credit?

    Purchase and Redeem an iTunes Gift Card.
    How to Redeem a Code  >  http://support.apple.com/kb/ht1574

  • (Cisco Historical Reporting / HRC ) All available connections to database server are in use by other client machines. Please try again later and check the log file for error 5054

    Hi All,
    I am getting an error message "All available connections to database server are in use by other client machines. Please try again later and check the log file for error 5054"  when trying to log into HRC (This user has the reporting capabilities) . I checked the log files this is what i found out 
    The log file stated that there were ongoing connections of HRC with the CCX  (I am sure there isn't any active login to HRC)
    || When you tried to login the following error was being displayed because the maximum number of connections were reached for the server .  We can see that a total number of 5 connections have been configured . ||
    1: 6/20/2014 9:13:49 AM %CHC-LOG_SUBFAC-3-UNK:Current number of connections (5) from historical Clients/Scheduler to 'CRA_DATABASE' database exceeded the maximum number of possible connections (5).Check with your administrator about changing this limit on server (wfengine.properties), however this might impact server performance.
    || Below we can see all 5 connections being used up . ||
    2: 6/20/2014 9:13:49 AM %CHC-LOG_SUBFAC-3-UNK:[DB Connections From Clients (count=5)]|[(#1) 'username'='uccxhrc','hostname'='3SK5FS1.ucsfmedicalcenter.org']|[(#2) 'username'='uccxhrc','hostname'='PFS-HHXDGX1.ucsfmedicalcenter.org']|[(#3) 'username'='uccxhrc','hostname'='PFS-HHXDGX1.ucsfmedicalcenter.org']|[(#4) 'username'='uccxhrc','hostname'='PFS-HHXDGX1.ucsfmedicalcenter.org']|[(#5) 'username'='uccxhrc','hostname'='47BMMM1.ucsfmedicalcenter.org']
    || Once the maximum number of connection was reached it threw an error . ||
    3: 6/20/2014 9:13:49 AM %CHC-LOG_SUBFAC-3-UNK:Number of max connection to 'CRA_DATABASE' database was reached! Connection could not be established.
    4: 6/20/2014 9:13:49 AM %CHC-LOG_SUBFAC-3-UNK:Database connection to 'CRA_DATABASE' failed due to (All available connections to database server are in use by other client machines. Please try again later and check the log file for error 5054.)
    Current exact UCCX Version 9.0.2.11001-24
    Current CUCM Version 8.6.2.23900-10
    Business impact  Not Critical
    Exact error message  All available connections to database server are in use by other client machines. Please try again later and check the log file for error 5054
    What is the OS version of the PC you are running  and is it physical machine or virtual machine that is running the HRC client ..
    OS Version Windows 7 Home Premium  64 bit and it’s a physical machine.
    . The Max DB Connections for Report Client Sessions is set to 5 for each servers (There are two servers). The no of HR Sessions is set to 10.
    I wanted to know if there is a way to find the HRC sessions active now and terminate the one or more or all of that sessions from the server end ? 

    We have had this "PRX5" problem with Exchange 2013 since the RTM version.  We recently applied CU3, and it did not correct the problem.  We have seen this problem on every Exchange 2013 we manage.  They are all installations where all roles
    are installed on the same Windows server, and in our case, they are all Windows virtual machines using Windows 2012 Hyper-V.
    We have tried all the "this fixed it for me" solutions regarding DNS, network cards, host file entries and so forth.  None of those "solutions" made any difference whatsoever.  The occurrence of the temporary error PRX5 seems totally random. 
    About 2 out of 20 incoming mail test by Microsoft Connectivity Analyzer fail with this PRX5 error.
    Most people don't ever notice the issue because remote mail servers retry the connection later.  However, telephone voice mail systems that forward voice message files to email, or other such applications such as your scanner, often don't retry and
    simply fail.  Our phone system actually disables all further attempts to send voice mail to a particular user if the PRX5 error is returned when the email is sent by the phone system.
    Is Microsoft totally oblivious to this problem?
    PRX5 is a serious issue that needs an Exchange team resolution, or at least an acknowledgement that the problem actually does exist and has negative consequences for proper mail flow.
    JSB

  • TS3899 "cannot get mail" in iphone5 suddenly. been using iphone to check 2 email accounts for months now, one is gmail and not troubled. the other is thunderbird and i get this error message now. no settings have been changed or anything! ideas?

    hey all, I have been getting the "cannot get mail" error message on my iphone5 suddenly.
    ive been using iphone to check two email accounts for months now, one is gmail and not troubled. the other is mail from thunderbird and i get this error message now saying it is not responding. no settings have been changed or anything, it just suddenly stopped receiving mail on my device as of Tuesday afternoon.
    Does anyone have iny ideas about why? i have yet to update to the new OS7 yet, could that be it?

    'The installer has insufficient privileges to modify this file C:\Program Files (x86)\Common Files\Apple\Apple Application Support\Web kit.resources\inspector\Images\Spinner Inactive Selected.gif.'
    That one's consistent with disk/file damage. The first thing I'd try with that is running a disk check (chkdsk) over your C drive.
    XP instructions in the following document: How to perform disk error checking in Windows XP
    Vista instructions in the following document: Check your hard disk for errors
    Windows 7 instructions in the following document: How to use CHKDSK (Check Disk)
    Select both Automatically fix file system errors and Scan for and attempt recovery of bad sectors, or use chkdsk /r (depending on which way you decide to go about doing this). You'll almost certainly have to schedule the chkdsk to run on startup. The scan should take quite a while ... if it quits after a few minutes or seconds, something's interfering with the scan.
    Does the chkdsk find/repair any damage? If so, can you get an install to go through properly afterwards?

  • Using a function in a check constraint

    Hi,
    I created a domain table(id, code, domain_code, description) and foreign keys to this table. To ensure that a valid domain is put in the column I created a function that returns a boolean and has two parameters (id and domain_code). It returns true if the id and domain belong together.
    I want to know if it is possible to create a check constraint which validates the data in the refering table with the data in the domain table.
    Does anyone know if this is possible? Or do I have to use a db-trigger?
    Regards,
    Romano

    It still sounds like all you need is a foreign key constraint. Please see the example below, based on your revised criteria.
    scott@ORA92> create table domain
      2    (id         number,
      3       code         number,
      4       domain_code number,
      5       constraint  domain_pk primary key (id),
      6       constraint  domain_uk unique (code, domain_code))
      7  /
    Table created.
    scott@ORA92> insert into domain values (1, 10, 2)
      2  /
    1 row created.
    scott@ORA92> create table domain_values_table
      2    (id         number,
      3       domain_code number,
      4       constraint domain_values_table_uk unique (id, domain_code))
      5  /
    Table created.
    scott@ORA92> insert into domain_values_table values (1, 2)
      2  /
    1 row created.
    scott@ORA92> commit
      2  /
    Commit complete.
    scott@ORA92> create table referring
      2    (id         number,
      3       domain_code number,
      4       status         number,
      5       constraint  referring_fk foreign key (status)
      6                references domain (id),
      7       constraint  referring_fk2 foreign key (id, domain_code)
      8                references domain_values_table (id, domain_code))
      9  /
    Table created.
    scott@ORA92> insert into referring values (1,  2, null)
      2  /
    1 row created.
    scott@ORA92> insert into referring values (3, 4, null)
      2  /
    insert into referring values (3, 4, null)
    ERROR at line 1:
    ORA-02291: integrity constraint (SCOTT.REFERRING_FK2) violated - parent key not found

  • Domain check constraint using column name

    Hello,
    in the domain administration of Data Modeler, I defined a domain "age",
    and set it to logical type "Integer". Now I want to define a check constraint
    for that domain, saying, that every attribute of domain "age" must have
    values greater than 18.
    But how should I specify the column name for that check-constraint, since
    I cannot know now, to which columns this domain will be applied to, and
    these columns could have different names!
    I tried {column} > 18 and hoped that {column} might be substituted by
    the appropriate column name when generating DDL but it was not,
    the DDL contained "check ( {column} > 18 ) which did of course not work.
    Does anybody have an idea?

    Thanks a lot, that solved the problem. I noticed additionally, that %COLUMN% is case sensitive, so %COLUMN% gets substituted by the column name in the DDL, while %column% does not.

  • I wan't update using itunes, i want to make update using my phone, but when check for an update using software update in setting message appear " can't check for update....."?

    i wan't update using itunes, i want to make update using my phone, but when check for an update using software update in setting message appear " can't check for update....."?

    Reboot the device and see if the error happens again. Updating through iTunes is usually optimal, but the file size differs via Software Update on the device and iTunes (50MB vs ~800MB)

  • Check this Single place for all R12 Docs - Very Useful

    Check this,
    http://download.oracle.com/docs/cd/E18727_01/index.htm
    Description
    Oracle E-Business Suite is a comprehensive suite of integrated, global business applications which provides a customer focused strategy. Use this web site to search the various documentation types for Oracle EBS Applications. This web page provides access to documentation available in PDF and HTML formats. Use the tabs to locate and view Oracle EBS documentation.
    (Note: I have posted the same in OAF Forum, making it duplicate to share with a larger group)
    With regards,
    Kali.
    OSSi.

    Duplicate post -- Check this Single place for all R12 Docs - Very Useful
    Please post only once.
    Thanks!

  • Crash of Oracle XE when check constraint uses in-operator with desc. values

    ORA-03113 and other errors in conjunction with lost of connection occur in Oracle XE under the following conditions:
    /* Crash (values of check constraint in descending order) */
    DROP TABLE CRASHTEST CASCADE CONSTRAINTS;
    CREATE TABLE CRASHTEST
    CRASHTEST_ID NUMBER(9),
    CRASHTEST_OK NUMBER(1) DEFAULT 0
    ALTER TABLE CRASHTEST ADD (CONSTRAINT CRASHTEST_CK CHECK (CRASHTEST_OK IN (0,-1)));
    INSERT INTO CRASHTEST (CRASHTEST_ID, CRASHTEST_OK) VALUES (1, 0);
    INSERT INTO CRASHTEST (CRASHTEST_ID, CRASHTEST_OK) VALUES (2, -1);
    COMMIT;
    SELECT * FROM CRASHTEST WHERE CRASHTEST_OK = 0;
    If all values of the in-clause within the check constraint are entered in ascending order, no error occurs:
    /* No Crash (values of check constraint in ascending order) */
    DROP TABLE CRASHTEST CASCADE CONSTRAINTS;
    CREATE TABLE CRASHTEST
    CRASHTEST_ID NUMBER(9),
    CRASHTEST_OK NUMBER(1) DEFAULT 0
    ALTER TABLE CRASHTEST ADD (CONSTRAINT CRASHTEST_CK CHECK (CRASHTEST_OK IN (-1,0)));
    INSERT INTO CRASHTEST (CRASHTEST_ID, CRASHTEST_OK) VALUES (1, 0);
    INSERT INTO CRASHTEST (CRASHTEST_ID, CRASHTEST_OK) VALUES (2, -1);
    COMMIT;
    SELECT * FROM CRASHTEST WHERE CRASHTEST_OK = 0;
    Especially interesting is the fact, that the error is caused by a check constraint in conjunction with a select statement!
    Hopefully, there are no other hidden bombs stealing my time...
    Have a nice day,
    Sven

    It might be interesting to post that in the XE forum to notify Oracle developers and XE users.
    Oracle Database Express Edition (XE)
    C.

  • DB Diagram: Modality Difference between NOT NULL and check constraint

    Hi,
    I am using jdev 11g (11.1.1.10) I am trying to create a db diagram from two tables. I have a FK that is NOT NULL (defined on the column). When i try to display these two tables modality, it does not show up in the diagram. I noticed that there are two ways NOT null can be defined on a table (right click on the db object to edit it; a) under column definitions there is a check box for not null, b) there is a check constraint that one can add to do not null.
    I am confused and was wondering whether I must I have check constraints on the database in order to display modality (optional versus mandatory). Logically speaking it does not make any sense though.

    Hi Susan,
    Thanks for your email. I understand that in order to show modality under
    UML notation, one must define a COLUMN being NOT NULL instead of defining a check constraint.
    I still do not understand how modality (optional versus mandatory) is shown in ERD notation in JDev. I tried flipping ERD/UML notations and made sure icons for tables were showing, but no MODALITY is shown in ERD notation ( an '0" icon or a "|" icon for optional and mandatory). Is it the solid line versus dotted line in the ERD diagram? I am confused because generally under Crawfoot ERD notation '0" icon or a "|" icon is shown for modality.
    Modality gets picked up in jdev diagram when COLUMN not null is specified and UML notation is used
    ALTER TABLE DETAILAJ MODIFY EMPID not null;
    Modality does not get picked up in jdev db diagram when check constraint is specified and UML notation is used
    ALTER TABLE DETAILAJ
    ADD CONSTRAINT CK_NN_DETAILAJ__EMPID CHECK(EMPID IS NOT NULL) ;
    Another question i have related to the matter mentioned above is as follows. Since I want to see modality in db diagram, it follows that I must define a column as not null instead of a check constraint. I must also use NO VALIDATE on NOT NULL column because i have prior data that does not meet the new restriction. I noticed that if i use the following syntax to define a NOT NULL column, two things happen.
    a) A constraint is defined as not null automatically and a system generated name is given to the constraint.
    b) DB diagram in Jdev does not show the modality.
    My question is whether there is a way to see modality in this case.
         alter table DETAILAJ
         MODIFY EMPID NOT NULL ENABLE NOVALIDATE ;
    Edited by: user11219846 on Nov 19, 2009 11:07 AM

  • Is it possible to create a dynamic(with a select) check constraint?

    create table a (col_to_be_coded_fora number);
    create table b (col_to_be_coded_forb number);
    create table c (col_name varchar2(20), col_code number, col_desc varchar2(20));
    insert into c values ('col_to_be_coded_fora', 1, 'active');
    insert into c values ('col_to_be_coded_fora', 2, 'de-active');
    insert into c values ('col_to_be_coded_fora', 3, 'pending');
    insert into c values ('col_to_be_coded_forb', 10, 'school');
    insert into c values ('col_to_be_coded_forb', 20, 'hospital');
    insert into a values ( 1); -- meaning 'active' for table a, column col_to_be_coded_fora, can go in
    insert into a values (10); -- meaning nothing for table a, column col_to_be_coded_fora, must give error
    insert into b values ( 1); -- meaning nothing for table b, column col_to_be_coded_forb, must give error
    insert into b values (10); -- meaning 'school' for table b, column col_to_be_coded_fora, can go in
    I know i can handle this problem with dividing table c into to tables and creating foreign key relationship.
    in this demo case i have only a and b, 2 tables but i want to encode thousands of tables with a table like c.
    &#304;s it possible to create a dynamic check constraint on a table which selects c table for the inputs that have permision?
    Or do i have to use after insert, update triggers on table a and b to ensure this functionality?
    Is there a smarter implementation for this need, may be a design change?
    Thank you,
    Kind regards.
    Tonguç

    Hi Tonguç,
    A small design change makes it possible to do this with simple foreign key constraints.
    I would do something like:
    ual303@ORKDEV01> CREATE TABLE c (
      2    col_name VARCHAR2(20),
      3     col_code NUMBER,
      4     col_desc VARCHAR2(20),
      5     PRIMARY KEY (col_name, col_code)
      6  );
    Tabel is aangemaakt.
    ual303@ORKDEV01> CREATE TABLE a (
      2    col_to_be_coded_fora NUMBER PRIMARY KEY,
      3     col_name VARCHAR2(20) DEFAULT 'col_to_be_coded_fora' CHECK (col_name = 'col_to_be_coded_fora'),
      4     FOREIGN KEY (col_name, col_to_be_coded_fora) REFERENCES c
      5  );
    Tabel is aangemaakt.
    ual303@ORKDEV01> CREATE TABLE b (
      2    col_to_be_coded_forb NUMBER PRIMARY KEY,
      3     col_name VARCHAR2(20) DEFAULT 'col_to_be_coded_forb' CHECK (col_name = 'col_to_be_coded_forb'),
      4     FOREIGN KEY (col_name, col_to_be_coded_forb) REFERENCES c
      5  );
    Tabel is aangemaakt.
    ual303@ORKDEV01> insert into c values ('col_to_be_coded_fora', 1, 'active');
    1 rij is aangemaakt.
    ual303@ORKDEV01> insert into c values ('col_to_be_coded_fora', 2, 'de-active');
    1 rij is aangemaakt.
    ual303@ORKDEV01> insert into c values ('col_to_be_coded_fora', 3, 'pending');
    1 rij is aangemaakt.
    ual303@ORKDEV01> insert into c values ('col_to_be_coded_forb', 10, 'school');
    1 rij is aangemaakt.
    ual303@ORKDEV01> insert into c values ('col_to_be_coded_forb', 20, 'hospital');
    1 rij is aangemaakt.
    ual303@ORKDEV01> -- meaning 'active' for table a, column col_to_be_coded_fora, can go in
    ual303@ORKDEV01> insert into a(col_to_be_coded_fora) values ( 1);
    1 rij is aangemaakt.
    ual303@ORKDEV01> -- meaning nothing for table a, column col_to_be_coded_fora, must give error
    ual303@ORKDEV01> insert into a(col_to_be_coded_fora) values (10);
    insert into a(col_to_be_coded_fora) values (10)
    FOUT in regel 1:
    .ORA-02291: integrity constraint (UAL303.SYS_C0033537) violated - parent key not found
    ual303@ORKDEV01> -- meaning nothing for table b, column col_to_be_coded_forb, must give error
    ual303@ORKDEV01> insert into b(col_to_be_coded_forb) values ( 1);
    insert into b(col_to_be_coded_forb) values ( 1)
    FOUT in regel 1:
    .ORA-02291: integrity constraint (UAL303.SYS_C0033540) violated - parent key not found
    ual303@ORKDEV01> -- meaning 'school' for table b, column col_to_be_coded_fora, can go in
    ual303@ORKDEV01> insert into b(col_to_be_coded_forb) values (10);
    1 rij is aangemaakt.
    ual303@ORKDEV01>Cheers,
    Colin

Maybe you are looking for