gpt4 book ai didi

sql - 在 Oracle 表中插入随机数据

转载 作者:行者123 更新时间:2023-12-04 21:17:27 26 4
gpt4 key购买 nike

我想在 Oracle 表中创建随机数据:

CREATE TABLE EVENTS(
EVENTID INTEGER NOT NULL,
SOURCE VARCHAR2(50 ),
TYPE VARCHAR2(50 ),
EVENT_DATE DATE,
DESCRIPTION VARCHAR2(100 )
)
/

我试过这个:
BEGIN  
FOR loop_counter IN 1..1000
LOOP
INSERT INTO EVENTS (EVENTID, SOURCE, TYPE, EVENT_DATE, DESCRIPTION) VALUES (loop_counter, loop_counter, 'warning',
DBMS_RANDOM.VALUE(TO_CHAR(DATE '2000-01-01','J') ,TO_CHAR(DATE '9999-12-31','J')), dbms_random.value(1,100));
END LOOP;
COMMIT;
END;

我收到此错误异常

Error report - ORA-06550: line 5, column 13: PL/SQL: ORA-00932: inconsistent datatypes: expected DATE got NUMBER ORA-06550: line 4, column 1: PL/SQL: SQL Statement ignored 06550. 00000 - "line %s, column %s:\n%s" *Cause: Usually a PL/SQL compilation error. *Action:



你能给我建议我如何解决这个问题吗?

最佳答案

用:

BEGIN  
FOR loop_counter IN 1..1000 LOOP
INSERT INTO "EVENTS" (EVENTID, "SOURCE", TYPE, EVENT_DATE, DESCRIPTION)
VALUES (loop_counter, loop_counter, 'warning',
TO_DATE(TRUNC(DBMS_RANDOM.VALUE(TO_CHAR(DATE '2000-01-01','J') ,TO_CHAR(DATE '9999-12-31','J'))),'J')
,dbms_random.value(1,100)
);
END LOOP;
COMMIT;
END;

SqlFiddleDemo

变化:
  • 添加缺失 ;最终 END
  • 报价关键词
  • 重写随机日期生成
  • 关于sql - 在 Oracle 表中插入随机数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33860428/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com