使用 Oracle PL/SQL developer 生成测试数据
我想测试一些模式和索引,我想知道 PL/SQL Developer 中是否有可以生成测试数据的功能(这样我就不必创建序列和循环来在表中插入数据).
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 并不总是必要的;这个技巧可能会有所帮助:
Loops and PL/SQL aren't always necessary; this trick might be helpful:
insert into emp(id, name, salary)
select rownum, 'Employee ' || to_char(rownum), dbms_random.value(2, 9) * 1000
from dual
connect by level <= 100;
将生成 100 条记录,命名为 Employee 1 到 Employee 100,其工资在 2000 到 9000 之间是随机的.
will generate 100 records, named Employee 1 through Employee 100 with random "round" salaries between 2000 and 9000.
两种主要技术是:
- 使用
按级别连接 <= n
在对偶查询中生成 n 行. dbms_random
包的使用;还有一个非常有用的函数dbms_random.string
,它可以用来——顾名思义——生成包含某些字符的特定长度的随机字符串.
- Use of
connect by level <= n
to generate n rows in a query on dual. - Use of
dbms_random
package; there's also a very useful functiondbms_random.string
which can be used -- like its name suggests -- to generate random strings of a certain length containing certain characters.
相关文章