我正在尝试 运行 dba_hist_plan 查询来查找特定的模式对象
I am trying to run a dba_hist_plan query to look for specific schema objects
这是我的脚本,去掉了架构名称。
col c1 heading ‘Owner’ format a13
col c2 heading ‘Object|Type’ format a15
col c3 heading ‘SQL|ID’ format a25
break on c1 skip 2
break on c2 skip 2
select
p.object_owner c1,
p.object_type c2,
p.SQL|ID' c3,
from
dba_hist_sql_plan p
where
p.object_name is not null
and
p.object_owner <> '*'
group by
p.object_owner,
p.object_type,
p.SQL|ID'
order by
1,2,3 desc
;
我在这里遇到这个错误 - SQL 错误:ORA-00996:连接运算符是 ||,不是 |
00996. 00000 - “连接运算符是 ||,不是 |”
以下是查询的清理版本:
select distinct
object_owner,
object_type,
SQL_ID
from
dba_hist_sql_plan
where
object_name is not null
and object_owner <> '*'
order by 1,2,3 desc;
我做了这些改变;有些是修复,有些是风格建议:
- 删除了多余的单引号。
- 已将 SQL|ID 更改为 SQL_ID。
- 已将 GROUP BY 替换为 DISTINCT。它们在这里的工作方式相同,但由于您没有使用任何聚合函数,因此 DISTINCT 更简单。
- 删除了 table 别名。 (为什么要创建额外的变量?)
但是您确定要使用 SQL*Plus 执行此操作吗? SQL*Plus 非常适合脚本安装和架构更改,但您的任务看起来像是结构化和非结构化数据的临时数据分析。出于多种原因,IDE 工作表是完成此任务的更好工具。如果您还没有 GUI 工具,请下载免费的 Oracle SQL Developer。
这是我的脚本,去掉了架构名称。
col c1 heading ‘Owner’ format a13
col c2 heading ‘Object|Type’ format a15
col c3 heading ‘SQL|ID’ format a25
break on c1 skip 2
break on c2 skip 2
select
p.object_owner c1,
p.object_type c2,
p.SQL|ID' c3,
from
dba_hist_sql_plan p
where
p.object_name is not null
and
p.object_owner <> '*'
group by
p.object_owner,
p.object_type,
p.SQL|ID'
order by
1,2,3 desc
;
我在这里遇到这个错误 - SQL 错误:ORA-00996:连接运算符是 ||,不是 | 00996. 00000 - “连接运算符是 ||,不是 |”
以下是查询的清理版本:
select distinct
object_owner,
object_type,
SQL_ID
from
dba_hist_sql_plan
where
object_name is not null
and object_owner <> '*'
order by 1,2,3 desc;
我做了这些改变;有些是修复,有些是风格建议:
- 删除了多余的单引号。
- 已将 SQL|ID 更改为 SQL_ID。
- 已将 GROUP BY 替换为 DISTINCT。它们在这里的工作方式相同,但由于您没有使用任何聚合函数,因此 DISTINCT 更简单。
- 删除了 table 别名。 (为什么要创建额外的变量?)
但是您确定要使用 SQL*Plus 执行此操作吗? SQL*Plus 非常适合脚本安装和架构更改,但您的任务看起来像是结构化和非结构化数据的临时数据分析。出于多种原因,IDE 工作表是完成此任务的更好工具。如果您还没有 GUI 工具,请下载免费的 Oracle SQL Developer。