orcale 批量新增怎么写sql
时间: 2024-06-05 08:08:49 浏览: 63
可以使用 INSERT INTO 语句来实现批量新增操作,具体步骤如下:
1. 准备好要插入的数据,放在一个临时表中,例如:
CREATE TABLE tmp_emp (
empno NUMBER(4),
ename VARCHAR2(10),
job VARCHAR2(9),
mgr NUMBER(4),
hiredate DATE,
sal NUMBER(7,2),
comm NUMBER(7,2),
deptno NUMBER(2)
);
2. 将要插入的数据插入到临时表中,例如:
INSERT INTO tmp_emp VALUES (7369,'SMITH','CLERK',7902,'17-DEC-80',800,NULL,20);
INSERT INTO tmp_emp VALUES (7499,'ALLEN','SALESMAN',7698,'20-FEB-81',1600,300,30);
INSERT INTO tmp_emp VALUES (7521,'WARD','SALESMAN',7698,'22-FEB-81',1250,500,30);
INSERT INTO tmp_emp VALUES (7566,'JONES','MANAGER',7839,'2-APR-81',2975,NULL,20);
INSERT INTO tmp_emp VALUES (7654,'MARTIN','SALESMAN',7698,'28-SEP-81',1250,1400,30);
3. 使用 INSERT INTO SELECT 语句将数据从临时表中插入到目标表中,例如:
INSERT INTO emp (empno, ename, job, mgr, hiredate, sal, comm, deptno)
SELECT empno, ename, job, mgr, hiredate, sal, comm, deptno
FROM tmp_emp;
4. 可以使用 DROP TABLE 语句删除临时表,例如:
DROP TABLE tmp_emp;
这样就完成了批量新增操作。注意,在实际应用中,需要根据具体情况修改表名、字段名以及数据。
阅读全文
相关推荐

















