0

如果未在“插入”语句中使用,则以下查询可以正常工作。使用“插入”语句,我收到错误“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');
4

3 回答 3

1

Order by 在嵌套插入查询中不起作用,请删除它。

于 2012-07-23T12:55:06.140 回答
0

您的查询中几乎没有错误。

With basis{}1.使用解码或任何数据库功能时,请在里面提供适当的别名

例如

 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在基础块内部没有定义

于 2012-07-23T12:55:59.650 回答
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 子句放在括号内。

于 2012-07-23T20:36:19.597 回答