Reusing an anonymous parameter in a prepared statement
        Posted  
        
            by Chris Lieb
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Chris Lieb
        
        
        
        Published on 2010-05-27T21:07:43Z
        Indexed on 
            2010/05/27
            21:11 UTC
        
        
        Read the original article
        Hit count: 249
        
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.
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?
Details
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_ROLE_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)
I want to insert the same data into the first and third anonymous parameters.
© Stack Overflow or respective owner