Re: Increment at counter

From: FaheemRao <faheemrao_at_yahoo.com>
Date: 24 Oct 2001 17:54:44 -0700
Message-ID: <43b58913.0110241654.2f2c883c_at_posting.google.com>


[Quoted] Why dont you try to use Sequence Object.

Get the next value from the sequence object , by calling Sequence_name.nextval

and at the end you find Max from the that Column and that is the Number of rows you inserted.

regards
Faheem Rao

"Roel Toledo" <dontsendmailstome_at_bogusmail.com> wrote in message news:<8wDB7.81335$WW.4273465_at_bgtnsc05-news.ops.worldnet.att.net>...
> "Allan Martin" <allan.martin_at_saic.com> wrote in message
> news:3bd6837c_at_cpns1.saic.com...
> > Hi,
> > I'm trying to insert into a number variable the amount of
> > records that I insert into a table. ie. I want to increment the counter by
> > 1 every time a row is inserted. I'd then display the amount at the end.
> >
> > I have tried this over and over again and have even bought a book from
> > AMAZON to help me in the future.
> >
> > Does anyone know what to do as my book will take more that 20 days to
> arrive
> > from
> > America?
> >
> > I've got what I had in mind below.
> >
> > Thanks a lot,
> > Allan
> >
> > DECLARE
> >
> > v_counter NUMBER := 0;
> >
> > BEGIN
> >
> > insert into tbl1
> > (v1,
> > v2,
> > v3)
> > select distinct
> > v1,
> > v2,
> > v3
> > -- v_counter = v_counter + 1;
> > from theTable;
> >
> > commit;
> >
> > dbms_output.put_line('1. || v_counter || ' records inserted.');
> >
> > END;
>
>
>
> The quickest and best way to do it is by using SQL%ROWCOUNT as follows:
>
> DECLARE
> v_rows_inserted NUMBER := 0;
> BEGIN
> insert into tbl1
> (v1,
> v2,
> v3)
> select distinct
> v1,
> v2,
> v3
> from theTable;
> v_rows_inserted := SQL%ROWCOUNT;
> commit;
> dbms_output.put_line('1. || v_rows_inserted || ' records inserted.');
> END;
>
>
> Hth,
>
> Roel Toledo
Received on Thu Oct 25 2001 - 02:54:44 CEST

Original text of this message