title: Conditional unique constraint with multiple fields in oracle db
body: <p>I have this table:</p>
  
  <pre><code>XPTO_TABLE (id, obj_x, date_x, type_x, status_x)
  </code></pre>
  
  <p>I wanna create a unique constraint that applies to the fields <code>(obj_x, date_x, type_x)</code> only when <code>status_x &lt;&gt; 5</code>.</p>
  
  <p>I have tried to create this one but Oracle says:</p>
  
  <pre><code>line 1: ORA-00907: missing right parenthesis
  </code></pre>
  
  
  
  <pre><code>CREATE UNIQUE INDEX UN_OBJ_DT_TYPE_STATUS
  ON XPTO_TABLE(
      (CASE
           WHEN STATUS_X &lt;&gt; 5
           THEN
               (OBJ_X,
                TO_CHAR (DATE_X, 'dd/MM/yyyy'),
                TYPE_X)
           ELSE
               NULL
       END));
  </code></pre>
  
  <p>What's the correct syntax ?</p>