Autonomous Transactions and table locks
Does a commit statement in an Autonomous Transaction block in PL/SQL release locks aquired in the master transaction block?
e.g
CREATE OR REPLACE PACKAGE test_auto_trans AS
PROCEDURE mainproc;
PROCEDURE testproc;
END test_auto_trans;
CREATE OR REPLACE PACKAGE BODY test_auto_trans AS
/*****************Main Procedure*********************/
PROCEDURE mainproc AS
BEGIN
LOCK TABLE a,b,c IN EXCLUSIVE MODE nowait;
/*some processing involving tables a,b,c here. no commit done yet*/
testproc();
/* will the locks on a,b,c still be available here? */
EXCEPTION
WHEN others THEN
dbms_output.put_line('Error');
dbms_output.put_line(sqlcode);
dbms_output.put_line(sqlerrm);
RAISE;
END mainproc;
/*****************test Procedure*********************/
PROCEDURE testproc AS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
/*some processing using tables a,b,c here*/
commit;
EXCEPTION
WHEN others THEN
dbms_output.put_line('Error');
dbms_output.put_line(sqlcode);
dbms_output.put_line(sqlerrm);
RAISE;
END testproc;
END test_auto_trans;
/
No transaction will release the locks held by another transaction. When you declare a stored proc to be PRAGMA AUTONOMOUS_TRANSACTION, it is essentially the same as if you logged in as the same user but in a different session.
For example, if I have two sqlplus sessions running as user a, if I do an update in session1 and a delete and commit in session 2 I can still rollback in session 1.
However, your psuedo code as posted will not work at all since the call to test_proc will block until you commit in the main proc, and since test_proc will never return, the main proc will never get to commit. It is exactly analogous to the following:
session1> SELECT * FROM t;
ID DESCR
1 One
2 Two
session1> LOCK TABLE t IN EXCLUSIVE MODE nowait;
Table(s) Locked.
session1> UPDATE t SET descr = 'Un'
2 WHERE id = 1;
1 row updated.so far, this is your main proc. Now, in another session (which is equivalent to your autonomous transaction procedure), I do:
session2> UPDATE t SET descr = 'Deux'
2 WHERE id = 2;which as I type is still waiting on the commit from session 1. Therefore, I cannot get to commit the autonomous transaction which would return control to session1
HTH
John
Message was edited by:
John Spencer
Sorry, I initially forgot to answer your actual question "what about DML statements like truncate". Since TRUNCATE is actually a DDL statement I will assume that is what you meant. My initial answer covers DML statements (except SELECT which will work).
All DDL statements in Oracle go
COMMIT
DDL statement
COMMIT
since the initial commit requires a very brief exclusive lock, you will get an error like:
ORA-00054: resource busy and acquire with NOWAIT specified
Exactly as if you did:
session1> LOCK TABLE t IN EXCLUSIVE MODE nowait;
Table(s) Locked.then tried to do it again the another session
session2> LOCK TABLE t IN EXCLUSIVE MODE nowait;
LOCK TABLE t IN EXCLUSIVE MODE nowait
ERROR at line 1:
ORA-00054: resource busy and acquire with NOWAIT specified
Similar Messages
-
Transactions and database locks
Hi,
We use Weblogic 4.5.1 on Windows NT 4.0 with Oracle 8.0.5. Our database
isolation is set to TRANSACTION_READ_COMMITTED. I have an entity bean with
TX_REQUIRED & TRANSACTION_READ_COMMITTED settings. If my client creates a
transaction, and starts calling methods on this entity bean, is the
corresponding database row locked for the duration of the transaction? We
have concurrent SQl-plus sessions going on and we want make sure there is
no data corruption. If the row is not locked, is it ok for me to explicitly
lock it from inside my entity bean?
Thanks,
Srini.
Hi. This should have been posted to the EJB or JDBC group, but I'll take it.
This is an Oracle question. If you have a transaction as you've described,
then the behavior will be exactly as if you had multiple SQL-PLUS sessions,
and in one of them, you did:
SQL> BEGIN;
-- do what your bean would do;
SQL> COMMIT;
You can test this there. In general, you'll find that Oracle's optimistic locking
will allow any number of simutaneous transactions to access a given row
at one time. Oracle does not lock the real data while a transaction is ongoing,
instead making a copy for the client to work off of. At commit time, depending
on the isolation level semantics, some or all of the transactions may fail when
Oracle tries to update the real data from the per-session private data.
I would council against running with SERIALIZABLE mode because there
is a serious bug in Oracle, where serializable transactions may fail silently.
Details on request.
Joe
Srini wrote:
> Hi,
> We use Weblogic 4.5.1 on Windows NT 4.0 with Oracle 8.0.5. Our database
> isolation is set to TRANSACTION_READ_COMMITTED. I have an entity bean with
> TX_REQUIRED & TRANSACTION_READ_COMMITTED settings. If my client creates a
> transaction, and starts calling methods on this entity bean, is the
> corresponding database row locked for the duration of the transaction? We
> have concurrent SQl-plus sessions going on and we want make sure there is
> no data corruption. If the row is not locked, is it ok for me to explicitly
> lock it from inside my entity bean?
>
> Thanks,
> Srini.
PS: Folks: BEA WebLogic is in S.F., and now has some entry-level positions for
people who want to work with Java and E-Commerce infrastructure products. Send
resumes to [email protected]
The Weblogic Application Server from BEA
JavaWorld Editor's Choice Award: Best Web Application Server
Java Developer's Journal Editor's Choice Award: Best Web Application Server
Crossroads A-List Award: Rapid Application Development Tools for Java
Intelligent Enterprise RealWare: Best Application Using a Component Architecture
http://weblogic.beasys.com/press/awards/index.htm
-
Transaction and table craeting.
Hi all,
I am using Oracle 8i and java as client.
How can I use transaction with table creating( for temp. tables).
For exmple:
1. insert into someTable ...
2. create GLOBAL TEMPORARY table myTable ....
3. insert into myTable select ....
4. update anotherTable set .....
5. Truncate myTable.
6. Drop myTable
7. On condition : ROLLBACK.
By making rollback, the system do not make rollback on step 1.
Can I do this with oracle and how.
Many thanks in advance.Hi ,
Thanks for the information.
It was helpful.I could see that for VBELN of VBAK table the ROLLNAME is VBELN_VA.
When I queried DD04T for VBELN_VA ,it gives me the DDTEXT for it as 'Sales Document'.
However, if on VA03 the same field is displayed with label Standard Order.
My requirement is how to find relation between a table field(VBELN)or DDTEXT(Sales Document) and the label displayed(STANDARD ORDER) on a transaction screen.
The two may be different. This is just one instance.
I need to derive a generalised solution for all transcations not just VA03.
Being a Java programmer, I have limited knowledge of SAP.
Hence, it would be great help if you could suggest some standard RFC or some table that stores this information so that it can be retrieved from java layer and not SAP GUI.
Regards,
MNGhosh
Edited by: MNGhosh on Sep 15, 2009 8:47 AM -
FOREIGN KEY Constraint And Table Lock
According to Db Concepts on Data Integrity->Types of Integrity Contraints->Referential Integrity Constraints, if the FK column is not indexed, delete/update of parent table would cause child table share locked.
I can understand the reason behind this behaviour because if parent's PK is modified but not commited yet, we don't want another transaction to insert/update the child's FK column to use the deleted parent PK value and this requires a table share lock.
The problem is, I don't understand why if the child's FK is indexed, no table share lock is acquired. The same condition could happen and we still need to prevent another transaction from using the uncommitted deleted PK in parent as the child's FK.
Appreciate and advice.hi
When PK column change, Oracle is going to have to do a
referential integrity check on any referenced columns ,in
the absence of an index on the child end of the foreign
key, that would seem to result in a full table scan of the table which cause locks the entire table for any
Delete or Update on Parent table.
Khurram -
Re: Transactions and Locking Rows for Update
Dale,
Sounds like you either need an "optimistic locking" scheme, usually
implemented with timestamps at the database level, or a concurrency manager.
A concurrency manager registers objects that may be of interest to multiple
users in a central location. It takes care of notifying interested parties
(i.e., clients,) of changes made to those objects, using a "notifier" pattern.
The optimistic locking scheme is relatively easy to implement at the
database level, but introduces several problems. One problem is that the
first person to save their changes "wins" - every one else has to discard
their changes. Also, you now have business policy effectively embedded in
the database.
The concurrency manager is much more flexible, and keeps the policy where
it probably belongs. However, it is more complex, and there are some
implications to performance when you get to the multiple-thousand-user
range because of its event-based nature.
Another pattern of lock management that has been implemented is a
"key-based" lock manager that does not use events, and may be more
effective at managing this type of concurrency for large numbers of users.
There are too many details to go into here, but I may be able to give you
more ideas in a separate note, if you want.
Don
At 04:48 PM 6/5/97 PDT, Dale "V." Georg wrote:
I have a problem in the application I am currently working on, which it
seems to me should be easily solvable via appropriate use of transactions
and database locking, but I'm having trouble figuring out exactly how to
do it. The database we are using is Oracle 7.2.
The scenario is as follows: We have a window where the user picks an
object from a dropdown list. Some of the object's attributes are then
displayed in that window, and the user then has the option of editing
those attributes, and at some point hitting the equivalent of a 'save'button
to write the changes back to the database. So far, so good. Now
introduce a second user. If user #1 and user #2 both happen to pull up
the same object and start making changes to it, user #1 could write back
to the database and then 15 seconds later user #2 could write back to the
database, completely overlaying user #1's changes without ever knowing
they had happened. This is not good, particularly for our application
where editing the object causes it to progress from one state to the next,
and multiple users trying to edit it at the same time spells disaster.
The first thing that came to mind was to do a select with intent to update,
i.e. 'select * from table where key = 'somevalue' with update'. This way
the next user to try to select from the table using the same key would not
be able to get it. This would prevent multiple users from being able to
pull the same object up on their screens at the same time. Unfortunately,
I can think of a number of problems with this approach.
For one thing, the lock is only held for the duration of the transaction, so
I would have to open a Forte transaction, do the select with intent to
update, let the user modify the object, then when they saved it back again
end the transaction. Since a window is driven by the event loop I can't
think of any way to start a transaction, let the user interact with the
window, then end the transaction, short of closing and re-opening the
window. This would imply having a separate window specifically for
updating the object, and then wrapping the whole of that window's event
loop in a transaction. This would be a different interface than we wanted
to present to the users, but it might still work if not for the next issue.
The second problem is that we are using a pooled DBSession approach
to connecting to the database. There is a single Oracle login account
which none of the users know the password to, and thus the users
simply share DBSession resources. If one user starts a transaction
and does a select with intent to update on one DBSession, then another
user starts a transaction and tries to do the same thing on the same
DBSession, then the second user will get an error out of Oracle because
there's already an open transaction on that DBSession.
At this point, I am still tossing ideas around in my head, but after
speaking with our Oracle/Forte admin here, we came to the conclusion
that somebody must have had to address these issues before, so I
thought I'd toss it out and see what came back.
Thanks in advance for any ideas!
Dale V. Georg
Indus Consultancy Services [email protected]
Mack Trucks, Inc. [email protected]
>
>
>
>
====================================
Don Nelson
Senior Consultant
Forte Software, Inc.
Denver, CO
Corporate voice mail: 510-986-3810
aka: [email protected]
====================================
"I think nighttime is dark so you can imagine your fears with less
distraction." - CalvinWe have taken an optimistic data locking approach. Retrieved values are
stored as initial values; changes are stored seperately. During update, key
value(s) or the entire retieved set is used in a where criteria to validate
that the data set is still in the initial state. This allows good decoupling
of the data access layer. However, optimistic locking allows multiple users
to access the same data set at the same time, but then only one can save
changes, the rest would get an error message that the data had changed. We
haven't had any need to use a pessimistic lock.
Pessimistic locking usually involves some form of open session or DBMS level
lock, which we haven't implemented for performance reasons. If we do find the
need for a pessimistic lock, we will probably use cached data sets that are
checked first, and returned as read-only if already in the cache.
-DFR
Dale V. Georg <[email protected]> on 06/05/97 03:25:02 PM
To: Forte User Group <[email protected]> @ INTERNET
cc: Richards* Debbie <[email protected]> @ INTERNET, Gardner*
Steve <[email protected]> @ INTERNET
Subject: Transactions and Locking Rows for Update
I have a problem in the application I am currently working on, which it
seems to me should be easily solvable via appropriate use of transactions
and database locking, but I'm having trouble figuring out exactly how to
do it. The database we are using is Oracle 7.2.
The scenario is as follows: We have a window where the user picks an
object from a dropdown list. Some of the object's attributes are then
displayed in that window, and the user then has the option of editing
those attributes, and at some point hitting the equivalent of a 'save' button
to write the changes back to the database. So far, so good. Now
introduce a second user. If user #1 and user #2 both happen to pull up
the same object and start making changes to it, user #1 could write back
to the database and then 15 seconds later user #2 could write back to the
database, completely overlaying user #1's changes without ever knowing
they had happened. This is not good, particularly for our application
where editing the object causes it to progress from one state to the next,
and multiple users trying to edit it at the same time spells disaster.
The first thing that came to mind was to do a select with intent to update,
i.e. 'select * from table where key = 'somevalue' with update'. This way
the next user to try to select from the table using the same key would not
be able to get it. This would prevent multiple users from being able to
pull the same object up on their screens at the same time. Unfortunately,
I can think of a number of problems with this approach.
For one thing, the lock is only held for the duration of the transaction, so
I would have to open a Forte transaction, do the select with intent to
update, let the user modify the object, then when they saved it back again
end the transaction. Since a window is driven by the event loop I can't
think of any way to start a transaction, let the user interact with the
window, then end the transaction, short of closing and re-opening the
window. This would imply having a separate window specifically for
updating the object, and then wrapping the whole of that window's event
loop in a transaction. This would be a different interface than we wanted
to present to the users, but it might still work if not for the next issue.
The second problem is that we are using a pooled DBSession approach
to connecting to the database. There is a single Oracle login account
which none of the users know the password to, and thus the users
simply share DBSession resources. If one user starts a transaction
and does a select with intent to update on one DBSession, then another
user starts a transaction and tries to do the same thing on the same
DBSession, then the second user will get an error out of Oracle because
there's already an open transaction on that DBSession.
At this point, I am still tossing ideas around in my head, but after
speaking with our Oracle/Forte admin here, we came to the conclusion
that somebody must have had to address these issues before, so I
thought I'd toss it out and see what came back.
Thanks in advance for
any
ideas!
Dale V. Georg
Indus Consultancy Services [email protected]
Mack Trucks, Inc. [email protected]
------ Message Header Follows ------
Received: from pebble.Sagesoln.com by notes.bsginc.com
(PostalUnion/SMTP(tm) v2.1.9c for Windows NT(tm))
id AA-1997Jun05.162418.1771.334203; Thu, 05 Jun 1997 16:24:19 -0500
Received: (from sync@localhost) by pebble.Sagesoln.com (8.6.10/8.6.9) id
NAA11825 for forte-users-outgoing; Thu, 5 Jun 1997 13:47:58 -0700
Received: (from uucp@localhost) by pebble.Sagesoln.com (8.6.10/8.6.9) id
NAA11819 for <[email protected]>; Thu, 5 Jun 1997 13:47:56 -0700
Received: from unknown(207.159.84.4) by pebble.sagesoln.com via smap (V1.3)
id sma011817; Thu Jun 5 13:47:43 1997
Received: from tes0001.macktrucks.com by relay.macktrucks.com
via smtpd (for pebble.sagesoln.com [206.80.24.108]) with SMTP; 5 Jun
1997 19:35:31 UT
Received: from dale by tes0001.macktrucks.com (SMI-8.6/SMI-SVR4)
id QAA04637; Thu, 5 Jun 1997 16:45:51 -0400
Message-ID: <[email protected]>
Priority: Normal
To: Forte User Group <[email protected]>
Cc: "Richards," Debbie <[email protected]>,
"Gardner," Steve <[email protected]>
MIME-Version: 1.0
From: Dale "V." Georg <[email protected]>
Subject: Transactions and Locking Rows for Update
Date: Thu, 05 Jun 97 16:48:37 PDT
Content-Type: text/plain; charset=US-ASCII; X-MAPIextension=".TXT"
Content-Transfer-Encoding: quoted-printable
Sender: [email protected]
Precedence: bulk
Reply-To: Dale "V." Georg <[email protected]> -
Transactions and Locking Rows for Update
I have a problem in the application I am currently working on, which it
seems to me should be easily solvable via appropriate use of transactions
and database locking, but I'm having trouble figuring out exactly how to
do it. The database we are using is Oracle 7.2.
The scenario is as follows: We have a window where the user picks an
object from a dropdown list. Some of the object's attributes are then
displayed in that window, and the user then has the option of editing
those attributes, and at some point hitting the equivalent of a 'save' button
to write the changes back to the database. So far, so good. Now
introduce a second user. If user #1 and user #2 both happen to pull up
the same object and start making changes to it, user #1 could write back
to the database and then 15 seconds later user #2 could write back to the
database, completely overlaying user #1's changes without ever knowing
they had happened. This is not good, particularly for our application
where editing the object causes it to progress from one state to the next,
and multiple users trying to edit it at the same time spells disaster.
The first thing that came to mind was to do a select with intent to update,
i.e. 'select * from table where key = 'somevalue' with update'. This way
the next user to try to select from the table using the same key would not
be able to get it. This would prevent multiple users from being able to
pull the same object up on their screens at the same time. Unfortunately,
I can think of a number of problems with this approach.
For one thing, the lock is only held for the duration of the transaction, so
I would have to open a Forte transaction, do the select with intent to
update, let the user modify the object, then when they saved it back again
end the transaction. Since a window is driven by the event loop I can't
think of any way to start a transaction, let the user interact with the
window, then end the transaction, short of closing and re-opening the
window. This would imply having a separate window specifically for
updating the object, and then wrapping the whole of that window's event
loop in a transaction. This would be a different interface than we wanted
to present to the users, but it might still work if not for the next issue.
The second problem is that we are using a pooled DBSession approach
to connecting to the database. There is a single Oracle login account
which none of the users know the password to, and thus the users
simply share DBSession resources. If one user starts a transaction
and does a select with intent to update on one DBSession, then another
user starts a transaction and tries to do the same thing on the same
DBSession, then the second user will get an error out of Oracle because
there's already an open transaction on that DBSession.
At this point, I am still tossing ideas around in my head, but after
speaking with our Oracle/Forte admin here, we came to the conclusion
that somebody must have had to address these issues before, so I
thought I'd toss it out and see what came back.
Thanks in advance for any ideas!
Dale V. Georg
Indus Consultancy Services [email protected]
Mack Trucks, Inc. [email protected]
[email protected]------------------I have a problem in the application I am currently working on, which it
seems to me should be easily solvable via appropriate use of transactions
and database locking, but I'm having trouble figuring out exactly how to
do it. The database we are using is Oracle 7.2.
The scenario is as follows: We have a window where the user picks an
object from a dropdown list. Some of the object's attributes are then
displayed in that window, and the user then has the option of editing
those attributes, and at some point hitting the equivalent of a 'save' button
to write the changes back to the database. So far, so good. Now
introduce a second user. If user #1 and user #2 both happen to pull up
the same object and start making changes to it, user #1 could write back
to the database and then 15 seconds later user #2 could write back to the
database, completely overlaying user #1's changes without ever knowing
they had happened. This is not good, particularly for our application
where editing the object causes it to progress from one state to the next,
and multiple users trying to edit it at the same time spells disaster.
The first thing that came to mind was to do a select with intent to update,
i.e. 'select * from table where key = 'somevalue' with update'. This way
the next user to try to select from the table using the same key would not
be able to get it. This would prevent multiple users from being able to
pull the same object up on their screens at the same time. Unfortunately,
I can think of a number of problems with this approach.
For one thing, the lock is only held for the duration of the transaction, so
I would have to open a Forte transaction, do the select with intent to
update, let the user modify the object, then when they saved it back again
end the transaction. Since a window is driven by the event loop I can't
think of any way to start a transaction, let the user interact with the
window, then end the transaction, short of closing and re-opening the
window. This would imply having a separate window specifically for
updating the object, and then wrapping the whole of that window's event
loop in a transaction. This would be a different interface than we wanted
to present to the users, but it might still work if not for the next issue.
The second problem is that we are using a pooled DBSession approach
to connecting to the database. There is a single Oracle login account
which none of the users know the password to, and thus the users
simply share DBSession resources. If one user starts a transaction
and does a select with intent to update on one DBSession, then another
user starts a transaction and tries to do the same thing on the same
DBSession, then the second user will get an error out of Oracle because
there's already an open transaction on that DBSession.
At this point, I am still tossing ideas around in my head, but after
speaking with our Oracle/Forte admin here, we came to the conclusion
that somebody must have had to address these issues before, so I
thought I'd toss it out and see what came back.
Thanks in advance for any ideas!
Dale V. Georg
Indus Consultancy Services [email protected]
Mack Trucks, Inc. [email protected]
[email protected]------------------ -
Autonomous transaction - user updating information through form
Good afternoon,
I have a form that has a database datablock that is populated using a cursor that does a select on 4 tables, being one the most important (table A). When the user is done he commits the changes and the information is saved in table B, the "source" of the datablock.
This generates a concurrency problem: if two users give the same parameters the cursor populates the same information in their respective sessions and the information is saved twice. I want to prevent this, only one person should be allowed to use the information.
I know about autonomous transactions and perhaps this is the best idea: update the status of the row in table A in order to prevent any further uses but i want to check any other solution. Perhaps i could write the user and the time and the second person would get a message: "being used by"
Thanks,Yes i too have read about autonomous transaction and its very rare usability.
Ok here's the situation:
Table B
code_B (number) PK
code_B1 (number PK
description
selected (Y/N), default N
more fields...
Table A
code_A PK
description
code_B NOT part of PK_A
code_B1 NOT part of PK_A
more fields
step 1: user opens form X and marks some records from table B, setting selected to Y
step 2: User open forms Y and populates block Z (table A) based on a cursor (PL/sql run through a push button) that looks for all the records from B that have selected = Y
step 3: user commits and the form updates table A with new records
this is the normal procedure but sometimes two users open form Y at almost the same time and the both populate the datablock Z with the same info.
I have thought about creating a new hidden datablock in form Y that uses table B, in order to block other users.
and these forms have been like this for years now, i did not create them and the tables have millions of records now...
This was a design flaw, not taking concurrency into account i guess
Many thanks
Edited by: user474437 on Apr 17, 2010 10:38 AM -
Pipeline function raised ORA-06519: active autonomous transaction detected
Hi All,
My name is John and I've got a problem which I need to share with all of you guru and experts. I've created the following pipeline function under the Oracle user ABC:
CREATE OR replace FUNCTION SomeFunction(p_from_date DATE, p_to_date DATE) RETURN T_TAB_A pipelined
IS
PRAGMA autonomous_transaction;
BEGIN
DELETE FROM temp_rcm;
INSERT INTO temp_rcm
SELECT * FROM int.facility fd,
int.capacity co
WHERE co.resource_name = fd.resource_name
AND co.trade_date = fd.trade_date
AND co.trade_date BETWEEN p_from_date AND p_to_date;
COMMIT;
FOR rec IN (SELECT co.*
FROM temp_rcm co
left join int.outage o
ON ( o.flag = 'Y'
AND o.reason_flag = 'F'
AND o.INTERVAL = co.INTERVAL
AND co.resource_name = o.resource_name )
ORDER BY co.INTERVAL,
co.name) LOOP
pipe ROW (T_A( rec.INTERVAL, rec.trade_date,
rec.resource_name,rec.day_of_week_long, rec.working_day, rec.peak));
END LOOP;
RETURN;
END SomeFunction;
I was able to compile and create the SomeFunction function successfully but when I executed it using the following command:
select * from table(SomeFunction(to_date('01/01/2010',to_date('01/01/2010')));
I was returned with the Oracle error - ORA-06519: active autonomous transaction detected and rolled back
I have searched through the web, such Oracle error occurs whenever the function has a missing 'COMMIT' or 'ROLLBACK' command inside an autonomous_transaction. But the fact is I have already included the 'COMMIT;' in the function. I suspected that the error was caused by the tables which I queried against (like int.facility and int.capacity) were all views that belonged to another schema called int. Or is that something that I miss in the function? Thank you for your time and assistance.
Regards,
Johnjohnwanng wrote:
Hi Guys,
Thank you for all your feedback. In addition to your reply, Bill, can you spare some time and provide us a simple example of the steps involved to implement the 'correct' implementation based on the queries that I've used. As I do not understand your vanilla approach. Much appreciated and thank you for the time again.
Regards,
JohnIf I had to guess, Billy may have meant something like this (untested):
CREATE OR REPLACE FUNCTION SomeFunction
( p_from_date IN int.facility.trade_date%TYPE
, p_to_date IN int.facility.trade_date%TYPE
RETURN SYS_REFCURSOR
AS
rcur SYS_REFCURSOR;
BEGIN
OPEN rcur FOR
SELECT co.interval
, co.trade_date
, co.resource_name
, co.day_of_week_long
, co.working_day
, co.peak
FROM int.capacity co
JOIN int.facility fd ON fd.resource_name = co.resource_name
AND fd.trade_date = co.trade_date
LEFT OUTER JOIN int.outage o ON o.interval = co.interval
AND o.resource_name = co.resource_name
WHERE co.trade_date BETWEEN p_from_date AND p_to_date
AND o.reason_flag = 'F'
AND o.flag = 'Y'
ORDER BY co.interval
, co.name
RETURN rcur;
END;
/I made the following modifications:
1. I set the input parameter data types to match that of the table column you are checking against. A good practice to get into.
2. Removed the autonomous transaction and inserting into a temp table. In Oracle it's a good practice to perform everything in a single SQL statement if possible.
3. Changed the return data type to a SYS_REFCURSOR
Hope this helps and provides a good example. -
Disk space transaction and temp table lock in oracle
Hi,
Today many sessions used to get disk space transaction lock and temp table lock and i am seeing these locks first time in my Production database,
is there any workaround to avoid this contension.
Thanks
Prakash GRPost your version (all 3 decimal places).
Post the SELECT statement and results that have led you to this conclusion.
Other than the fact that you have seen a number what, precisely, is the issue. -
Ora 02290 when using qms_transaction_mgt and autonomous transactions
Hi all,
I'm using the qms procedures:
qms_transaction_mgt for openeing and closing transactions.
Somewhere in my procedure when the transaction is opened i call another procedure which contains a autonomous transaction.
The next time qms_transaction_mgt.close_transaction is called i get an ORA-02290: check constraint (HST65.QMS_NEED_TO_CLOSE_TRANSACTION) violated
When i debug the qms_transaction_mgt.close transaction the g_current_trans_id variable is empty, which indicates the transaction is allready closed.
When i remove the pragma autonomous_transaction statement and the commit statement from the procedure i call, the problem is resolved.
Version information:
Designer 9.0.2 with a with a Oracle 9i 9.2 database and Headstart 9i.
Does anybody know how i can resolve this or if this is a bug and how to fix it?
Thanks,
YvonIan, Yvon,
It is unfortunately a know restriction that the CDM RuleFrame component of both Headstart for Designer 6i and Headstart for Designer 9i doesn't work in combination with autonomous transactions.
The reason is that the RuleFrame administration relies on information stored in 1. pl/sql package variables and 2. database tables. Using autonomous transactions (that involve CDM RuleFramed DML) causes this information to dissynchronize.
A year ago I investigated the possibilities to make autonomous transactions possible with RuleFrame but unfortunately this is fundamental problem: RuleFrame wants to combine multiple DML-actions into one logical transaction (gards this with the "need_to_close_transaction" constraint), while autonomous transactions intend to to the opposite: commit a part of a transaction while the rest of the transaction still is posted/not committed.
There is one exception: if you call an atonomous procedure that does DML on a non-ruleframe-enabled table (no TAPI triggers that intend to open/close the transaction, no CAPI etc), everything functions.
Problem explanation:
====================
1. Outer transaction is opened (by front end or TAPI triggers of first DML)
2. DML takes place
3. Autonomous transaction-procedure is called
4. Auto-transaction again tries (and succeeds!) to open the transaction, it doesn't see that the transaction is opened (db table qms_transactions is empty for the autonomous transaction on query)
5. DML within auto-transaction is posted
6. Auto-transaction closes transaction
7. Auto-transaction is committed
8. Outer transaction thinks the transaction is already closed, because the auto-transaction cleaned out the package variables when it closed the transaction.
9. Commit of the outer transaction fails as the deferred check constraint need_to_close_transaction avoids this to happen (rollback takes place because of this violation).
Hope this helps
Kind Regards
Marc Vahsen
Headstart Team Oracle NL -
Identifying deadlocked resources in graph with 1 row lock and 1 table lock
Hi, I have run into repeated occurrences of the deadlock graph at the bottom of this post and have a few questions about it:
1. It appears that proc 44, session 548 is holding a row lock (X). Is the waiter, proc 30, session 542, trying to acquire a row lock (X) also or an exclusive table lock (X) on the table containing that row?
2. Under what circumstances would something hold a row exclusive table lock (SX) and want to upgrade that to a share row exclusive table lock (SSX)?
3. Our table cxml_foldercontent has a column 'structuredDataId' with a FK to cxml_structureddata.id and an ON DELETE SET NULL trigger. Would this help explain why an "update" to one table (i.e.g cxml_foldercontent) would also need to acquire a lock in a foreign table, cxml_structureddata?
4. What is the difference between "Current SQL statement:" and "Current SQL statement for this session:"? That terminology is confusing. Is session 542 executing the "update" or the "delete"?
5. In the "Rows waited on:" section is it saying that Session 542 is waiting on on obj - rowid = 0000BE63 - AAAL5jAAGAAA6tZAAK or that it is has the lock on that row and other things are waiting on it?
A couple of notes:
- the cxml_foldercontent.structuredDataId FK column has an index on it already
Deadlock graph:
---------Blocker(s)-------- ---------Waiter(s)---------
Resource Name process session holds waits process session holds waits
TX-003a0011-000003d0 44 548 X 30 542 X
TM-0000be63-00000000 30 542 SX 44 548 SX SSX
session 548: DID 0001-002C-000002D9 session 542: DID 0001-001E-00000050
session 542: DID 0001-001E-00000050 session 548: DID 0001-002C-000002D9
Rows waited on:
Session 542: obj - rowid = 0000BE63 - AAAL5jAAGAAA6tZAAK
(dictionary objn - 48739, file - 6, block - 240473, slot - 10)
Session 548: no row
Information on the OTHER waiting sessions:
Session 542:
pid=30 serial=63708 audsid=143708731 user: 41/CASCADE
O/S info: user: cascade, term: unknown, ospid: 1234, machine:
program: JDBC Thin Client
application name: JDBC Thin Client, hash value=2546894660
Current SQL Statement:
update cascade.cxml_foldercontent set name=:1 , lockId=:2 , isCurrentVersion=:3 , versionDate=:4 , metadataId=:5 , permissionsId=:6 , workflowId=:7 , isWorkingCopy=:8 , parentFolderId=:9 , relativeOrder=:10 , cachePath=:11 , isRecycled=:12 , recycleRecordId=:13 , workflowComment=:14 , draftUserId=:15 , siteId=:16 , prevVersionId=:17 , nextVersionId=:18 , originalCopyId=:19 , workingCopyId=:20 , displayName=:21 , title=:22 , summary=:23 , teaser=:24 , keywords=:25 , description=:26 , author=:27 , startDate=:28 , endDate=:29 , reviewDate=:30 , metadataSetId=:31 , expirationNoticeSent=:32 , firstExpirationWarningSent=:33 , secondExpirationWarningSent=:34 , expirationFolderId=:35 , maintainAbsoluteLinks=:36 , xmlId=:37 , structuredDataDefinitionId=:38 , pageConfigurationSetId=:39 , pageDefaultConfigurationId=:40 , structuredDataId=:41 , pageStructuredDataVersion=:42 , shouldBeIndexed=:43 , shouldBePublished=:44 , lastDatePublished=:45 , lastPublishedBy=:46 , draftOriginalId=:47 , contentTypeId=:48 where id=:49
End of information on OTHER waiting sessions.
Current SQL statement for this session:
delete from cascade.cxml_structureddata where id=:1Mohamed Houri wrote:
What is important for a foreign key is to be indexed (of course if the parent table is deleted/merged/updated, or if a performance reason imposes it). Wether this index is unique or not doesn't matter (as far as i know).But, you should ask your self the following question : what is the meaning of having a 1 to 1 relationship between a parent and a child table ? if you succeed to create a unique index on your FK then this means that for each PK value corresponds at most one FK value!! Isn't it? is this what you want to have?Thanks, as I mentioned above, cxml_structureddata is actually the child table of cxml_foldercontent with 1 or more records' owningEntityId referring to rows in cxml_foldercontent. The reason for the FK on cxml_foldercontent.structuredDataId is a little ambiguous but it explained above.
Will a TX-enqueue held on mode X always be waited on by another TX-enqueue row lock X? Or can it be waited on by an Exclusive (X) table lock?Not really clear. Sorry, are you saying my question is unclear or it's not clear why type of eXclusive lock session 542 is trying to acquire in the first line of the trace? Do you think that the exclusive lock being held by session 548 in the first line is on rows in cxml_foldercontent (due to the ON DELETE SET NULL on these child rows) or rows in the cxml_structureddata that it's actually deleting?
Is there any way for me to tell for certain?
The first enqueue is a TX (Transaction Enqueue) held by session 548 on mode X (exclusive). This session represents the blocking session. At the same time the locked row is waited on by the blocked session (542) and the wait is on mode X (exclusive). So put it simply, we have here session 542 waiting for session 548 to release it lock (may be by commiting/roll backing). At this step we are not in presence of a deadlock.
The second line of the deadlock graph shows that session 542 is the blocking session and it is doing a TM enqueue (DML lock) held on SX(Shared eXclusive). While session 548(which is the waiting session) is blocked by session 542 and is waiting on SSX mode.
Here we see that 548 is blocking session 542 via a TX enqueue and session 542 is blocking session 548 via a TM enqueue ---> That is the deadlock. Oracle will then immediately choose arbitrarlly a victim session (542 or 548) and kill its process letting the remaining session continuing its work.
That is your situation explained here.Thanks, any idea why session 542 (the DELETE from cxml_structureddata) would be trying to upgrade it's lock to SSX? Is this lock mode required to update a child tables foreign key columns when using an ON DELETE SET NULL trigger? Having read more about SSX, I'm not sure I understand in what cases it's used. Is there a way for me to confirm with 100% certainty specifically which tables in the TM enqueue locks are being held on? Is session 548 definitely trying to acquire an SSX mode on my cxml_foldecontent table or could it be cxml_structureddata table?
(a) Verify that all your FK are indexed (be carreful that the FK columns should be at the leading edge of the index)Thanks, we've done this already. When you say the "leading edge" you mean for a composite index? These indexes are all single column.
(b) Verify the logic of the DML against cxml_foldercontentCan you be more specific? Any idea what I'm looking for? -
How to add a field and table control to BP transaction.
Hi,
I have a requirement to add a field and table control to the 'Control data' tab of the Transaction BP.
Can some on please help me if having a solution and with any relavant documents.
Thanks in advance.
Raj & Khader.Also explore with EEWB tcode.
Refer this threads
Re: EEWB
Created New fields in Business Activity with EEWB
Cheers
Manohar -
Create a Cockpit (Transaction) for Reports and Tables
Hi Gurus,
i am very new in ABAP. I want to create a Transaction/view in SAP BW where i can put my favourite Abap reports and tables and execute These directly from the created view/Transaction without se16/se11 or se38 Access and dont know if this is possible and how to do it.
the reason herefore is that we get deprived in differently time ranges our authorizations for the Standard Transactions.
I have a list of my tables and programms.
Thanks for your help.we get deprived in differently time ranges our authorizations for the Standard Transactions.
So you try to bypass security checks put in place by the Basis team
or could you explain your requirement ?
Remember (or learn) that creating such transaction, you are able to bypass following authorization checks using SU24 (Identity Management, User and Role Administration of Application Server ABAP, AS ABAP Authorization Concept, From the Programmed Authorization Check to a Role, Editing Authorization Default Data (Development System) / Editing Authorization Default Data (Customer System). )
Regard,
Raymond -
SoD Analysis , tables to relate roles, transactions and auth objects
Hi everyone,
I am analyzing my company SAP roles in terms of segregation of duties, however I having a problem.
I need a table/report to give me for each role, every transactions and for each transaction in the role every authorization objects.
For example I want to know for Role B that have transaction C which have the follow authorization object D with values X and Y.
Therefore I want to know for each role and respective transactions which are only display or/and execute or/and editable. How can I do that?
Thanks!Hi,
There is no default report/table which gives you the required information. However, you can achieve this by using SQVI. Join the tables, and create a tcode for the same. Refer the below link:
Re: SAP Query in SQVI transaction
Alternatively, you can download all the data into spreadsheet and create Pivots to plot the information.
The other alternative is to have a custom program built which takes the information from AGR_DEFINE, AGR_AGRS, AGR_1251, AGR_1252, AGR_TCODE tables.
Hope this helps!!
Regards,
Raghu -
Workflow and autonomous transactions
I am trying to implement Workflow to execute PL/SQL procedures that are currently executed manually on my project. Most of the procedures issue commits or rollbacks and per Oracle support I needed to use PRAGMA AUTONOMOUS_TRANSACTION in the Workflow "wrapper" procedures to prevent errors with workflow. This has been successful with the vast majority of our procedures, however, in at least one case, a procedure that we execute (inserting millions of rows, Gbs of data) never finishes.
At first I thought that workflow might be the problem, but I have tested the procedure outside of Workflow in SQLPLus with the PRAGMA declared with the same result.
If I execute the procedure without the PRAGMA from SQL Plus without workflow it finishes in just under 4 hours (the expected time frame). Any ideas about what might be the cause of this strange behavior?
The problem seems to be caused by the PRAGMA which I need to implement Workflow. Any help would be much appreciated.This sounds like a database issue rather than a workflow issue. If it does not work from PL/SQL outside of workflow, then I would suggest logging a TAR with Oracle Support. Sounds like you have narrowed it down to an autonomous transaction that runs for > 4hours.
You might want to include a simple reproducible test case as well in the TAR. In the mean time, you could try and break down the amount of work being done into a number of PL/SQL calls instead of one. For example 4 * 1hour PL/SQL calls instead of 1 that lasts 4 hours and doesnt work.
HTH
Mark
Maybe you are looking for
-
Error 'Document 1000 0000000001 2014 already assigned' while posting invoice reduction
Hi Gurus, here is my situation: I have created sch.agreement, GR done and posted IR. Now created credit memo through MIRO to reverse my previous invoice. then posted IR(consider number as 0000000001) with higher price. then this invoice was rejected
-
How do I move bookmarks from my list or in a folder to the Favorites connection in my Start menu
I have a folder in my start menu named Favorites. When I click on it, it takes me to the list of bookmarked folders. When I open the folder I want, it shows some, but not all of the bookmarked sites in the folders. How do I add bookmarked sites to th
-
Can WRG54G be a wireless repeater for WRG54GC or vice versa?
I have a WRG54GC on second floor off cable modem and works wirelessly to 2 PCs. However, I do not have signal on the first floor opposite side of house. I cannot move the access point as that's where the cable modem comes in. Can the other router I h
-
Need to reinstall my Premium Skype on a different ...
My old computer crashed and I need to install my Premium Skype on my new computer. How do I do that without paying for a second Premium Skype account? mike.walker502
-
Hi, We're using OMS 11g. The mount point on which this is installed is of 25Gb and the mount point is 100% utilized. I wanted to know that what are the files which can be deleted(on a routine basis) for space maintainence? Regards