oracle ebs 加锁
DECLARE -- lock l_lockname VARCHAR2(100); l_lockhandle VARCHAR2(200); l_lock_output NUMBER; l_locked BOOLEAN := FALSE; g_pkg_name VARCHAR2(240) := '2345'; g_org_id NUMBER := 112; BEGIN /* 定义按何种方式并发(此处为同一个OU不能同时执行) * lockname类似于定义一个唯一的名字,当并发程序执行时就会去判断是否这个唯一标识已经存在 */ l_lockname := g_pkg_name || '_' || g_org_id; --根据l_lockname获取唯一标识l_lockhandle dbms_lock.allocate_unique(lockname => l_lockname, lockhandle => l_lockhandle); /*用l_lockhandle这个唯一标识去给当前请求加锁 -- Return value: -- 0 - success -- 1 - timeout -- 2 - deadlock -- 3 - parameter error -- 4 - already own lock specified by 'id' or 'lockhandle' -- 5 - illegal lockhandle*/ l_lock_output := dbms_lock.request(l_lockhandle, 6, 60, FALSE); dbms_output.put_line('1 ' || l_lock_output); dbms_lock.allocate_unique(lockname => l_lockname, lockhandle => l_lockhandle); l_lock_output := dbms_lock.request(l_lockhandle, 6, 60, FALSE); dbms_output.put_line('2 ' || l_lock_output); --此处添加请求的业务逻辑 --dbms_lock.sleep(seconds => 50); /*特别注意的是一定要将lockname释放掉 否则这个并发就永远别想再执行了*/ l_lock_output := dbms_lock.release(l_lockhandle); dbms_output.put_line('3 ' || l_lock_output); dbms_lock.allocate_unique(lockname => l_lockname, lockhandle => l_lockhandle); l_lock_output := dbms_lock.request(l_lockhandle, 6, 60, FALSE); dbms_output.put_line('4 ' || l_lock_output); l_lock_output := dbms_lock.release(l_lockhandle); dbms_output.put_line('5 ' || l_lock_output); EXCEPTION WHEN apps.fnd_api.g_exc_error THEN IF l_lock_output = 0 THEN l_lock_output := dbms_lock.release(l_lockhandle); END IF; WHEN OTHERS THEN IF l_lock_output = 0 THEN l_lock_output := dbms_lock.release(l_lockhandle); END IF; END;
土豆君