Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: PL/SQL question - number of rows inserted

Re: PL/SQL question - number of rows inserted

From: Bharat Bhushan Tripathi <bbt_at_CELTICS.TULNEPZ.UNISYS.COM>
Date: Mon Jan 29 04:09:47 1996
Message-Id: <9601290909.AA10946@alice.jcc.com>


At 12:13 PM 1/26/96 GMT, you wrote:
>PL/SQL question ...
>
>I have the following statement in a PL/SQL block
>
> INSERT INTO tablea
> SELECT * FROM tableb WHERE x=y;
>
>(or something very similar)
>
>This always succeeds no matter if the sub-select returns any rows or not.
>
>In my application inserting no rows is an error.
>
>How do I tell if there were any rows inserted (%ROWCOUNT is always 0,
SQLCODE is
>always 0)?
>
>I could always run a cursor like
>
> SELECT * FROM tableb WHERE x=y
> AND ROWNUM < 2;
>
>And if this returns nothing not bother with the INSERT (simply envoke somekind
> of error).
>However, what if the sub-select is
>
> SELECT x,y,z FROM bigtablea, bigtableb, bigtablec... WHERE EXISTS (SELECT
...)
> etc etc etc
>
>then the performance hit would be too great.
>
>I could always use a row insert trigger on tablea which sets a package global
> variable
>whenever a row is actually inserted into tablea and look at this after the
> insert has
>completed (remembering to clear it down before the INSERT) but this meeans
> writing a
>trigger and a package and all the maintenance and DBA bother that involves.
>
>Anybody got any better ideas?
>
>Tim Onions
>Principle Technical Consultant AT&T Istel (UK)
>
>

After the 'INSERT' statement, check SQL%NOTFOUND. In case no rows have been inserted SQL%NOTFOUND would be true. I don't know why Oracle doesn't raise NO DATA FOUND exception in this case.

HTH.



Bharat Bhushan Tripathi
Senior Software Engineer        Ph. (011-8)-562585, 562588-92
Tata Unisys Limited,            Fax. (011-8)-56584
Computer Consultancy Division, Tlx. 08905-211 TULN IN SDF#A/5-A/6,
Noida Export Processing Zone, Noida - 201 305 INDIA E-Mail. bbt_at_celtics.tulnepz.unisys.com
Received on Mon Jan 29 1996 - 04:09:47 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US