如果未在“insert”语句中使用,则以下查询可正常工作。使用“insert”语句,我收到错误“basis.sql_text:indvalid identifier”。我似乎无法弄清楚为什么。想法?
with basis as
(SELECT DISTINCT
b.snap_id,
c.begin_interval_time,
c.end_interval_time,
a.sql_id,
b.executions_delta,
DECODE (d.command_type,
1, 'Create_Table',
2, 'Insert',
3, 'Select',
6, 'Update',
7, 'Delete',
26, 'Lock Table',
35, 'Alter Database',
42, 'Alter Session',
44, 'Commit',
45, 'Rollback',
46, 'Savepoint',
47, 'Begin/Declare',
command_type) command_type,
object_owner,
NVL2 (e.index_name, e.table_name, object_name) table_name,
object_type,
DBMS_LOB.SUBSTR (d.sql_text, 256, 1) sql_text,
'DEVSDB1',
'20-JUL-12 03.55.21.000000 PM'
FROM dba_hist_sql_plan@DEVSDB1 A,
dba_hist_sqlstat@DEVSDB1 b,
dba_hist_snapshot@DEVSDB1 C,
dba_hist_sqltext@DEVSDB1 d,
dba_indexes@DEVSDB1 E
WHERE a.sql_id = b.sql_id
AND b.sql_id = d.sql_id
AND b.snap_id = c.snap_id
AND e.index_name(+) = a.object_name
AND object_owner IN ('EG', 'WV90')
AND object_type IS NOT NULL
AND end_interval_time >= (SYSDATE - 1))
INSERT INTO sdhoste.EMSDB_USAGE@DEVSDB1
SELECT basis.snap_id,
basis.begin_interval_time,
basis.end_interval_time,
basis.sql_id,
NVL (basis.executions_delta, '0'),
basis.command_type,
basis.object_owner,
t.table_name,
basis.object_type,
basis.sql_text
FROM dba_tables@DEVSDB1 T
LEFT JOIN
basis
ON basis.table_name = t.table_name
WHERE OWNER IN ('EG', 'WV90');
答案 0 :(得分:1)
排序依据在嵌套插入查询中不起作用,请将其删除。
答案 1 :(得分:0)
您的查询中存在少量错误。
1.使用解码或任何数据库功能时,在With basis{}
内提供适当的别名
e.g。
DECODE (command_type,
1, 'Create_Table',
2, 'Insert',
3, 'Select',
6, 'Update',
7, 'Delete',
26, 'Lock Table',
35, 'Alter Database',
42, 'Alter Session',
44, 'Commit',
45, 'Rollback',
46, 'Savepoint',
47, 'Begin/Declare',
command_type
)cmdtype,
和
DBMS_LOB.SUBSTR (d.sql_text, 256, 1) sql_tex
2. basis.exec_per_snap
内部没有定义基础块
答案 2 :(得分:0)
试试这个:
INSERT INTO sdhoste.EMSDB_USAGE@DEVSDB1
WITH basis AS
(basis query here)
SELECT basis.snap_id
, basis.begin_interval_time
, basis.end_interval_time
, basis.sql_id
, NVL (basis.executions_delta, '0')
, basis.command_type
, basis.object_owner
, t.table_name
, basis.object_type
, basis.sql_text
FROM dba_tables@DEVSDB1 T LEFT JOIN basis
ON basis.table_name = t.table_name
WHERE OWNER IN ('EG', 'WV90');
不要将WITH子句放在parens中。