Reputation: 15
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:
Upvotes: 0
Views: 1372
Reputation: 83
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
Upvotes: 1
Reputation: 32011
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
Upvotes: 2
Reputation: 3833
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
Upvotes: 1
Reputation: 13247
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)
Upvotes: 3