Inserting multiple rows query failed

1.2k Views Asked by At
INSERT INTO EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)
VALUES  (7499,'ALLEN','SALESMAN',7698,'20-Feb-81',1600,300,30)
      , (7521,'WARD','SALESMAN',7698,'22-Feb-81',1250,500,30);

Tried to insert two rows at the same time. but failed saying "SQL command not properly ended". Can someone please correct the query?

Error:

Error at Command Line : 18 Column : 125 Error report - SQL Error: ORA-00933: SQL command not properly ended 00933. 00000 - "SQL command not properly ended" *Cause: *Action:

4

There are 4 best solutions below

2
Zaynul Abadin Tuhin On BEST ANSWER

try like below

insert into emp  (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)

select 7499,'ALLEN','SALESMAN',7698,'20-Feb-81',1600,300,30  from dual
union all
select 7521,'WARD','SALESMAN',7698,'22-Feb-81',1250,500,30 from dual
2
Arulkumar On

Based on your error message (ORA-00933:SQL command not properly ended), the DBMS is Oracle.

You can use the following query to INSERT INTO in Oracle.

INSERT ALL  
  INTO EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES (7499,'ALLEN','SALESMAN',7698,'20-Feb-81',1600,300,30)  
  INTO EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES (7521,'WARD','SALESMAN',7698,'22-Feb-81',1250,500,30)
0
DarkRob On

To insert multiple records in ORACLE, you need to club your records into cte. Or use Insert All as mentioned by @Arulkumar.

INSERT INTO Emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) 
  WITH names AS ( 
    SELECT 7499,'ALLEN','SALESMAN',7698,'20-Feb-81',1600,300,30 UNION ALL 
    SELECT 7521,'WARD','SALESMAN',7698,'22-Feb-81',1250,500,30 
  ) 
  SELECT * FROM names

You may find this link for more info on insert command in Oracle.Link

0
Final'Cie On

Your Syntax is for Microsoft SQL Server, but your Error Message is from an Oracle DBMS.

You could use the INSERT ALL query:

INSERT ALL
  INTO mytable (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
  INTO mytable (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
  INTO mytable (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
SELECT * FROM dual;

See Official Oracle Documentation