ORACLE数据库在进行DROP TABLE时失败报错ORA-00604问题的分析处理

近期,遇到ORACLE数据库在进行DROP TABLE时,无法删除,报错ORA-00604: error occurred at recursive SQL level 1,ORA-20001......的问题。

对于这种明显超出常理的问题,也无对应的后台日志,很难从报错入手排除问题。

此时的一个典型思路,是对SQL操作进行TRACE跟踪,如10046TRACE或者ERRORSTACK跟踪,来获取深层的TRACE日志,进行分析,通常可以发现问题的根因。

本次问题就是使用10046TRACE跟踪分析,或者DROP TABLE时数据库的底层SQL调用,最终发现是有1个触发器影响不让删除。

分析如下:

1、删除报错

SQL> create table KLB_PEQS1.test20210303 as select * from dba_users;

Table created.

SQL> drop table KLB_PEQS1.test20210303 ;

Table dropped.

SQL> show user

USER is "KLB_PEQS1"

SQL> create table test20210303 as select * from dba_users;

Table created.

SQL> drop table test20210303 ;

drop table test20210303

*

ERROR at line 1:

ORA-00604: error occurred at recursive SQL level 1

ORA-20001: KLB_PEQS1.TEST20210303 ?????drop??!

ORA-06512: at line 7

SQL> select * from dba_role_privs where grantee='KLB_PEQS1';

GRANTEE GRANTED_ROLE ADM DEF


KLB_PEQS1 RESOURCE NO YES

KLB_PEQS1 DBA NO YES

KLB_PEQS1 CONNECT NO YES

SQL>

SQL> select * from dba_role_privs where grantee='KLB_PEQS1';

GRANTEE GRANTED_ROLE ADM DEF


KLB_PEQS1 RESOURCE NO YES

KLB_PEQS1 DBA NO YES

KLB_PEQS1 CONNECT NO YES

SQL> drop table test20210303 ;

drop table test20210303

*

ERROR at line 1:

ORA-00604: error occurred at recursive SQL level 1

ORA-20001: KLB_PEQS1.TEST20210303 ?????drop??!

ORA-06512: at line 7

2、TRACE分析

SQL> select sid from v$mystat where rownum=1;

SID


786

SQL>

SQL>

SQL> drop table test20210303 ;

drop table test20210303

*

ERROR at line 1:

ORA-00604: error occurred at recursive SQL level 1

ORA-20001: KLB_PEQS1.TEST20210303 ?????drop??!

ORA-06512: at line 7

SQL> select b.spid,a.sid,a.username,a.program,a.machine,BLOCKING_SESSION

2 from vsession a,vprocess b

3 where a.paddr=b.addr and a.sid=786;

SPID SID USERNAME


PROGRAM


MACHINE


BLOCKING_SESSION


24317 786 KLB_PEQS1

sqlplus@nf-dboracle (TNS V1-V3)

nf-dboracle

SQL>

SQL>

SQL>

SQL> oradebug setospid 24317

Oracle pid: 92, Unix process pid: 24317, image: oracle@nf-dboracle (TNS V1-V3)

SQL> oradebug event 10046 trace name context forever,level 12;

Statement processed.

SQL> oradebug tracefile_name

/u01/app/oracle/diag/rdbms/orclpri/orcl/trace/orcl_ora_24317.trc

SQL> oradebug event 10046 trace name context off;

Statement processed.

3、分析TRACE文件

TKPROF: Release 11.2.0.3.0 - Development on Wed Mar 3 11:46:43 2021

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Trace file: /u01/app/oracle/diag/rdbms/orclpri/orcl/trace/orcl_ora_24317.trc

Sort options: default

********************************************************************************

count = number of times OCI procedure was executed

cpu = cpu time in seconds executing

elapsed = elapsed time in seconds executing

disk = number of physical reads of buffers from disk

query = number of buffers gotten for consistent read

current = number of buffers gotten in current mode (usually for update)

rows = number of rows processed by the fetch or execute call

********************************************************************************

SQL ID: asrh3b8ngw9zg Plan Hash: 0

DECLARE

l_errmsg VARCHAR2(100) := '不允许进行drop操作!';

BEGIN

IF ora_login_user NOT IN ('SYS','SYSTEM','DATA_MONITOR') THEN

raise_application_error(-20001, ora_dict_obj_owner||'.'||ora_dict_obj_name||' '||l_errmsg);

END IF;

END;

call count cpu elapsed disk query current rows


Parse 1 0.00 0.00 0 0 0 0

Execute 1 0.00 0.00 0 0 0 0

Fetch 0 0.00 0.00 0 0 0 0


total 2 0.00 0.00 0 0 0 0

Misses in library cache during parse: 0

Optimizer mode: ALL_ROWS

Parsing user id: 5 (recursive depth: 1)

相关推荐
计算机安禾1 天前
【数据库系统原理】第19篇:计算机存储层次结构与数据库文件的物理组织
数据库·oracle
JAVA面经实录9171 天前
操作系统面试题
java·服务器·数据库·计算机网络·面试
摇滚侠1 天前
mariadb-libs 被 mysql-community-libs-5.7.28-1.el7.x86_64 取代
数据库·mysql·mariadb
DIY源码阁1 天前
JavaSwing饮品管理系统 - MySQL版
java·数据库·mysql·eclipse
专注搞钱1 天前
GPT-4o写设备Recipe:从3小时到10分钟
数据库·人工智能·gpt·半导体
东风破1371 天前
达梦数据库实战:备份恢复与数据迁移全攻略(实例初始化、服务注册、路径迁移)
数据库·chrome
SelectDB技术团队1 天前
2026 SelectDB AI 产品发布会:Agent Native 数据基础设施能力全景发布
数据库·人工智能·agent·apache doris·selectdb
爱吃羊的老虎1 天前
【数据库】模块一:数据库基础与关系代数
数据库
dishugj1 天前
iSCSI + Multipath + ASM:Oracle RAC 共享存储技术链详解
数据库·oracle
yoothey1 天前
MySQL事务机制解析 - 面试高分知识点
数据库·mysql·面试