Search code examples
oracle-databaseinsertobject-relational-model

How do I insert data into a object relational table with multiple ref in the schema


I have a table with a schema of Table(number, ref, ref, varchar2, varchar2,...).

How would I insert a row of data into this table?

When I do:

insert into table 
values (1, select ref(p), ref(d), '239 F.3d 1343', '35 USC § 283', ... 
           from plaintiff p, defendant d
            where p.name='name1' and d.name='name2');

I get a "missing expression" error.

If I do:

insert into table
1, select ref(p), ref(d), ... 
from plaintiff p, defendant 
where p.name=...;

I get a "missing keyword VALUES" error.


Solution

  • Your syntax on the insert is off. Try:

    insert into table  
    (select 1, ref(p), ref(d), '239 F.3d 1343', '35 USC § 283', ... 
       from plaintiff p, defendant d where p.name='name1' and d.name='name2');
    

    In general, it's a good practice to explicitly mention the columns you're inserting into as well, to avoid problems later if the column order changes, as well as to self-document the code:

    insert into table (col1, col2, col3, ...) 
    (select 1, ref(p), ref(d), '239 F.3d 1343', '35 USC § 283', ... 
       from plaintiff p, defendant d where p.name='name1' and d.name='name2');