Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 576
  • Last Modified:

Throw exception if there are pending updates

Is it possible to create and SQL block that will execute a SELECT only if there are no an uncommitted updates pending.

Ideally I would like to throw an exception if there are pending updates.  Any suggestions
0
weegiraffe
Asked:
weegiraffe
1 Solution
 
Naveen KumarProduction Manager / Application Support ManagerCommented:
you can check V$LOCKED_OBJECT or V$LOCK accordingly to check whether there are any locks on the tables ( which are being updated/deleted ).
0
 
weegiraffeAuthor Commented:
hi nav_kum_v

Can you please provide a simple example of how to do this in PL/SQL block?
0
 
Naveen KumarProduction Manager / Application Support ManagerCommented:
i mean just run a select statement against that view. something like this...

declare
rr_type v$locked_object%rowtype;
begin
select  * into rr_type from v$locked_object where object_id = ( select object_id from dba_objects
where object_name='MY_TEST_TABLE' ) and rownum = 1;

-- lock found
-- do something else here...may be log into error/debug table or thrown an exception/error message.

exception when no_data_found then
    -- no locks
    null;    
end;
/
0
 
sdstuberCommented:
why do you want to check for updates before issuing a select?

updates don't block select?  It's perfectly safe to do so.
0
 
johnsoneSenior Oracle DBACommented:
Rather than checking a V$ view, why not just do a SELECT ... FOR UPDATE NOWAIT.  That should error out if it cannot lock all the rows.

However, I do agree with sdstuber, as the locks would not block a select, why do you need to check?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now