Oracle教程之管理表(六)--Oracle外部表的管理
生活随笔
收集整理的這篇文章主要介紹了
Oracle教程之管理表(六)--Oracle外部表的管理
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
外部表是表結構被存放在數據字典,而表數據被存放在OS文件的表。通過使用外部表,不僅可以在數據庫中查詢OS文件的數據,還可以使用INSERT方式將OS文件數據裝載到數據庫中,從而實現SQL*Loader所提供的功能。建立外部表后,可以查詢外部表的數據,在外部表上執行連接查詢,或對外部表的數據進行排序。需要注意,外部表上不能執行DML修改,也不能在外部表上建立索引。1、建立外部表——準備工作:[oracle@solaris10 ~]$mkdir /export/home/oracle/dat[oracle@solaris10 ~]$cd /export/home/oracle/dat[oracle@solaris10 dat]$vi empxt1.dat360,Jane,Janus,ST_CLERK,121,17-MAY-2001,3000,0,50,jjanus361,Mark,Jasper,SA_REP,145,17-MAY-2001,8000,.1,80,mjasper362,Brenda,Starr,AD_ASST,200,17-MAY-2001,5500,0,10,bstarr363,Alex,Alda,AC_MGR,145,17-MAY-2001,9000,.15,80,aalda[oracle@solaris10 dat]$vi empxt2.dat401,Jesse,Cromwell,HR_REP,203,17-MAY-2001,7000,0,40,jcromwel402,Abby,Applegate,IT_PROG,103,17-MAY-2001,9000,.2,60,aapplega403,Carol,Cousins,AD_VP,100,17-MAY-2001,27000,.3,90,ccousins404,John,Richardson,AC_ACCOUNT,205,17-MAY-2001,5000,0,110,jrichard——建立對應的目錄:SQL> conn /as sysdbaConnected.SQL> create or replace directory admin_dat_dir2 ?as '/export/home/oracle/dat';Directory created.SQL> create or replace directory admin_log_dir2 ?as '/export/home/oracle/log';Directory created.SQL> create or replace directory admin_bad_dir2 ?as '/export/home/oracle/bad';Directory created.SQL> ![oracle@solaris10 ~]$mkdir /export/home/oracle/{log,bad}[oracle@solaris10 ~]$ls1 ? ? ? ? ? ? ? Documents ? ? ? core ? ? ? ? ? ?dat ? ? ? ? ? ? local.login ? ? shell1.sql ? ? ? ? ? afiedt.buf ? ? ?cr_anny_db.sql ?hell.txt ? ? ? ?local.profile ? x86Desktop ? ? ? ? bad ? ? ? ? ? ? cr_dict.sql ? ? local.cshrc ? ? log——授權scott 可以訪問所建立的目錄SQL> grant read on directory admin_dat_dir to scott;Grant succeeded.SQL> grant write on directory admin_log_dir to scott;Grant succeeded.SQL> grant write on directory admin_bad_dir to scott;Grant succeeded.——建立外部表SQL> conn scott/tigerConnected.SQL>CREATE TABLE admin_ext_employees(employee_id ? ? ? NUMBER(4),first_name ? ? ? ?VARCHAR2(20),last_name ? ? ? ? VARCHAR2(25),job_id ? ? ? ? ? ?VARCHAR2(10),manager_id ? ? ? ?NUMBER(4),hire_date ? ? ? ? DATE,salary ? ? ? ? ? ?NUMBER(8,2),commission_pct ? ?NUMBER(2,2),department_id ? ? NUMBER(4),email ? ? ? ? ? ? VARCHAR2(25))ORGANIZATION EXTERNAL(TYPE ORACLE_LOADERDEFAULT DIRECTORY admin_dat_dirACCESS PARAMETERS(records delimited by newlinebadfile admin_bad_dir:'empxt%a_%p.bad'logfile admin_log_dir:'empxt%a_%p.log'fields terminated by ','missing field values are null( employee_id, first_name, last_name, job_id, manager_id,hire_date char date_format date mask "dd-mon-yyyy",salary, commission_pct, department_id, email))LOCATION ('empxt1.dat', 'empxt2.dat'))PARALLELREJECT LIMIT UNLIMITED;Table created.SQL> select * from tab;TNAME ? ? ? ? ? ? ? ? ? ? ? ? ?TABTYPE ?CLUSTERID------------------------------ ------- ----------DEPT ? ? ? ? ? ? ? ? ? ? ? ? ? TABLEEMP ? ? ? ? ? ? ? ? ? ? ? ? ? ?TABLEBONUS ? ? ? ? ? ? ? ? ? ? ? ? ?TABLESALGRADE ? ? ? ? ? ? ? ? ? ? ? TABLETEST ? ? ? ? ? ? ? ? ? ? ? ? ? TABLEADMIN_EXT_EMPLOYEES ? ? ? ? ? ?TABLE6 rows selected.——查詢外部表記錄SQL> select * from ADMIN_EXT_EMPLOYEES;EMPLOYEE_ID FIRST_NAME LAST_NAME ?JOB_ID ? ? MANAGER_ID HIRE_DATE ? ? ? ? ? ? ? SALARY COMMISSION_PCT DEPARTMENT_ID EMAIL----------- ---------- ---------- ---------- ---------- ------------------- ---------- -------------- ------------- ----------360 Jane ? ? ? Janus ? ? ?ST_CLERK ? ? ? ? ?121 2001-05-17 00:00:00 ? ? ? 3000 ? ? ? ? ? ? ?0 ? ? ? ? ? ?50 jjanus361 Mark ? ? ? Jasper ? ? SA_REP ? ? ? ? ? ?145 2001-05-17 00:00:00 ? ? ? 8000 ? ? ? ? ? ? .1 ? ? ? ? ? ?80 mjasper362 Brenda ? ? Starr ? ? ?AD_ASST ? ? ? ? ? 200 2001-05-17 00:00:00 ? ? ? 5500 ? ? ? ? ? ? ?0 ? ? ? ? ? ?10 bstarr363 Alex ? ? ? Alda ? ? ? AC_MGR ? ? ? ? ? ?145 2001-05-17 00:00:00 ? ? ? 9000 ? ? ? ? ? ?.15 ? ? ? ? ? ?80 aalda401 Jesse ? ? ?Cromwell ? HR_REP ? ? ? ? ? ?203 2001-05-17 00:00:00 ? ? ? 7000 ? ? ? ? ? ? ?0 ? ? ? ? ? ?40 jcromwel402 Abby ? ? ? Applegate ?IT_PROG ? ? ? ? ? 103 2001-05-17 00:00:00 ? ? ? 9000 ? ? ? ? ? ? .2 ? ? ? ? ? ?60 aapplega403 Carol ? ? ?Cousins ? ?AD_VP ? ? ? ? ? ? 100 2001-05-17 00:00:00 ? ? ?27000 ? ? ? ? ? ? .3 ? ? ? ? ? ?90 ccousins404 John ? ? ? Richardson AC_ACCOUNT ? ? ? ?205 2001-05-17 00:00:00 ? ? ? 5000 ? ? ? ? ? ? ?0 ? ? ? ? ? 110 jrichard10 rows selected.只能讀,不能做dmlSQL> delete from ADMIN_EXT_EMPLOYEES;delete from ADMIN_EXT_EMPLOYEES*ERROR at line 1:ORA-30657: operation not supported on external organized table——把外部表數據插入到oracle 表里SQL> create table employees as select * from admin_ext_employees where 1=2;Table created.SQL> insert into employees select * from admin_ext_employees;10 rows created.SQL> select * from employees;EMPLOYEE_ID FIRST_NAME LAST_NAME ?JOB_ID ? ? MANAGER_ID HIRE_DATE ? ? ? ? ? ? ? SALARY COMMISSION_PCT DEPARTMENT_ID EMAIL----------- ---------- ---------- ---------- ---------- ------------------- ---------- -------------- ------------- ----------401 Jesse ? ? ?Cromwell ? HR_REP ? ? ? ? ? ?203 2001-05-17 00:00:00 ? ? ? 7000 ? ? ? ? ? ? ?0 ? ? ? ? ? ?40 jcromwel402 Abby ? ? ? Applegate ?IT_PROG ? ? ? ? ? 103 2001-05-17 00:00:00 ? ? ? 9000 ? ? ? ? ? ? .2 ? ? ? ? ? ?60 aapplega403 Carol ? ? ?Cousins ? ?AD_VP ? ? ? ? ? ? 100 2001-05-17 00:00:00 ? ? ?27000 ? ? ? ? ? ? .3 ? ? ? ? ? ?90 ccousins404 John ? ? ? Richardson AC_ACCOUNT ? ? ? ?205 2001-05-17 00:00:00 ? ? ? 5000 ? ? ? ? ? ? ?0 ? ? ? ? ? 110 jrichard360 Jane ? ? ? Janus ? ? ?ST_CLERK ? ? ? ? ?121 2001-05-17 00:00:00 ? ? ? 3000 ? ? ? ? ? ? ?0 ? ? ? ? ? ?50 jjanus361 Mark ? ? ? Jasper ? ? SA_REP ? ? ? ? ? ?145 2001-05-17 00:00:00 ? ? ? 8000 ? ? ? ? ? ? .1 ? ? ? ? ? ?80 mjasper362 Brenda ? ? Starr ? ? ?AD_ASST ? ? ? ? ? 200 2001-05-17 00:00:00 ? ? ? 5500 ? ? ? ? ? ? ?0 ? ? ? ? ? ?10 bstarr363 Alex ? ? ? Alda ? ? ? AC_MGR ? ? ? ? ? ?145 2001-05-17 00:00:00 ? ? ? 9000 ? ? ? ? ? ?.15 ? ? ? ? ? ?80 aalda10 rows selected.
CUUG
更多oracle視頻教程請點擊:http://crm2.qq.com/page/portalpage/wpa.php?uin=800060152&f=1&ty=1&aty=0&a=&from=6
CUUG
更多oracle視頻教程請點擊:http://crm2.qq.com/page/portalpage/wpa.php?uin=800060152&f=1&ty=1&aty=0&a=&from=6
轉載于:https://blog.51cto.com/19880614/1168945
總結
以上是生活随笔為你收集整理的Oracle教程之管理表(六)--Oracle外部表的管理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 杂而小记
- 下一篇: 西游东去 (~~创意?创新?恶搞?不置可