I'm getting an error in SQL command not properly ended

前端 未结 5 625
梦毁少年i
梦毁少年i 2021-01-17 17:36

when I enter this

INSERT INTO works_on
(essn, pno, hours)
values
(\'123456789\', 1, 32.5),
(\'123456789\', 2, 7.5),
(\'666884444\', 3, 40.0),
(\'453453453\',         


        
相关标签:
5条回答
  • 2021-01-17 17:50

    try take a look at this by ShoeLace

    Oracle SQL uses a semi-colon ;  as its end of statement marker.
    
    you will need to add the ; after bother insert statments.
    
    NB: that also assumes ADODB will allow 2 inserts in a single call.
    
    the alternative might be to wrap both calls in a block,
    
        BEGIN
              insert (...) into (...);
              insert (...) into (...);
        END;
    
    0 讨论(0)
  • 2021-01-17 17:53

    The VALUES syntax supports inserting only one entries into a database. In the ORACLE FAQs, the following is suggested:

    INSERT ALL
    INTO works_on (essn, pno, hours) VALUES ('123456789', 1, 32.5)
    INTO works_on (essn, pno, hours) VALUES ('123456789', 2, 7.5)
    INTO works_on (essn, pno, hours) VALUES ('666884444', 3, 40.0)
    INTO works_on (essn, pno, hours) VALUES ('453453453', 1, 20.0)
    INTO works_on (essn, pno, hours) VALUES ('453453453', 2, 20.0)
    INTO works_on (essn, pno, hours) VALUES ('333445555', 2, 10.0)
    INTO works_on (essn, pno, hours) VALUES ('333445555', 3, 10.0)
    INTO works_on (essn, pno, hours) VALUES ('333445555', 10, 10.0)
    INTO works_on (essn, pno, hours) VALUES ('333445555', 20, 10.0)
    INTO works_on (essn, pno, hours) VALUES ('999887777', 30, 30.0)
    INTO works_on (essn, pno, hours) VALUES ('999887777', 10, 10.0)
    INTO works_on (essn, pno, hours) VALUES ('987987987', 10, 35.0)
    INTO works_on (essn, pno, hours) VALUES ('987987987', 30, 5.0)
    INTO works_on (essn, pno, hours) VALUES ('987654321', 30, 20.0)
    INTO works_on (essn, pno, hours) VALUES ('987654321', 20, 15.0)
    INTO works_on (essn, pno, hours) VALUES ('888665555', 20, 0)
    SELECT * FROM dual;
    
    0 讨论(0)
  • 2021-01-17 17:57

    You cannot combine all your values in a single insert like that in Oracle unfortunately. You can either separate your SQL statements, or use another approach like this to run in a single statement:

    INSERT INTO works_on (essn, pno, hours)
    SELECT '123456789', 1, 32.5 FROM DUAL UNION 
    SELECT '123456789', 2, 7.5 FROM DUAL UNION 
    SELECT '666884444', 3, 40.0 FROM DUAL UNION 
    SELECT '453453453', 1, 20.0 FROM DUAL UNION 
    ...
    SELECT '987987987', 30, 5.0 FROM DUAL UNION 
    SELECT '987654321', 30, 20.0 FROM DUAL UNION 
    SELECT '987654321', 20, 15.0 FROM DUAL UNION 
    SELECT '888665555', 20, 0 FROM DUAL
    

    SQL Fiddle Demo

    0 讨论(0)
  • 2021-01-17 17:58
    INSERT INTO 
    WORKS_ON VALUES
    (&ESSN,&PNO,&HOURS);
    

    After u'll get like below dat.

    ENTER VALUE FOR ESSN: IN THIS U ENTER 123456789
    
    ENTER VALUE FOR PNO: IN THIS U ENTER 1
    
    ENTER VALUE FOR HOURS:32.5
    

    After that You'll get:

    1 ROW IS CREATED

    Then type '/' symbol and press enter. You'll get for enter for insert another row into that table.

    Follow above procedure for easy way to insert row into tables.

    0 讨论(0)
  • 2021-01-17 18:04

    In Oracle, you can't specify multiple sets of values like this (I'm guessing that you're coming from a MySQL background where that syntax is allowed). The simplest approach is to generate multiple INSERT statements

    INSERT INTO works_on
    (essn, pno, hours)
    values
    ('123456789', 1, 32.5);
    
    INSERT INTO works_on
    (essn, pno, hours)
    values
    ('123456789', 2, 7.5);
    
    INSERT INTO works_on
    (essn, pno, hours)
    values
    ('666884444', 3, 40.0);
    
    ...
    

    You can also insert multiple rows using a single INSERT ALL statement

    INSERT ALL
      INTO works_on(essn, pno, hours) values('123456789', 1, 32.5)
      INTO works_on(essn, pno, hours) values('123456789', 2, 7.5)
      INTO works_on(essn, pno, hours) values('666884444', 3, 40.0)
      INTO works_on(essn, pno, hours) values('453453453', 1, 20.0)
      INTO works_on(essn, pno, hours) values('453453453', 2, 20.0)
      INTO works_on(essn, pno, hours) values('333445555', 2, 10.0)
      INTO works_on(essn, pno, hours) values('333445555', 3, 10.0)
      ...
    SELECT *
      FROM dual;
    
    0 讨论(0)
提交回复
热议问题