Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate test data using Oracle 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).

like image 498
eyettea Avatar asked Oct 16 '13 08:10

eyettea


People also ask

Is PL SQL used for testing?

The SQL Developer unit testing feature provides a framework for testing PL/SQL objects, such as functions and procedures, and monitoring the results of such objects over time. You create tests, and for each you provide information about what is to be tested and what result is expected.

How do I write a unit test case in PL SQL?

A SQL script to run the unit tests will be written in the same unit testing directory (e.g. Run-Initiator-UnitTests. sql) which first will clean up the unit testing table (line 1), invoke each of the unit test scripts (lines 3-6) in the directory and then display the PASSED or FAILED results (lines 8-16).


1 Answers

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.
like image 162
Colin 't Hart Avatar answered Sep 28 '22 07:09

Colin 't Hart