How to implement optemistic locking in pl/sql for oracle database

i have search the net to find example of how i can do the optimistic locking in pl/sql, all the resources i found were old , for example "Optimistic Locking with Concurrence in Oracle.
As " by Graham Thornton Snr. Database Architect / Oracle DBA in 2001, but at the end he said that the approach will not work fine if the update being made is a relative update, this apprach includes:-
1.add a timestamp column to an exsiting table.
2.add a preinsert trigger on the table to set the timestamp.
3.add a preupdate trigger to comapre the old time stamp with the new one.
So where i can find updated resources about this issue.
Edited by: 812643 on 17-Nov-2010 12:39

totally plagiarized from expert oracle database architecture 9i, 10g, 11g by Tom Kyte pg201
one popular implementation of optimistic locking is to keep the old and new values in the application and upon updating the data use and update like this
update table
set column1 =: new_column1, column2 = : new_column2, ...
where primary_key = :primary_key
and decode( column1, :old_column1, 1 ) = 1
and decode( column2, :old_column2, 1 ) = 1
another implementation
optimistic locking using a version column
add a single column to each database table you wish to protect from lost updates. this column is generally either a number or date/timestamp column
It is typically maintened via a row trigger on the table, which is responsible for incrementing the number column or updating the date/timestamp column
every time a row is modified.
another one on page 204
optimistic locking usin a checksum
similiar to the version column implementation but it uses the base data itself to compute a virtual version column.
the ones suggested where owa_opt_lock.checksum, dbms_obfuscation_toolkit.md5, dbms_crypto.hash, ora_hashEdited by: pollywog on Nov 17, 2010 3:48 PM
might be a good book for you to look into getting it has a whole chapter on locking and latching.
Edited by: pollywog on Nov 17, 2010 3:54 PM

