title: Oracle SQL, conditional foreign key
body: <p>I have a problem with implementing DB. I have 2 tables:</p>
  
  <pre><code> CREATE TABLE TAB1
   (
      TAB1_ID INT NOT NULL PRIMARY KEY,
      TAB1_BOOL VARCHAR(4) NOT NULL CHECK (TAB1_BOOL IN('OPT1', 'OPT2'))
   );
   CREATE TABLE TAB2
   (
     TAB2_ID INT NOT NULL
   );
  </code></pre>
  
  <p>I would like to make TAB2_ID as foreign key of TAB1_ID, but TAB2_ID can be only these TAB1_IDs which rows in table TAB1 are marked with TAB1_BOOL == OPT1. For example:</p>
  
  <pre><code>TAB1 contains 2 rows: 
  1. 'TAB1_ID==1' 'TAB1_BOOL==OPT1', 
  2. 'TAB1_ID==2' 'TAB1_BOOL==OPT2'.
  Now, statement like:
  INSERT INTO TAB2 (TAB2_ID) VALUES (2);
  should be rejected because row with TAB1_ID==2 is marked with OPT2
  </code></pre>
  
  <p>Is it possible to make this in Oracle SQL ?</p>