0

我正在创建一个脚本,它将一次性在表中插入多个数据。

create table emp
(
Empno number(3) primary key,
ename varchar2(20),
job varchar2(20),
MGR varchar2(20),
sal varchar2(20)
);


insert all
into emp values(100,'Dinesh','President',NULL,50000);
into emp values(101,'Tanveer','MGR',100,25000);
into emp values(102,'Tejas','Developer',101,12000);
select * from dual

但是上面的插入命令给出了错误

ORA-00911: 无效字符

上面的代码是正确的,但有些地方不正确,请帮我找出来。

4

1 回答 1

1

In Oracle, a single-table INSERT can either specify a single VALUES clause or a sub-query. Since the task requires the insertion of multiple rows, the single VALUES clause won't work. A sub-query must be specified.

One simple way to generate the desired sub-query is to SELECT a sequence of literals from dual for each row and to collapse them all into a single table using the UNION ALL operator.

INSERT INTO emp ( empno, ename, job, mgr, sal )
    SELECT 100, 'Dinesh',  'President', NULL, 50000 FROM dual UNION ALL
    SELECT 101, 'Tanveer', 'MGR',       100,  25000 FROM dual UNION ALL
    SELECT 102, 'Tejas',   'Developer', 101,  12000 FROM dual;
于 2013-09-06T16:53:27.243 回答