Generate test data using Oracle PL/SQL developer

笑着哭i 提交于 2019-12-18 17:04:45

问题


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).


回答1:


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;

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

The two main techniques are:

  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.


来源:https://stackoverflow.com/questions/19398787/generate-test-data-using-oracle-pl-sql-developer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!