0
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:

Arulkumar
  • 12,966
  • 14
  • 47
  • 68
beyou
  • 15
  • 1
  • 1
  • 5
  • Share what error you are getting. – Gaurav Kandpal Sep 05 '19 at 06:32
  • @Gaurav 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) 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: – beyou Sep 05 '19 at 06:33

4 Answers4

3

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)
Arulkumar
  • 12,966
  • 14
  • 47
  • 68
  • : getting error 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) Error at Command Line : 22 Column : 118 Error report - SQL Error: ORA-00928: missing SELECT keyword 00928. 00000 - "missing SELECT keyword" – beyou Sep 05 '19 at 06:39
  • It's missing the `select` statement required at the end. See documentation for [insert](https://docs.oracle.com/en/database/oracle/oracle-database/12.2/sqlrf/INSERT.html). – William Robertson Sep 05 '19 at 17:43
2

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
Zaynul Abadin Tuhin
  • 31,407
  • 5
  • 33
  • 63
1

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

DarkRob
  • 3,843
  • 1
  • 10
  • 27
1

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

Final'Cie
  • 73
  • 1
  • 8