Home > Enterprise >  Missing comma in insert statement
Missing comma in insert statement

Time:02-02

I have an insert statmement which wont execute due to a missing comma error.

INSERT INTO trip 
VALUES (01, TO_DATE('28-Jan-2022', 'dd-Mon-yyyy', '29-Jan-2022', 'dd-Mon-yyyy', '28-Jan-2022 7:10:00', 'dd-Mon-yyyy hh:mi:ss', '29-Jan-2022 9:30:00', 'dd-Mon-yyyy hh:mi:ss', 0, 200, 20, 'SANFDAE11U1286116', 34, 34, 'AUS00101', 01 );

Can you help me find it? Thankyou.

CodePudding user response:

I think you got an error because you did not close function TO_DATE, so you need to add ).
This statement would work without error, maybe.

INSERT INTO trip VALUES (01, TO_DATE('28-Jan-2022', 'dd-Mon-yyyy'), TO_DATE('29-Jan-2022', 'dd-Mon-yyyy'), TO_DATE('28-Jan-2022 7:10:00', 'dd-Mon-yyyy hh:mi:ss'), TO_DATE('29-Jan-2022 9:30:00', 'dd-Mon-yyyy hh:mi:ss'), 0, 200, 20, 'SANFDAE11U1286116', 34, 34, 'AUS00101', 01 );

I don't know what AUS00101, SANFDAE11U1286116... means, but anyway the problem is opening and closing brackets.

Also, TO_DATE is known to be capable of only 1 date.

CodePudding user response:

Each string requires its own TO_DATE

Additionally,

  • 01 is a string; you should enclose it into single quotes; without them, you'll enter a number, 1 (leading zero will be lost)
  • name all columns in INSERT; you'll easily get confused if you specify just values to be inserted. Something like my dummy example (as I don't know real column names):

INSERT INTO trip (id,
                  start_date,
                  end_date,
                  date_1,
                  date_2,
                  ping,
                  pong,
                  attr,
                  string_value,
                  num1,
                  num2,
                  country,
                  code)
     VALUES ('01',
             TO_DATE ('28-Jan-2022', 'dd-Mon-yyyy'),
             TO_DATE ('29-Jan-2022', 'dd-Mon-yyyy'),
             TO_DATE ('28-Jan-2022 7:10:00', 'dd-Mon-yyyy hh:mi:ss'),
             TO_DATE ('29-Jan-2022 9:30:00', 'dd-Mon-yyyy hh:mi:ss'),
             0,
             200,
             20,
             'SANFDAE11U1286116',
             34,
             34,
             'AUS00101',
             '01');
  •  Tags:  
  • Related