Created
April 4, 2021 11:13
-
-
Save hemantkchitale/3c901c0513282084a3f6d37d3447538b to your computer and use it in GitHub Desktop.
Sample PL/SQL code to use dbms_application_info.set_session_longops to populate v$session_longops
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- see https://hemantoracledba.blogspot.com/2021/04/using-sessionlongops-view-with.html for a demo | |
DECLARE | |
rindex BINARY_INTEGER; | |
slno BINARY_INTEGER; | |
target_count number; | |
updated_count number; | |
product_row products%rowtype; | |
check_flag varchar2(8); | |
BEGIN | |
rindex := dbms_application_info.set_session_longops_nohint; | |
updated_count := 0; | |
select num_rows into target_count --- this is an approximation based on last updated statistics on the table | |
from user_tables | |
where table_name = 'PRODUCTS'; | |
-- begin the updates here | |
for product_row in (select product_id, product_name from products) | |
loop | |
-- validate_for_update is a function that checks if this product should get a new PRODUCT_ID | |
select validate_for_update(product_row.product_id, product_row.product_name) into check_flag from dual ; | |
if check_flag='OK' then | |
update products set product_id = product_id+10000 where product_id=product_row.product_id; | |
insert into update_run_log values (product_row.product_id,systimestamp); | |
updated_count := updated_count+1; | |
dbms_application_info.set_session_longops(rindex, | |
slno, | |
op_name=>'New_Product_IDs', | |
target=>0, -- default, not used by me | |
context=>0, -- default, not used by me | |
sofar=>updated_count, | |
totalwork=>target_count, | |
target_desc=>'Table : PRODUCTS', | |
units=>'rows'); | |
else | |
null; | |
end if; | |
end loop; | |
END; | |
/ | |
commit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is a demo of how you can use both DBMS_APPLICATION_INFO and V$SESSION_LONGOPS to enable monitoring of a (batch ?) job run.
The job is modified to include calls to DBMS_APPLICATION_INFO.SET_SESSION_LONGOPS.
The DBA can then monitor the job from V$SESSION_LONGOPS.
See https://hemantoracledba.blogspot.com/2021/04/using-sessionlongops-view-with.html for a demo