码迷,mamicode.com
首页 > 数据库 > 详细

oracle 外部表查alter日志

时间:2017-03-29 19:01:45      阅读:369      评论:0      收藏:0      [点我收藏+]

标签:varchar2   sql   ace   direct   create   数据   rdbms   to_date   创建   

--创建文件夹,路径是alter日志的路径
create or replace directory data_dir as
/u01/app/oracle/diag/rdbms/orcl/orcl/trace;

--创建外部表
create table alert_log(
       text_line varchar2(225)
)
organization external
(
       TYPE ORACLE_LOADER
       DEFAULT DIRECTORY DATA_DIR
       ACCESS PARAMETERS
       (
              RECORDS DELIMITED BY NEWLINE
              FIELDS
       )
       LOCATION
       (
              alert_orcl.log
       )
);

--查询数据库启动时间sql
select to_char(LAST_TIME) shutdown,
       to_char(start_time) starup,
       round((start_time - LAST_TIME) * 24 * 60, 2) mins_down,
       round((LAST_TIME - lag(start_time) over(order by r)), 2) days_up,
       case
         when (lead(r) over(order by r) is null) then
          round((sysdate - start_time), 2)
       end days_still_up
  from (select r,
               to_date(last_time,
                       Dy Mon DD HH24:MI:SS YYYY,
                       NLS_DATE_LANGUAGE = American) LAST_TIME,
               to_date(start_time,
                       Dy Mon DD HH24:MI:SS YYYY,
                       NLS_DATE_LANGUAGE = American) start_time
          from (select r,
                       text_line,
                       lag(text_line, 1) over(order by r) start_time,
                       lag(text_line, 2) over(order by r) last_time
                  from (select rownum r, text_line
                          from alert_log
                         where text_line like ___ ___ __ __:__:__ 20__
                            or text_line like Starting ORACLE instance %))
         where text_line like Starting ORACLE instance %);

 

oracle 外部表查alter日志

标签:varchar2   sql   ace   direct   create   数据   rdbms   to_date   创建   

原文地址:http://www.cnblogs.com/wolil/p/6641032.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!