title: Reusing an anonymous parameter in a prepared statement
body: <p>I am customizing the insert SQL generated by hibernate and have hit an issue.  When Hibernate generates the query by itself, it inserts data into the first two columns of the table, but this causes a database error since all four columns of the table are non-nullable.  For the insert to be performed properly, it must insert the same data into two columns of the new record.  This means that I need Hibernate to bind the same data to two different parameters in the query (prepared statement) that I am writing.</p>
  
  <p>Is there some SQL syntax that allows me to refer to anonymous parameters bound to a prepared statement in an order different from which they are bound?</p>
  
  <p><strong>Details</strong></p>
  
  <pre><code>REF_USER_PAGE_XREF
  ----------------------------------------
  PK FK1 | NETWORK_ID     | VARCHAR2(100)
  PK FK1 | PAGE_PATH      | VARCHAR2(1000)
         | USER_LAST_UPDT | VARCHAR2(100)
         | TMSP_LAST_UPDT | DATE
  
  insert into 
      REF_USER_PAGE_XREF(
          NETWORK_ID, 
          PAGE_PATH, 
          TMSP_LAST_UPDT, 
          USER_LAST_UPDT) 
  values (
      ?, /* want to insert the same data here */
      ?, 
      ?, /* and here */
      (select 
          to_char(sysdate, 'DD-MON-YY') 
      from 
          dual)
  </code></pre>
  
  <p>I want to insert the same data into the first and third anonymous parameters.</p>
  
  <p><strong><em>Final Answer</em></strong> (based on answer from @mdma)</p>
  
  <pre><code>insert into 
      REF_USER_PAGE_XREF(
          NETWORK_ID, 
          PAGE_PATH, 
          USER_LAST_UPDT, 
          TMSP_LAST_UPDT) 
  select 
      Param1, 
      Param2, 
      Param1, 
      (select 
          to_char(sysdate, 'DD-MON-YY') 
      from 
          dual) 
  from 
      (select 
          ? as Param1, 
          ? as Param2
      from 
          dual) params
  </code></pre>