【发布时间】:2015-11-10 10:39:04
【问题描述】:
我想为这些 Oracle 表创建测试数据:
CREATE TABLE AGENT_HISTORY(
EVENT_ID INTEGER NOT NULL,
AGENTID INTEGER NOT NULL,
EVENT_DATE DATE NOT NULL
)
/
CREATE TABLE CPU_HISTORY(
CPU_HISTORY_ID INTEGER NOT NULL,
EVENT_ID INTEGER NOT NULL,
CPU_NAME VARCHAR2(50 ) NOT NULL,
CPU_VALUE NUMBER NOT NULL
)
/
你能帮我创建一个为 100 行生成随机值的程序吗?
我试过了
BEGIN
FOR loop_counter IN 1..1000
LOOP
INSERT INTO AGENT_HISTORY (EVENT_ID, AGENTID, EVENT_DATE)
VALUES (loop_counter, 22, SYSDATE);
END LOOP;
COMMIT;
FOR loop_counter IN 1..1000
LOOP
INSERT INTO CPU_HISTORY_ID (CPU_HISTORY_ID, EVENT_ID, CPU_NAME, CPU_VALUE)
VALUES (loop_counter, loop_counter, 'cpu1', dbms_random.value(1,100));
END LOOP;
COMMIT;
END;
但我收到以下错误:
Error report -
ORA-00001: unique constraint (ADMIN.KEY8) violated
ORA-06512: at line 5
00001. 00000 - "unique constraint (%s.%s) violated"
*Cause: An UPDATE or INSERT statement attempted to insert a duplicate key.
For Trusted Oracle configured in DBMS MAC mode, you may see
this message if a duplicate entry exists at a different level.
*Action: Either remove the unique restriction or do not insert the key.
Error report -
ORA-06550: line 5, column 16:
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 5, column 4:
PL/SQL: SQL Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
【问题讨论】:
-
关闭不是因为你不喜欢有人想要代码这一事实。
-
INSERT INTO CPU_HISTORY_ID删除_ID以使用表名CPU_HISTORY。
标签: sql oracle compiler-errors ora-06550