目得:首先了解什么是外部表,与其它表的区别,建立一个简单的外部表(主要看操作过程),最后我们用外部表查看ORACLE报警日志
1.了解oracle外部表
外部表定义:结构被存放在数据字典,而表数据被放在OS文件中的表
作用:在数据库中查询OS文件的数据,还可以将OS文件数据装载到数据库中
与其它表的区别:在外部表上不能执行DML操作,也不能在外部表上建索引,只能执行select操用
2.建一个简单的外部表
1.建一个OS上的文件
因为外部表主要是查看OS上的文件,首先在OS上建一个文件
mkdir -p /oracle/ext
vi /oracle/ext/ext.dat
10,20,30
40,50,60
70,80,90
|
2.授予用户权限,并建立目录对象
在此我们先建一个新用户
create user test identified by “123” default tablespace test quota unlimited on test;
|
用户授权
SQL> grant create any directory to test;
|
建立目录对象
SQL> conn test / 123
Connected.
SQL> create directory ext as '/oracle/ext';
Directory created.
|
3.建立外部表
SQL> create table exttable(
id number,name varchar2(10),i number
)organization external
(type oracle_loader
default directory ext
access parameters
(records delimited by newline
fields terminated by ','
)location('ext.dat')
);
|
4.测试
SQL> select * from exttable;
ID NAME I
---------- ---------- ----------
10 20 30
40 50 60
70 80 90
|
测试成功,可见在数据库中可以查询OS文件的数据
2. 使用外部表查看oracle报警日志
由于在上面实验中已建立了一个用户,并赋相应的权限,而且也有了OS文件(即报警文件alert_SID.log),所以在此直接建立目录对象并建立外部表就可以了。
1.建立目录对象
SQL> conn test / 123
Connected.
SQL> create directory bdump as '/oracle/u01/app/oracle/admin/db2/bdump';
Directory created.
|
2.建立外部表
SQL> create table alert_log(
text varchar2(400)
)organization external
(type oracle_loader
default directory bdump
access parameters
(records delimited by newline
)location('alert_db2.log')
);
|
3.测试
首先查看能否查到alert_db2.log的内容
SQL> select * from alert_log where rownum < 10;
TEXT
--------------------------------------------------------------------------------
Thu Jun 11 00:51:46 2009
Starting ORACLE instance (normal)
Cannot determine all dependent dynamic libraries for /proc/self/exe
Unable to find dynamic library libocr10.so in search paths
RPATH = /ade/aime1_build2101/oracle/has/lib/:/ade/aime1_build2101/oracle/lib/:/a
de/aime1_build2101/oracle/has/lib/:
LD_LIBRARY_PATH is not set!
The default library directories are /lib and /usr/lib
Unable to find dynamic library libocrb10.so in search paths
Unable to find dynamic library libocrutl10.so in search paths
9 rows selected.
|
测试成功
然后我们测试查报警信息’ORA-%’
SQL> select * from alert_log where text like 'ORA-%';
TEXT
--------------------------------------------------------------------------------
ORA-00202: control file: '/oracle/u01/app/oracle/product/10.2.0/db2/dbs/cntrldb2
.dbf'
ORA-27037: unable to obtain file status
ORA-205 signalled during: ALTER DATABASE MOUNT...
ORA-00301: error in adding log file '/home/oracle/oracle/oradata/testdb/redo01.l
og' - file cannot be created
ORA-27040: file create error
ORA-1501 signalled during: CREATE DATABASE db2
ORA-00200: control file could not be created
TEXT
--------------------------------------------------------------------------------
ORA-00202: control file: '/oracle/u01/app/oracle/product/10.2.0/db2/dbs/cntrldb2
.dbf'
ORA-27038: created file already exists
ORA-1501 signalled during: CREATE DATABASE db2
ORA-00200: control file could not be created
ORA-00202: control file: '/oracle/u01/app/oracle/product/10.2.0/db2/dbs/cntrldb2
.dbf'
ORA-27038: created file already exists
ORA-1501 signalled during: CREATE DATABASE db2
|
测试成功,
可见我们可以使用外部表来方便的查看ORACLE的报警信息.
本文转自 vfast_chenxy 51CTO博客,原文链接:http://blog.51cto.com/chenxy/168236,如需转载请自行联系原作者