Sql 用随机数据填充表
我会尽可能简单地解释我的问题。我有一个任务要完成,我必须进行各种不同的查询,然后通过不同的方法索引、嵌套循环等对它们进行优化。。问题是,对于我来说,要实现主要目标,我需要在我的表中有数千个条目,这样优化方法才能真正产生明显的效果。以下是我正在使用的两个主要表格:Sql 用随机数据填充表,sql,oracle,plsql,Sql,Oracle,Plsql,我会尽可能简单地解释我的问题。我有一个任务要完成,我必须进行各种不同的查询,然后通过不同的方法索引、嵌套循环等对它们进行优化。。问题是,对于我来说,要实现主要目标,我需要在我的表中有数千个条目,这样优化方法才能真正产生明显的效果。以下是我正在使用的两个主要表格: create cluster fact_trip (id_trip integer); create table trip (id_trip integer not null, driver_mark integ
create cluster fact_trip
(id_trip integer);
create table trip
(id_trip integer not null,
driver_mark integer)
cluster fact_trip(id_trip);
alter table cursa add constraint trip_pk primary key(id_trip);
create table facturi
(id_factura integer not null,
price number(6,2) not null,
discount number(6,2),
id_trip integer not null)
cluster fact_trip(id_trip);
alter table facturi add constraint facturi_pk primary key(id_factura);
create index fact_trip_index on cluster fact_trip;
alter table facturi add constraint facturi_trip_fk foreign key(id_trip)
references trip(id_trip);
我知道如何生成和优化查询,但我在plSQL方面不是最好的,我需要创建一个序列或循环,以便填充我的表,特别是应用于表facturi的序列需要依赖于id_trip外键。因此,我要求有人帮助我编写这样一个plSQL代码,它可以用数据随机填充我的两个表。您可以使用下面的语句在表中创建示例数据。下面的两条语句将在每个表中放置1000行。如果需要更多或更少的记录,可以在第一次插入时调整级别 插入行程 选择CAST ROWNUM AS INTEGER AS id\u trip, 将DBMS_RANDOM.VALUE 1100转换为整数作为驱动程序_标记 来自双重 按5级连接,然后将DBMS_RANDOM.VALUE 1,1000,2 END四舍五入 作为折扣, t、 身份证旅行 作为一次旅行 从双d 左连接选择id\U行程 从旅行 按DBMS_随机值t排序 ON 1=1;
您不需要PL/SQL。只需使用dbms_random.value和多表插入: