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.授予用户权限,并建立目录对象
在此我们先建一个新用户
createusertestidentifiedby“123” default tablespacetestquotaunlimitedontest; |
用户授权
sql>grantcreateanydirectorytotest; |
建立目录对象
sql>conntest/123 Connected. sql>createdirectoryextas'/oracle/ext'; Directorycreated. |
3.建立外部表
sql>create
table
exttable(idnumber,namevarchar2(10),inumber
)organizationexternal
(typeoracle_loader
defaultdirectoryext
access
parameters(recordsdelimitedbynewline
fieldsterminatedby','
)location('ext.dat')
);
4.测试
sql>select*fromexttable; IDNAME I ------------------------------ 1020 30 4050 60 70 8090 |
2. 使用外部表查看oracle报警日志
由于在上面实验中已建立了一个用户,并赋相应的权限,而且也有了OS文件(即报警文件alert_SID.log),所以在此直接建立目录对象并建立外部表就可以了。
1.建立目录对象
sql>conntest/123 Connected. sql>createdirectorybdumpas'/oracle/u01/app/oracle/admin/db2/bdump'; Directorycreated. |
2.建立外部表
sql>createtablealert_log( textvarchar2(400))organizationexternal (typeoracle_loader defaultdirectorybdump accessparameters (recordsdelimitedbynewline )location('alert_db2.log') ); |
首先查看能否查到alert_db2.log的内容
sql>select*fromalert_logwhererownum<10; TEXT-------------------------------------------------------------------------------- ThuJun1100:51:462009 StartingORACLE instance(normal)Cannotdeterminealldependentdynamiclibrariesfor/proc/self/exe Unabletofinddynamiclibrarylibocr10.soinsearchpaths RPATH=/ade/aime1_build2101/oracle/has/lib/:/ade/aime1_build2101/oracle/lib/:/a de/aime1_build2101/oracle/has/lib/: LD_LIBRARY_PATHisnot set!Thedefaultlibrarydirectoriesare/liband/usr/lib Unabletofinddynamiclibrarylibocrb10.soinsearchpaths Unabletofinddynamiclibrarylibocrutl10.soinsearchpaths 9rowsselected. |
测试成功
然后我们测试查报警信息'ORA-%'
sql>select*fromalert_logwheretextlike'ORA-%'; TEXT -------------------------------------------------------------------------------- ORA-00202:control file:'/oracle/u01/app/oracle/product/10.2.0/db2/dbs/cntrldb2.dbf' ORA-27037:unabletoobtainfilestatus ORA-205signalledduring:ALTER DATABASEMOUNT...ORA-00301:errorinaddinglogfile'/home/oracle/oracle/oradata/testdb/redo01.l og'-filecannotbecreated ORA-27040:filecreateerror ORA-1501signalledduring:CREATEDATABASEdb2 ORA-00200:controlfilecouldnotbecreated TEXT -------------------------------------------------------------------------------- ORA-00202:controlfile:'/oracle/u01/app/oracle/product/10.2.0/db2/dbs/cntrldb2 .dbf' ORA-27038:createdfilealreadyexists ORA-1501signalledduring:CREATEDATABASEdb2 ORA-00200:controlfilecouldnotbecreated ORA-00202:controlfile:'/oracle/u01/app/oracle/product/10.2.0/db2/dbs/cntrldb2 .dbf' ORA-27038:createdfilealreadyexists ORA-1501signalledduring:CREATEDATABASEdb2 |
测试成功,
可见我们可以使用外部表来方便的查看ORACLE的报警信息.