2

I was able to insert two rows by the following query. What should I do to insert more rows into it?

insert into friend_name(
     friend_id, 
     first_name, 
     middle_name, 
     last_name)
select  
     3,
     'rich',
     'mond',
     'hill' 
from dual
union all
select 
     4,
     'monunica',
     'bellu',
     'cia' 
from dual
ɐlǝx
  • 1,384
  • 2
  • 17
  • 22
kiranavula
  • 27
  • 1
  • 5
  • 4
    Add another `union all` – Siyual Sep 07 '16 at 15:02
  • thanks is there any other way to do it more efficiently – kiranavula Sep 07 '16 at 15:05
  • 1
    @kiranavula Not really if you are hard coding all the values you are inserting. If you have actual data that's already existing in another table is very simple to do – Stivan Sep 07 '16 at 15:05
  • 1
    Will Oracle allow multiples of the format `insert into t (c1,c2) values (v1,v2), (v3,v4),...` ? This would at least preclude the `select ... from dual;` requirement. – SlimsGhost Sep 07 '16 at 15:08
  • @SlimsGhost it does not work in the oracle its like the code i mentioned above you need to add union all every time as you go on – kiranavula Sep 07 '16 at 15:20

1 Answers1

5

You can try this as well:

insert all
    into demo_table values (1, 'One', 'X' )
    into demo_table values (2, 'Two', 'Y' )
    into demo_table values (3, 'Three', 'Z' )
select * from dual;

@kiranavula..Incase you need to insert records only to few column of the table then use below:

Inserting record to only 1 column of the table.

insert all
    into demo_table(a) values ('One')
    into demo_table(a) values ('Two')
    into demo_table(a) values ('Three')
select * from dual;
XING
  • 9,608
  • 4
  • 22
  • 38