Similar Messages

  • How to create a linked server to SQL in Oracle?

    I am able to create a linked server to Oracle in SQL.. But I do not know the steps to create a linked server too SQL in Oracle.
    How to create a linked server to SQL in Oracle? After creating the linked server to SQL, I would like to create triggers in Oracle DB to insert records into SQL DB.

    There are 2 products in Oracle you can use to link to a MS SQl Server. The first one is for free and it is called Database Gateway for ODBC. With a suitable 3rd party ODBC driver you can connect to any foreign database. The second gateway is our commercial gateway and it is called Oracle Database Gateway for MS SQL Server. It is designed for MS SQl Server connections and more powerful then Dg4ODBC. It know how to map a lot of Oracle functions to SQL Server equivalents and you can also use it to directly call SQL Server procedures or functions. This dedicated SQL server gateway is also able to participate in distributed transactions.
    But again, this is a commercial gateway and you have to purchase a license for that second gateway, the Database Gateway for MS SQl Server.
    - Klaus

  • How can you change data on a SQL 2012 application database that uses availability groups from BizTalk server?

    If you use the WCF-SQL adapter it is recommend that you set UseAmbientTransaction to true if you are changing data. I think this requires MSDTC to be enabled on the SQL server that you are changing the data on. (http://msdn.microsoft.com/en-us/library/dd787981.aspx)
    I think that Availability groups does not support MSDTC. (http://msdn.microsoft.com/en-us/library/ms366279.aspx).
    How can you change data on a SQL 2012 application database that uses availability groups from BizTalk server?

    Hi,
    Yes, Availability groups doesn't support MSDTC. Please refer to the similar discusison which maybe helpfull:
    http://dba.stackexchange.com/questions/47108/alwayson-ag-dtc-with-failover
    http://stackoverflow.com/questions/17179221/msdtc-in-always-on-availability-groups

  • How to get the lock and block occured for the full day

    Hi,
         How to monitor the lock and blocks occurred for the full day? i need to get it by end of the day. is there any script for this?

    Hi,
         How to monitor the lock and blocks occurred for the full day? i need to get it by end of the day. is there any script for this?
    Why would you like to collect information about locks and let me tell you, you cannot collect information about ALL locks which were taken and even thinking about it is pointless.
    Coming to blocking if you have heavy system with huge concurrency there is bound to be blocking which is necessary and good for RDBMS but if the blocking remains for long time then this is a issue.
    There is DMV sys.dm_tran_locks which tell you what all locks are being taken. You can see various examples mentioned in DMV online documentation and can schedule the query to run every 5
    mins and insert its record in table which you can refer at end of the day.
    This task would be made very easy if you have Monitoring tool which gives you information in your mail every time blocking occurs I have Spotlight in my environment.
    If you are looking for doc for troubleshooting blocking  below is one you can refer
    http://support.microsoft.com/kb/224453
    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it.
    My TechNet Wiki Articles

  • Oracle SQL template to create re-usable DDL/DML Scripts for Oracle database

    Hi,
    I have a requirement to put together a Oracle SQL template to create re-usable DDL/DML Scripts for Oracle databases.
    Only the Oracle DBA will be running the scripts so permissions is not an issue.
    The workflow for any DDL is as follows:-
    1) New Table
    a. Check if the table exists from the system/admin views.
    b. If table exists then give message "Table Exists"
    c. If table does not exist then execute DDL code
    2) Add Column
    a. Check if Column exists for a given table from system/admin views
    b. If column exists in the specified table,
    b1. backup table.
    b2. alter table to make changes to the column
    b3. verify data or execute dml script convert from backup to the new change.
    c. If Column does not exist
    c1. backup table
    c2. alter table to add column
    c3. execute dml to populate column with default value.
    The DML scripts are for populating base tables with data required for business operations.
    3) Add new row
    a. check if row exists by comparing old values of each column with new values to be added for the new record.
    b. If exists, give message row exists
    c. If not exists, add new record.
    4) Update existing record (We have createtime columns in these tables so changes can be tracked)
    a. check if row exists using primary key.
    b. If exists,
    b1. deactivate the record using the "active" column of the table
    b2. Add new record with the changes required.
    c. If does not exist, add new record with the changes required.
    Could you please help with some ideas which can get this done accurately?
    I have tried several ways, but I am not able to put together something that fulfills all requirements.
    Thank you,

    First let me address your question. (This is the easy part.)
    1. The existence of tables can be found in DBA_TABLES. Query it and and then use conditional logic and execute immediate to process the DDL.
    2. The existence of table columns is found in DBA_TAB_COLUMNS. Query it and then conditionally execute your DDL. You can copy the "before picture" of the table using that same dba view, or even better, use DBMS_METADATA.
    As for your DML scripts, they should be restartable, reversible, and re-run-able. They should "fail gracefully" on error, be written in such a way that they can run twice in a row without creating duplicate changes.
    3. Adding appropriate constraints can prevent invalid duplicate rows. Also, you can usually add to the where clause so that the DML does only what it needs to do without even relying on the constraint (but the constraint is there as a safeguard). Look up the MERGE statement to learn how to do an UPSERT (update/insert), which will let you conditionally "deactivate" (update) or insert a record. Anything that you cannot do in SQL can be done with simple procedural code.
    Now, to the heart of the matter...
    You think I did not understand your requirements?
    Please be respectful of people's comments. Many of us are professionals with decades of experience working with databases and Oracle technology. We volunteer our valuable time and knowledge here for free. It is extremely common for someone to post what they feel is an easy SQL or PL/SQL question without stating the real goal--the business objective. Experienced people will spot that the "wrong question" has been asked, and then cut to the chase.
    We have some good questions for you. Not questions we need answers from, but questions you need to ask yourself and your team. You need to reexamine this post and deduce what those questions are. But I'll give you some hints: Why do you need to do what you are asking? And will this construct you are asking for even solve the root cause of your problems?
    Then ponder the following quotations about asking the right question:
    Good questions outrank easy answers.
    — Paul Samuelson
    The only interesting answers are those which destroy the questions.
    — Susan Sontag
    The scientific mind does not so much provide the right answers as ask the right questions.
    — Claude Levi-Strauss
    You can tell whether a man is clever by his answers. You can tell whether a man is wise by his questions.
    — Mahfouz Naguib
    One hears only those questions for which one is able to find answers.
    — Friedrich Nietzsche
    Be patient towards all that is unresolved in your heart and try to love the questions themselves.
    — Rainer Maria Rilke
    What people think of as the moment of discovery is really the discovery of the question.
    — Jonas Salk
    Judge a man by his questions rather than his answers.
    — Voltaire
    The ability to ask the right question is more than half the battle of finding the answer.
    — Thomas J. Watson

  • How to set JDBC Data Sources in Oracle MapViewer for Oracle database 12c Release 1 (12.1.0.1)

    How to set JDBC Data Sources in Oracle MapViewer for Oracle database 12c Release 1 (12.1.0.1)?
    The following is my configuration in the conf\mapViewerConfig.xml:
    <map_data_source name="mvdemo12"
    jdbc_host="127.0.0.1"
    jdbc_sid="orcl12c1"
    jdbc_port="1522"
    jdbc_user="mvdemo"
    jdbc_password="7OVl2rJ+hOYxG5T3vKJQb+hW4NPgy9EN"
    jdbc_mode="thin"
    number_of_mappers="3"
    allow_jdbc_theme_based_foi="true"
    editable="true"/>
    <!--  ****  -->
    But it does not work.
    After use "sqlplus mvdemo/[email protected]:1522/pdborcl", it connected to the Oracle database 12c.
    Does anyone know it?
    Thanks,

    For 11.1.1.7.1 use the syntax for jdbc_sid, i.e.
    //mypdb1.foo.com as described in the README,
    - MapViewer native (non-container) data sources can now use database service name in place of SID. To supply a db service name, you will use the same jdbc_sid attribute, but specify the service name with double slashes in front, such as follows:
      <map_data_source name="myds"
        jdbc_host="foo.com"
        jdbc_sid="//mypdb1.foo.com"
        jdbc_port="1522"
      />
    For 11.1.1.7.0 use a container_ds instead.
    i.e. instead of using
    <map_data_source name="my_12c_test"
                       jdbc_host="mydbinstance"
                       jdbc_sid="pdborcl12c"
                       jdbc_port="1522"
                       jdbc_user="mytestuser"
                       jdbc_password="m2E7T48U3LfRjKwR0YFETQcjNb4gCMLG8/X0KWjO00Q="
                       jdbc_mode="thin"
                       number_of_mappers="6"
                       allow_jdbc_theme_based_foi="false"
                       editable="false"
       />
    use
      <map_data_source name="my_12c_test"
                       container_ds="jdbc/db12c"
                       number_of_mappers="6"
                       allow_jdbc_theme_based_foi="false"
                       editable="false"
       />
    In my case the Glassfish 3.1.2.2 JDBC connection pool definition was
    Property
    url  jdbc:oracle:thin:@mydbinstance:1522/pdborcl12c.rest_of.service.name
    Uncheck the Wrap JDBC Objects option in Advanced panel, i.e. the Edit JDBC Connection Pool Advanced properties page.
    Add a JDBC resource for that newly created pool
    Use that in mapviewerconfig.xml as above

  • Steps to create Universe from Microsoft SQL oder Oracle Database

    Hi All,
    i am looking for a document which describe the steps to create an Universe base on Microsoft SQL oder oracle database.
    Thank you in advance
    Pat

    Hi,
    These links may be help for you:
    http://www.bidw.org/business-objects/universe-design/getting-started-with-universe-design/
    http://www.sap-businessobjects.info/universe-design.htm
    All the Best,
    Madhu...

  • How to list the JAR files loaded into the Oracle Database ?

    How to list the JAR files loaded into the Oracle Database ?

    From 11.1 onwards, the below two views are available to identify the jar files loaded into the Database.
    JAVAJAR$
    JAVAJAROBJECTS$
    By querying the JAVAJAR$ view you can know information about the JAR files loaded into the Database and using JAVAJAROBJECTS$ view you can find all the java objects associated with the given JAR file.
    These views are populated everytime you use LOADJAVA with "-jarsasdbobjects" option to load your custom java classes.
    But unfortunately this feature is available only from 11.1 onwards and there is no clear workaround for above in 10.2 or earlier.

  • How do I set-up on %ORACLE_HOME%\bin for Oracle client on Windows XP

    How do I set-up on %ORACLE_HOME%\bin for Oracle client on Windows XP?
    The Oracle bin directory is: C:\oracle\ora90\bin
    Thank you!

    If you are asking how to setup the resolution of %ORACLE_HOME%\bin to C:\oracle\ora90\bin, you must create a system environment variable called ORACLE_HOME that is set to a value of C:\oracle\ora90.
    Kind regards,
    Russ

  • How to know the optimal Degree of Parallelism for my database?

    I have an important application on my databae (Oracle 10,2,0) and the box has 4 CPU. All the tables are not partitioned. Should I set the parallel degree by myself?
    How to know the optimal Degree of Parallelism for my database?

    As far as I am concerned there is no optimal degree of parallism at the database level. The optimal value varies by query based on the plan in use. It may change over time.
    It is not that difficult to overuse the PQO and end up harming overall database performance. PQO is a brute force methology and should be applied carefully. Otherwise you end up with inconsisten results.
    You can let Oracle manage it, or you can manage it on the statement level via hints. I do not like specifying degrees of parallelism at the object level. As I said, no two queries are exactly alike and what is right for one query against a table may not be right for another query against the table.
    If in doubt set up the system to let Oracle manage it. if what you are really asking is how many PQO sessions to allocate then look at your Statspack or AWR reports and judge your system load. Monitor v$px_session and v$pq_slave to see how much activity these views show.
    IMHO -- Mark D Powell --

  • Executing psadmin.sql for Oracle

    I am trying to insatll Peoplesoft using Oracle 10g Release2,Websphere,Tuxedo 9.1, PeopleTools 8.49 and FSCM9.0.
    I have successfully installed Oracle 10g, Websphere,Tuxedo,Peopletools and FSCM9.0.
    Now, when I am trying to create database from C:\PT8.49\setup\PsMpDbInstall\setup.exe, the Installer after asking the paths get stuck in "Executing psadmin.sql for Oracle" for more than 2 days.
    I read in other threads that some people could resolve this by running the scripts manually. If that is the solution can anyone please help me with the scripts in sequence.
    Thanks in advance!!!!

    Peoplesoft database wizard for Oracle was/is a quite buggy. You should follow the Peopletools Installation Guide for the manual installation tasks instead.
    All the steps can be found in the doc :
    http://download.oracle.com/docs/cd/E05406_01/psft/acrobat/hwtools849_itora.pdf
    If it is not clear, you can have a look to my blog (see my profile), I tried to explain simple as possible the main steps.
    Nicolas.

  • How to Implement shared lock

    Hi friends,
    For a table I have created views. I want to create shared lock for that table.
    How to achieve that.
    can we create shared lock for views?
    Thanks.

    Hi Pagidala,
    Go to Se11-> Select Lock object radiobutton->give some name starting with E for example EZDEMO_LOCK->click on Create ->give short description->clcik on Tables Tab->give the table name for which you want to implement shared lock example ZTABLE ->lock mode you select as Read Lock.After this save check and activate your lock object.
    We have selected READ LOCK since it protects read access to an object. The read lock allows other transactions read access but not write access to the locked area of the table.
    Check the below link for the complete information on Lock Concept.
    http://help.sap.com/saphelp_nw04/helpdata/en/41/7af4c5a79e11d1950f0000e82de14a/content.htm
    Cheers!!
    VEnk@
    Edited by: Venkat Reddy on Oct 29, 2008 11:54 AM

  • How to implement Pessimistic Locking?

    Hello,
    I am using JDev 10g with integrated mapping workbench. There are option to set up optimistic locking, but I would like to implement pessimistic locking. How do I approach this?
    Thanks,
    Dmitry.

    Dmitry,
    Pessimistic locking is not configured on the descriptor it is executed at the API level on either a session or query. If you are using the UnitOfWork directly then I would recommend looking in the docs at
    UnitOfWork.refreshAndLockObject(Object)
    UnitOfWork.refreshAndLockObject(Object, short lockMode)
    If you wish to configure it on a query you can look at:
    ObjectLevelReadQuery.setLockMode(short lockMode)
    ObjectLevelReadQuery.acquireLocks()
    ObjectLevelReadQuery.acquireLocksWithoutWaiting()
    In the case of a query it should only be executed against a UnitOfWork where the database TX can be started to maintain the database locks.
    Doug

  • How to implement email facility in PL/SQL programs.

    Is there any Oracle package which supports email facility?
    I have some dbms automatic jobs fires every half hour, in case there is any failure in the process I would like to send an email to user or the person who is running the job.
    Can some body tell me how to implement it in PL/SQL?????????????

    You might find this article useful..
    visit..
    http://www.oracle.com/oramag/code/tips2000/090400.html

  • How to implement the JDBC call over SSL on Oracle?

    I searched the forums and google. It seems to support Oracle 9i JDBC call, Thin driver can not work and we should use OCI.
    I referenced OTN Oracle java example about the SSL, it talked about the security socket but not anythingabout JDBC. http://download-west.oracle.com/docs/cd/B10501_01/network.920/a96573/asoappf.htm#634403
    Who can provide a clear description and resource URL to tell how to make a simple implementation on JDBC over SSL.
    Thanks a lot.

    That article you referenced is referring to the JVM that runs when one runs java stored procedures. It has nothing to do with JDBC.
    You have a unusual requirement (probabaly originated as the same place as your alias.)
    Most of the time SSL is not needed for the database because the database and the applications that talk to it are already on a secured network.
    You can investigate some third party drivers, I believe I recall seeing that one of them does SSL.
    Alternatively you might look into a secure VPN connection. The connection travels over IP and tunnels other traffic through it. Given that the tunned itself is secure, the contents are as well.

Maybe you are looking for