• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 579
  • 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
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

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