Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need a sql query- insert number,date

Status
Not open for further replies.

PeriyurParthi

IS-IT--Management
Jul 18, 2001
258
IN
i have a db with a field nunmber and date, i need to insert 100 records into it, with a number icnrement and date increment.. replies will be helpful
thanks
parthi
 
Hi,

Try something like this :

declare
fld1 number :=0; 'start value field1
inc_fld1 number :=5 ' increment for field1
fld2 date :=to_date('01/01/2003','DD/MM/YYYY'); 'start value field1
inc_fld2 number :=2 ' increment for field2
nb_rec number :=100; 'nb of insert

begin
for i in 1..nb_rec loop
insert into table1
values (fld1,fld2,...);

fld1 := fld1+inc_fld1;
fld2 := fld2+inc_fld2;
end loop;
commit;
end;
/
 
The only correction, is that -- or /**/ are used for COMMENTS in pl/sql.

Another way is to use all_objects as pivoting table (asuming you have an access to >100 objects):

insert into table1 (num_field, date_field)
select rownum, sysdate + rownum
from all_objects
where rownum<101 Regards, Dima
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top