nmdj1234
nmdj1234

Reputation: 1

I have an insert into statement but there's an error with a comma and i just cant fix it

Here's the code i have to do but it gives an error saying the code has not been ended correctly and I cant see the problem, maybe I am just blind but i dont know.

 INSERT INTO Customer VALUES
    (11011, 'Jeffery', 'Smith', '18 Water RD', 0877277521, '[email protected]'),(its giving me an error here and saying the statement hasn't ended correctly)
    (11012, 'Alex', 'Hendricks', '22 Water Rd', 0863257857 , '[email protected]'),
    (11013 , 'Johnson', 'Clark', '101 Summer Lane', 0834567891,'[email protected]'),
    (11014 , 'Henry', 'Jones', '55 Mountain Way',0612547895 ,'[email protected]'),
    (11015 , 'Andre', 'Williams', '5 Main Rd ', 0827238521,'[email protected]');

Upvotes: 0

Views: 523

Answers (2)

You can use an INSERT ALL statement

INSERT ALL
  INTO Customer VALUES (11011, 'Jeffery', 'Smith', '18 Water RD', 0877277521, '[email protected]')
  INTO Customer VALUES (11012, 'Alex', 'Hendricks', '22 Water Rd', 0863257857 , '[email protected]')
  INTO Customer VALUES (11013 , 'Johnson', 'Clark', '101 Summer Lane', 0834567891,'[email protected]')
  INTO Customer VALUES (11014 , 'Henry', 'Jones', '55 Mountain Way',0612547895 ,'[email protected]')
  INTO Customer VALUES (11015 , 'Andre', 'Williams', '5 Main Rd ', 0827238521,'[email protected]')
SELECT * FROM DUAL;

db<>fiddle here

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1269753

Oracle only supports inserting on row at a time. The simplest solution is multiple inserts:

INSERT INTO Customer VALUES (11011, 'Jeffery', 'Smith', '18 Water RD', 0877277521, '[email protected]');
INSERT INTO Customer VALUES (11012, 'Alex', 'Hendricks', '22 Water Rd', 0863257857 , '[email protected]');
INSERT INTO Customer VALUES (11013 , 'Johnson', 'Clark', '101 Summer Lane', 0834567891,'[email protected]');
INSERT INTO Customer VALUES (11014 , 'Henry', 'Jones', '55 Mountain Way',0612547895 ,'[email protected]');
INSERT INTO Customer VALUES (11015 , 'Andre', 'Williams', '5 Main Rd ', 0827238521,'[email protected]');

Other solutions are to use insert all or to convert the statements from values to select . . . from dual union all.

I would also advise you to explicitly list the the columns, to help prevent inadvertent errors.

Upvotes: 3

Related Questions