您可以使用以下方法來檢查表是否被鎖定:
SELECT *
FROM V$LOCK
WHERE TYPE = 'TM' AND ID1 = <表的對象ID>;
DECLARE
v_lockhandle VARCHAR2(128);
BEGIN
v_lockhandle := DBMS_LOCK.REQUEST('<表名>', DBMS_LOCK.X_MODE, 10, TRUE);
DBMS_OUTPUT.PUT_LINE('Table is not locked');
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Table is locked');
END;
DECLARE
v_lockhandle VARCHAR2(128);
v_result NUMBER;
BEGIN
v_lockhandle := DBMS_LOCK.ALLOCATE_UNIQUE('<表名>');
v_result := DBMS_LOCK.REQUEST(v_lockhandle, DBMS_LOCK.X_MODE, 10, TRUE);
IF v_result = 0 THEN
DBMS_OUTPUT.PUT_LINE('Table is not locked');
DBMS_LOCK.RELEASE(v_lockhandle);
ELSE
DBMS_OUTPUT.PUT_LINE('Table is locked');
END IF;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Table is locked');
END;
請注意,這些方法僅適用于您具有足夠的權限來查詢鎖定信息。