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
Who is Participating?
Naveen KumarConnect With a Mentor Production Manager / Application Support ManagerCommented:
i mean just run a select statement against that view. something like this...

rr_type v$locked_object%rowtype;
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
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 ).
weegiraffeAuthor Commented:
hi nav_kum_v

Can you please provide a simple example of how to do this in PL/SQL block?
why do you want to check for updates before issuing a select?

updates don't block select?  It's perfectly safe to do so.
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?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.