创建一个很大的EMP表 EMP_LARGE
--CREATE TABLE EMP_LARGE AS SELECT * FROM EMP ; ---先复制一张EMP表 DECLARE --声明变量 v_loop NUMBER; v_num NUMBER; too_large EXCEPTION; BEGIN --开始执行 FOR v_loop IN 1 .. 100 LOOP --EMP开始是14条,14*2^100应该是很大的数了吧 SELECT COUNT(*) INTO v_num FROM emp_large; IF v_num <= 1000000 ---输入你喜欢的行数 THEN INSERT INTO emp_large (empno, ename, job, mgr, hiredate, sal, comm, deptno) SELECT empno, ename, job, mgr, hiredate, sal, comm, deptno FROM emp_large; END IF; END LOOP; COMMIT; --如果大于指定数量,则删除多余的(排序不严谨,随机删除) IF v_num > 1000000 THEN RAISE too_large; --抛异常 END IF ; EXCEPTION ---异常处理 WHEN too_large --异常名称 THEN --删除多余的 DELETE FROM emp_large WHERE ROWID IN ( SELECT rd FROM (SELECT ROWNUM rn,ROWID RD FROM emp_large) WHERE rn>1000000 ) ; COMMIT; SELECT COUNT(*) INTO v_num FROM emp_large; ---重新输入数量显示 dbms_output.put_line('运行成功,表emp_large的行数为:'||v_num); WHEN OTHERS then dbms_output.put_line('执行失败'); END;