Welcome 微信登录

首页 / 数据库 / MySQL / Oracle创建外部表

Oracle db允许以只读的形式查询外部表。外部表可以存储在任何oracle db可以读取的存储设备中,其内容不在db中保存,db只保存external table的metadata,db可以查询(join、sort)external table,可以创建view、synonym,但不可以执行DML语句。创建外部表语法create table ……orginzition external,可以把外部表假想为一个view,可以正常的做select。
analyze 和 虚拟列 表分析不使用与外部表创建外部表语法
外部表文件:
example1.txt
360,Jane,Janus,ST_CLERK,121,17-MAY-2001,3000,0,50,jjanus
361,Mark,Jasper,SA_REP,145,17-MAY-2001,8000,.1,80,mjasper
362,Brenda,Starr,AD_ASST,200,17-MAY-2001,5500,0,10,bstarr
363,Alex,Alda,AC_MGR,145,17-MAY-2001,9000,.15,80,aalda
example2.txt
401,Jesse,Cromwell,HR_REP,203,17-MAY-2001,7000,0,40,jcromwel
402,Abby,Applegate,IT_PROG,103,17-MAY-2001,9000,.2,60,aapplega
403,Carol,Cousins,AD_VP,100,17-MAY-2001,27000,.3,90,ccousins
404,John,Richardson,AC_ACCOUNT,205,17-MAY-2001,5000,0,110,jrichard
创建外部表oracle可识别路径:SQL> conn / as sysdbaSQL> create directory external_dir as "/u01/app/oracle/oradata/external";Directory created.SQL> grant read,write on directory external_dir to kevin;Grant succeeded.外部表的使用用户kevin,创建外部表SQL> CREATE TABLE ex_employees2 (employee_id NUMBER(4),3first_nameVARCHAR2(20),4last_name VARCHAR2(25),5job_idVARCHAR2(10),6manager_idNUMBER(4),7hire_date DATE,8salaryNUMBER(8,2),9commission_pctNUMBER(2,2),10department_id NUMBER(4),11email VARCHAR2(25)12 )13 ORGANIZATION EXTERNAL14 (15 TYPE ORACLE_LOADER16 DEFAULT DIRECTORY external_dir17 ACCESS PARAMETERS18 (19 records delimited by newline20 badfile external_dir:"empxt%a_%p.bad"21 logfileexternal_dir:"empxt%a_%p.log"22 fields terminated by ","23 missing field values are null24 ( employee_id, first_name, last_name, job_id, manager_id,25 hire_date char date_format date mask "dd-mon-yyyy",26 salary, commission_pct, department_id, email27 )28 )29 LOCATION ("example1.txt", "example2.txt")30 )31 PARALLEL32 REJECT LIMIT UNLIMITED;Table created.创建完成后可以可以通过cats把数据导入至数据库的表中,如果数据比较多,可以开启session level parallel导入alter session enable parallel;create table employee as select * from ex_employee;EMPLOYEE_ID FIRST_NAME LAST_NAME JOB_ID MANAGER_ID HIRE_DATE SALARY COMMISSION_PCT DEPARTMENT_ID EMAIL----------- -------------------- ------------------------- ---------- ---------- --------- ---------- -------------- ------------- -------------------------360 Jane Janus ST_CLERK121 17-MAY-01 3000050 jjanus361 Mark JasperSA_REP145 17-MAY-01 8000 .180 mjasper362 Brenda Starr AD_ASST 200 17-MAY-01 5500010 bstarr363 Alex AldaAC_MGR145 17-MAY-01 9000.1580 aalda401 JesseCromwellHR_REP203 17-MAY-01 7000040 jcromwel402 Abby Applegate IT_PROG 103 17-MAY-01 9000 .260 aapplega403 CarolCousins AD_VP 100 17-MAY-0127000 .390 ccousins404 John RichardsonAC_ACCOUNT205 17-MAY-01 50000 110 jrichard10 rows selected.创建完成,外部表可以正常使用更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12本文永久更新链接地址