INSERT ALL 有一些怪癖,但你在这里不需要它,你可以删除 ALL 和虚拟 select 使其成为一个简单的插入值语句:
BEGIN
FOR i IN 163 .. 400 LOOP
INSERT INTO results
(student_id,OPN1,OPN2,OPN3,OPN4,AGG1,AGG2,AGG3,AGG4,NEU1,NEU2,NEU3,NEU4,EXT1,EXT2,EXT3,EXT4,CSN1,CSN2,CSN3,CSN4)
VALUES
(i,
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)));
END LOOP;
COMMIT;
END;
/
您也不需要 PL/SQL,您可以使用分层查询(或递归 CTE)而不是循环:
INSERT INTO results
(student_id,OPN1,OPN2,OPN3,OPN4,AGG1,AGG2,AGG3,AGG4,NEU1,NEU2,NEU3,NEU4,EXT1,EXT2,EXT3,EXT4,CSN1,CSN2,CSN3,CSN4)
SELECT
level + 162,
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5)),
round(dbms_random.value(1,5))
FROM dual
CONNECT BY level <= 1 + 400 - 163;
或如@MTO 建议的那样,使用地板而不是圆形:
INSERT INTO results
(student_id,OPN1,OPN2,OPN3,OPN4,AGG1,AGG2,AGG3,AGG4,NEU1,NEU2,NEU3,NEU4,EXT1,EXT2,EXT3,EXT4,CSN1,CSN2,CSN3,CSN4)
SELECT
level + 162,
floor(dbms_random.value(1,6)),
floor(dbms_random.value(1,6)),
floor(dbms_random.value(1,6)),
floor(dbms_random.value(1,6)),
floor(dbms_random.value(1,6)),
floor(dbms_random.value(1,6)),
floor(dbms_random.value(1,6)),
floor(dbms_random.value(1,6)),
floor(dbms_random.value(1,6)),
floor(dbms_random.value(1,6)),
floor(dbms_random.value(1,6)),
floor(dbms_random.value(1,6)),
floor(dbms_random.value(1,6)),
floor(dbms_random.value(1,6)),
floor(dbms_random.value(1,6)),
floor(dbms_random.value(1,6)),
floor(dbms_random.value(1,6)),
floor(dbms_random.value(1,6)),
floor(dbms_random.value(1,6)),
floor(dbms_random.value(1,6))
FROM dual
CONNECT BY level <= 1 + 400 - 163;
db<>fiddle(为简单起见,列较少)。