Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 Oracle PL/SQL: Create test data Jump to:  
Category: >> Oracle PL/SQL >> Create test data Bookmark and Share

<< lastnext >>

Snippet Name: Create test data

Description: Instructions:

Copy the create table ddl into SQL/Plus.

Set the number of records you wish to create in the rec_num_var.

Copy the create procedure ddl into SQL/Plus.

In SQL/Plus type "exec datagen_proc" (without the quotes).

Comment: (none)

Language:
Highlight Mode: PLSQL
Last Modified: February 27th, 2009

 
CREATE TABLE table_x 
(id     NUMBER,
txt1      VARCHAR2(10),
date1     DATE,
num1     NUMBER);
 
 
CREATE OR REPLACE PROCEDURE datagen_proc AS
 
num_var          INTEGER;
txt_var          VARCHAR2(10);
date_var     DATE;
id_var           INTEGER;
i           INTEGER;
counter      INTEGER;
rec_num_var       INTEGER;
 
BEGIN
 
rec_num_var     := 100;          -- set the number of records you want
num_var          := 9;
txt_var          := 'z';
date_var     := TO_DATE('01-JAN-2001');
id_var           := 0;
counter      := 1;
 
EXECUTE IMMEDIATE 'truncate table table_x';
 
FOR i IN 1.. rec_num_var          
 
LOOP
     counter := counter +1;
     id_var := id_var+1;
 
     SELECT DECODE (txt_var, 'z', 'a',
               'a', 'b',
               'b', 'c',
               'c', 'a', 'error')
     INTO txt_var
     FROM dual;
 
     SELECT DECODE (num_var, 9, 1,
               1, 2,
               2, 3,
               3, 1)
     INTO num_var
     FROM dual;
 
     SELECT DECODE (date_var, TO_DATE('01-JAN-2001'), TRUNC(SYSDATE),
               TRUNC(SYSDATE), TRUNC(SYSDATE)-1,
               TRUNC(SYSDATE)-1, TRUNC(SYSDATE)-2,
               TRUNC(SYSDATE)-2, TRUNC(SYSDATE))
     INTO date_var
     FROM dual;
 
 
     INSERT INTO table_x (id, txt1, num1, date1)
     VALUES (id_var, txt_var, num_var, date_var);
 
     IF      counter = 100
     THEN      
          COMMIT;
          counter := 0;
     ELSE     NULL;
     END IF;
 
END LOOP;
 
COMMIT;
 
END datagen_proc;
 


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 109 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?