Pages

Thursday, November 3, 2011

Insert data in to a table by using simple FOR loop.....

Recently i had to insert several number of data rows to database table related to my oracle form( For the testing purpose). There's few constrains in that particular table. Before insert data, i have to concern about those constraints. Because my insertion can violate those constraints.  I disabled relevant constraints according to my data insertion and run simple FOR LOOP mentioned below.

BEGIN
    FOR v_LoopCounter IN 1..120 LOOP
        INSERT INTO TABLE_NAME  (col1,col2,col3,col4,col5,col6,col7,col8,col9,col10,col11,col12,col13,
         col14,col15,col16,col17,col18,col19,col20,col21,col22,col23,co24,co25)
        VALUES ('TESTU'||v_LoopCounter,'test'||v_LoopCounter,'94',null,null,null,null,null,      null,null,null,null,null,null,null,'1','Y','val',sysdate,'val1',sysdate,null,
       'E',null,'N');
    END LOOP;
END;


This is very simple sql code for insert several data rows to a table. Nyway you can use any number you want for counter. It depends on the number of data rows you want to insert to your table. This is more suitable for testing purpose. Because it's really hard to edit each and every column value in each insertion. But for the simple testing purpose you can edit unique fields by adding loop counter as a part of that field value.

No comments:

Post a Comment