Oracle EBS 加锁解锁程序

时间:2022-06-10 05:42:04
  FUNCTION request_lock(p_lock_name IN VARCHAR2) RETURN BOOLEAN IS
l_lock_name VARCHAR2(128);
l_lock_ret INTEGER;
l_ret_val BOOLEAN := TRUE;
l_lock_handle VARCHAR2(240);
BEGIN
IF p_lock_name IS NOT NULL THEN
--增加数据库锁,以保证一个批次同时只运行一次
l_lock_name := p_lock_name;
dbms_lock.allocate_unique(lockname => l_lock_name,
lockhandle => l_lock_handle);
g_lock_handle := l_lock_handle;
--获取数据库锁
l_lock_ret := dbms_lock.request(lockhandle => l_lock_handle,
lockmode => 6,
timeout => 10,
release_on_commit => FALSE);
IF l_lock_ret <> 0 THEN
--状态不为(成功)
l_ret_val := FALSE;
END IF;
ELSE
l_ret_val := FALSE;
END IF;
cux_conc_utl.log_msg('request lock');
RETURN l_ret_val;
END request_lock;
 PROCEDURE release_lock(p_lock_name IN VARCHAR2) IS
l_lock_name VARCHAR2(128);
l_lock_handle VARCHAR2(128);
l_lock_ret INTEGER;
BEGIN
IF g_lock_handle IS NOT NULL THEN
l_lock_ret := dbms_lock.release(g_lock_handle);
ELSE
l_lock_name := p_lock_name;
dbms_lock.allocate_unique(lockname => l_lock_name,
lockhandle => l_lock_handle);
l_lock_ret := dbms_lock.release(l_lock_handle);
g_lock_handle := l_lock_handle;
END IF;
cux_conc_utl.log_msg('release_lock: ' || l_lock_ret);
END release_lock;