使用 Oracle PL/SQL developer 生成测试数据 [英] Generate test data using Oracle PL/SQL developer

查看:35
本文介绍了使用 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.

两种主要技术是:

  1. 使用 按级别连接 <= n 在对偶查询中生成 n 行.
  2. dbms_random 包的使用;还有一个非常有用的函数dbms_random.string,它可以用来——顾名思义——生成包含某些字符的特定长度的随机字符串.
  1. Use of connect by level <= n to generate n rows in a query on dual.
  2. 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.

这篇关于使用 Oracle PL/SQL developer 生成测试数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