Generating Data: Increase a number by a random percentage

Suppose you want to create some test data in a table where a column value should increase by a random percentage each row.
For example, you wish to generate “sales” data for a month. For each day of the month you want to record how many sales orders are in the system. Since sales orders are always added, the number of sales orders will continually increase. On some days it will increase more than others. To reflect this variable growth, I came up with this solution.

The sales table then has two columns: sales_date and number_of_orders.

CREATE TABLE sales (sales_date DATE,number_of_orders NUMBER);

The following SQL can generate ever increasing values for the number_of_orders column for a period of n days. The SQL takes three arguments:

start_value – the number of sales orders you want to start out with

Num_days – the number of days for which you want to generate data

Start_date – the date from which you want to start generating data

max_growth_pct – the maximum percentage you want to allow the number of sales order to grow.

For each row in the result set, the number of sales orders generated will have increased by a random percentage (within the given range). The pct_increase column shows by what percentage each day the number of sales orders have grown.