nowait的作用是当要锁定的对象已经被另外的session锁定时,不等待立即返回resource busy的错误

解决方案 »

  1.   

    该函数的意思:
    锁定tab表查询aaa=in_aaa的记录, 如果该记录的sts不等于'S'的话,释放锁,返回. 如果该行等于"S"的话,则把该字段更新成"R".并把日期更新为当前时间.更新成功返回0,失败返回-1;
      

  2.   

    Using FOR UPDATE
    When you declare a cursor that will be referenced in the CURRENT OF clause of an UPDATE or DELETE statement, you must use the FOR UPDATE clause to acquire exclusive row locks. An example follows:DECLARE
       CURSOR c1 IS SELECT empno, sal FROM emp
          WHERE job = 'SALESMAN' AND comm > sal 
          FOR UPDATE NOWAIT;
    The SELECT ... FOR UPDATE statement identifies the rows that will be updated or deleted, then locks each row in the result set. This is useful when you want to base an update on the existing values in a row. In that case, you must make sure the row is not changed by another user before the update.The optional keyword NOWAIT tells Oracle not to wait if requested rows have been locked by another user. Control is immediately returned to your program so that it can do other work before trying again to acquire the lock. If you omit the keyword NOWAIT, Oracle waits until the rows are available.All rows are locked when you open the cursor, not as they are fetched. The rows are unlocked when you commit or roll back the transaction. So, you cannot fetch from a FOR UPDATE cursor after a commit. (For a workaround, see "Fetching Across Commits".)When querying multiple tables, you can use the FOR UPDATE clause to confine row locking to particular tables. Rows in a table are locked only if the FOR UPDATE OF clause refers to a column in that table. For example, the following query locks rows in the emp table but not in the dept table:DECLARE
       CURSOR c1 IS SELECT ename, dname FROM emp, dept
          WHERE emp.deptno = dept.deptno AND job = 'MANAGER'
          FOR UPDATE OF sal;
      

  3.   

    select ROWID,sts into v_rowid,v_sts
          from tab
          where aaa=in_aaa for update of sts,sts_date nowait;------什么意思?---------------------------
    当更新tab中列sts,sts_date,满足条件时进行行级锁