Search code examples
sqloracle-databaseinsertnextval

Insert multiple rows with multiple values nextval Oracle SQL


I'm trying to insert 2 rows with several values and test_id.nextval into an existing dataframe without including the column headings in the code:

insert into x
    select * from
        (select 12345, 'text', test_id_seq.nextval from dual
    union all
        select 23589, 'other text', test_id_seq.nextval from dual);

I got the error: sequence number not allowed here. So I removed the sequence number. Then the error not enough values occured. How can I insert multiple rows into an existing table with nextval ids?


Solution

  • Try this:

        insert into x
        select tt.* , test_id_seq.nextval from
        (select 12345, 'text' from dual
        union all
        select 23589, 'other text' from dual) tt;