Thursday, March 24, 2011

Copy record to another table adding fields

Hi, i have 2 tables: tab1 (field1, field2, field3) tab2 (field1, field2,field3, field4)

I want to copy a record from tab1 to tab2 taking all the fields and adding a value for field4. How can i select field1, field2 and field3 from tab2 and also add a value? I know that SELECT and VALUES in a INSERT query are mutually exclusive. I'm working on a Oracle DB

Thanks in advance

Gustavo

From stackoverflow
  • I don't know Oracle, but in Ms SQL it works like this:

    insert into tab2 (field1, field2, field3, field4) 
    select field1, field2, field3, 'New Value' from tab1
    
    Dave Costa : Yes, this would work in Oracle. Of course this example assumes the value for field4 is a constant.
    pistacchio : It worked, thanks!

0 comments:

Post a Comment