title: How to insert data into table with composite unique keys
body: <p>I have a table demo where I have 5 columns as below:</p>
  <pre><code>Create table demo
     
     ( 
     Demo_id number,
     demo_a number,
     Demo_b number,
     Demo_c number
    )
  </code></pre>
  <p>So  here demo_id is surrogate PK and combination of demo_a,demo_b,demo_cis unique</p>
  <p>So I have created a SP like this</p>
  <pre><code>save 
   (  pdemo_a in number. ,
       p_demo_b in number. , 
       p_demp_c in number,
       p_demo_id out number
   )
  </code></pre>
  <p>So I am receiving data from API into this SP and I have to insert the data into my demo_table. So I have written logic where I am checking if the combination of (demo_a,demo_b,demo_c) exists in the table. if it exists then I am selecting demo_id into a variable and returning it to the API otherwise I am inserting the data for this unique combination in my table using no_data_found exception.</p>
  <p>So basically code is:</p>
  <pre><code>Begin
  
      Select demo_id 
        into p_demo_id 
  
        from demo 
          where demo _a=p_demo_a
          and demo_b=p_demo_b
          and demo_c = p_demo_c;
  
  Exception 
  
      When no data found 
      then 
  
          insert into demo values()
  
  </code></pre>
  <p>Problem is the columns that are part of the unique key can be null so in that case when I check if the combination exists then because any of the field can be null because of which my select into clause fails. And the code goes to no_data_found section and tries to insert the record in the table but it fails beca``use that combination exists in the table. So what should I do. How do I return the demo_id to the API without throwing error.</p>