Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Sql%rowcount return 1 but it should return 2

Shadow123Nov 25 2015 — edited Nov 25 2015

Oracle 10g

Hi Gurus

I was reading one of the question from PL/SQL challenge  website https://plsqlchallenge.oracle.com/pls/apex/f?p=10000:23:114157934581224::NO::: but unable to get the exact idea.

I appreciate if someone help me out to understand code.

Sample data

set serveroutput on
/
drop table plch_stuff;
/

CREATE TABLE plch_stuff (
   id   INTEGER PRIMARY KEY,
   nm   VARCHAR2 (5) UNIQUE)
/

create or replace procedure plch_insert (
   insert_row_in IN BOOLEAN DEFAULT TRUE)
IS
begin
   IF insert_row_in
   THEN
      INSERT INTO plch_stuff VALUES (1, 'Hat');
   END IF;
END;
/
begin
   plch_insert;
   UPDATE plch_stuff SET nm = 'Hat';
   dbms_output.put_line('Last Count='||SQL%ROWCOUNT);
END;

Result

Last Count=1

But as per my understanding , result =Last Count=2 because one sql%rowcount for insert and then one for update. Please guide. Thanks

Regards

Matt

This post has been answered by unknown-7404 on Nov 25 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 23 2015
Added on Nov 25 2015
1 comment
743 views