Link to home
Start Free TrialLog in
Avatar of mahjag
mahjag

asked on

checking SQL%ROWCOUNT value in oracle 10 g (10.2.0)

when i was upgrading from 8i to 10g one of the packages had the code..

if SQL%ROWCOUNT = 0 then
    v_txt := v_program||': '||':  Tables Not Created. Check!!!!;

    RAISE_APPLICATION_ERROR(-20000,v_txt,TRUE);

END IF;

This failed while running in 10g database, I tried this
v_ins_row_count := SQL%ROWCOUNT;

IF v_ins_row_count = 0 THEN

    v_txt := v_program||': '||': Tables Not Created. Check!!!!';
    RAISE_APPLICATION_ERROR(-20000,v_txt,TRUE);

END IF;

This worked!! Do you guys know why, I dont want to change the code but looks like the current code always had sql%rowcount value as zero and it went to exception but the modified code did not..

Have you guys experienced this in 10g?
Avatar of sujit_kumar
sujit_kumar
Flag of United States of America image

have you tried "if SQL%ROWCOUNT <= 0 then"?
Avatar of Naveen Kumar
looks very strange to me because that should work and i have not heard or went thru any links saying it would not work in 10g...

it would be better if you post your full code and the errors/exceptions you are getting.
Avatar of mahjag
mahjag

ASKER

I tried SQL%ROWCOUNT < =0 and still see the same error..

I have insert statement

insert into mytableA
(col1,col2..)
(select col1,col2. from mytableB
)

if SQL%ROWCOUNT = 0 then
    v_txt := v_program||': '||':  Tables Not Created. Check!!!!;

    RAISE_APPLICATION_ERROR(-20000,v_txt,TRUE);

END IF;

that is all the code involved in this error.. let me know..
begin
insert into temp_table select * from testing1 ;
dbms_output.put_line('count:'||sql%rowcount);

if SQL%ROWCOUNT = 0 then
dbms_output.put_line('in exception');
    RAISE_APPLICATION_ERROR(-20000,'error defined by me',TRUE);

END IF;
end;
/

output is ( i have oracle express edition 10g ) :

count:3    ---> this shows me the number of records as 3 and no exception is raised
Statement processed.
0.03 secondsDBMS Output
 
i modified your code to the above because there is no ; after the insert 'insert into mytableA
(col1,col2..)
(select col1,col2. from mytableB
)' and this line i removed because it gave me error saying variable is not defined.

Let me know if you need any other help.

Thanks
Avatar of mahjag

ASKER

I just tried the same and it always worked if it is written as a test procedure with insert statement and sql%rowcount has a value, but inside a package same insert statement when you do sql%rowcount after the commit statement did not work ( meaning it gave zero as value)
not sure how this can be reproduced..
>when you do sql%rowcount after the commit statement did not work
which is "normal". the sql%rowcount needs to be first after the statement
Avatar of mahjag

ASKER

the same code was working fine in 8i not sure why this is not normal for 10g

8i code

insert statement
commit
if sql%rowcount = 0 then
--error statement
end if;
 
the same code when ported to 10g errored eventhough insert statement worked and the rows inserted to table is greater than zero..
I dont understand how it can work in 8i and not in 10g
ASKER CERTIFIED SOLUTION
Avatar of Naveen Kumar
Naveen Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial