-5

how do i add or insert multiple rows in two columns, at the same time? i am trying this

insert into Gwish_bal(Account_code,Flag) values (
('10192885','I'),
('10146883','I')
);

and it is not working i keep getting ORA-00907: missing right parenthesis. i want to insert a thousand numbers and flag them I. the output i need is a table which looks like this

a

ccount code    flag
800000008        I
800000009        I
....
800100000        I
Jens
  • 67,715
  • 15
  • 98
  • 113
J.Mike1914
  • 21
  • 2

5 Answers5

2

This should work:

INSERT ALL
INTO Gwish_bal (Account_code, Flag) VALUES ('10192885', 'l')
INTO Gwish_bal (Account_code, Flag) VALUES ('10146883','I');

But the more common solution I have come across is:

INSERT INTO Gwish_bal(Account_code,Flag)
SELECT '10192885', 'l' FROM dual
  UNION ALL
SELECT '10146883','I' FROM dual;
fhossfel
  • 2,041
  • 16
  • 24
  • INSERT INTO Gwish_bal(Account_code,Flag) SELECT '10192885', 'l' FROM dual UNION ALL SELECT '10146883','I' FROM dual; – J.Mike1914 Jun 27 '17 at 07:14
  • INSERT INTO Gwish_bal(Account_code,Flag) SELECT '10192885', 'l' FROM dual UNION ALL SELECT '10146883','I' FROM dual; This one works, thank you but for like a thousand rows eg '100000','I' TO '109000', 'I'. how do i do that – J.Mike1914 Jun 27 '17 at 07:17
  • You can try with a PL/SQL table and FORALL. If you are outside the database, use a statement with bind variables. If you just want the data in the database use sqlldr. – fhossfel Jun 27 '17 at 07:39
1

try

INSERT INTO Gwish_bal (Account_code, Flag)
VALUES
    ('10192885', 'l'),
    ('10146883', 'l');
Idriss Benbassou
  • 1,481
  • 2
  • 14
  • 23
1

Use this syntax:

INSERT ALL
  INTO Gwish_bal(Account_code,Flag) VALUES ('10192885','I')
  INTO Gwish_bal(Account_code,Flag) VALUES ('10146883','I')
SELECT * FROM dual;

for thousand rows:

insert INTO Gwish_bal(Account_code,Flag)
select to_char(level), 'I'
from dual
where level >= 10000
connect by level <= 11000 
I3rutt
  • 574
  • 4
  • 18
  • thank you!! i am new to this. so lets say i want add a thousand rows of account code and flag how would i go about it – J.Mike1914 Jun 27 '17 at 07:23
  • insert into Gwish_bal(Account_code, Flag) select Account_code, Flag from table_with_thousand_rows – I3rutt Jun 27 '17 at 07:27
1

this should be work in oracle

INSERT ALL 
    INTO Gwish_bal ("Account_code", "Flag")
         VALUES ('10192885', 'l')
    INTO Gwish_bal ("Account_code", "Flag")
         VALUES ('10192885', 'l')
    INTO Gwish_bal ("Account_code", "Flag")
         VALUES  ('10192885', 'l')
 SELECT * FROM dual  ;
Idriss Benbassou
  • 1,481
  • 2
  • 14
  • 23
0

You don't need to wrap the list.

insert into Gwish_bal(Account_code,Flag) values ('10192885','I'), ('10146883','I');
EvgenyKolyakov
  • 3,310
  • 2
  • 21
  • 31