使用Oracle PL / SQL开发人员生成测试数据

时间:2020-12-18 23:45:55

I want to test some schemas and indexes, and I was wondering if there is a functionality in PL/SQL Developer that can generate test data (so I won't have to create sequences and loops to insert data in the tables).

我想测试一些模式和索引,我想知道PL / SQL Developer中是否有可以生成测试数据的功能(因此我不必创建序列和循环来在表中插入数据)。

1 个解决方案

#1


11  

Loops and PL/SQL aren't always necessary; this trick might be helpful:

循环和PL / SQL并不总是必要的;这个技巧可能会有所帮助:

insert into emp(id, name, salary)
select rownum, 'Employee ' || to_char(rownum), dbms_random.value(2, 9) * 1000
from dual
connect by level <= 100;

will generate 100 records, named Employee 1 through Employee 100 with random "round" salaries between 2000 and 9000.

将生成100条记录,名为Employee 1到Employee 100,随机“轮”工资在2000到9000之间。

The two main techniques are:

两种主要技术是:

  1. Use of connect by level <= n to generate n rows in a query on dual.
  2. 使用按级别<= n连接在双重查询中生成n行。
  3. Use of dbms_random package; there's also a very useful function dbms_random.string which can be used -- like its name suggests -- to generate random strings of a certain length containing certain characters.
  4. 使用dbms_random包;还有一个非常有用的函数dbms_random.string,可以像它的名字一样使用它来生成包含某些字符的特定长度的随机字符串。

#1


11  

Loops and PL/SQL aren't always necessary; this trick might be helpful:

循环和PL / SQL并不总是必要的;这个技巧可能会有所帮助:

insert into emp(id, name, salary)
select rownum, 'Employee ' || to_char(rownum), dbms_random.value(2, 9) * 1000
from dual
connect by level <= 100;

will generate 100 records, named Employee 1 through Employee 100 with random "round" salaries between 2000 and 9000.

将生成100条记录,名为Employee 1到Employee 100,随机“轮”工资在2000到9000之间。

The two main techniques are:

两种主要技术是:

  1. Use of connect by level <= n to generate n rows in a query on dual.
  2. 使用按级别<= n连接在双重查询中生成n行。
  3. Use of dbms_random package; there's also a very useful function dbms_random.string which can be used -- like its name suggests -- to generate random strings of a certain length containing certain characters.
  4. 使用dbms_random包;还有一个非常有用的函数dbms_random.string,可以像它的名字一样使用它来生成包含某些字符的特定长度的随机字符串。