{"id":3231,"date":"2020-01-09T22:59:05","date_gmt":"2020-01-09T21:59:05","guid":{"rendered":"http:\/\/van-maanen.com\/?p=3231"},"modified":"2020-01-09T22:59:05","modified_gmt":"2020-01-09T21:59:05","slug":"external-table","status":"publish","type":"post","link":"http:\/\/archief.van-maanen.com\/?p=3231","title":{"rendered":"External table"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">An external table is a flat file outside the Oracle database. If properly described in Oracle, it can be read as an Oracle table.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The syntax consists of 3 elements:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>a create table part<\/li><li>an ORGANIZATION EXTERNAL part that indicates that we are discussing an external table<\/li><li>a set of attributes that discusses <ul><li>how the data are read (ORACLE_LOADER), <\/li><li>how the data are accessed &#8211; between parenthesis you find how the records are read, how the fields are separated and <\/li><li>what the fields are and <\/li><li>finally what the location is.<\/li><\/ul><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">CREATE TABLE fam_external_table\n (\n nmbr NUMBER,\n fname VARCHAR2(10),\n lname VARCHAR2(20)\n )\n ORGANIZATION EXTERNAL\n (\n TYPE ORACLE_LOADER DEFAULT DIRECTORY EXTERN\n ACCESS PARAMETERS (RECORDS DELIMITED BY NEWLINE\n FIELDS terminated BY \";\"\n REJECT ROWS WITH ALL NULL\n FIELDS(nmbr, fname,lname) )\n LOCATION ('familie.txt')\n );<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Doing so, we the data as a normal Oracle table:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"http:\/\/van-maanen.com\/wp-content\/uploads\/2020\/01\/Capture-17-2-1-1.png\" alt=\"\" class=\"wp-image-3232\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">A brilliant example is given in  <a href=\"https:\/\/asktom.oracle.com\/pls\/asktom\/asktom.search?tag=external-tables-200206\">https:\/\/asktom.oracle.com\/pls\/asktom\/asktom.search?tag=external-tables-200206<\/a> <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A nice feature is provided in SQL Developer. Via the import facility one may generate an external file. The usage is straight forward.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"http:\/\/van-maanen.com\/wp-content\/uploads\/2020\/01\/Capture-17-1-12-1-1.png\" alt=\"\" class=\"wp-image-3256\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The generated script then looks like:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" style=\"font-size:12px\">&#8211;CREATE OR REPLACE DIRECTORY EXTERNORA AS &#8216;C:\\Users\\tomva\\externora&#8217;;<br>\n&#8211;GRANT READ ON DIRECTORY EXTERNORA TO USER;<br>\n&#8211;GRANT WRITE ON DIRECTORY EXTERNORA TO USER;<br>\n&#8211;drop table PRUT;<br>\nCREATE TABLE PRUT <br>\n( EMPLOYEE_ID NUMBER(38),<br>\n  FIRST_NAME VARCHAR2(128),<br>\n  LAST_NAME VARCHAR2(128),<br>\n  EMAIL VARCHAR2(128),<br>\n  PHONE_NUMBER VARCHAR2(128),<br>\n  HIRE_DATE NUMBER(38),<br>\n  JOB_ID VARCHAR2(128),<br>\n  SALARY NUMBER(38),<br>\n  COMMISSION_PCT NUMBER(38, 2),<br>\n  MANAGER_ID NUMBER(38),<br>\n  DEPARTMENT_ID NUMBER(38))<br>\nORGANIZATION EXTERNAL<br>\n  (  TYPE ORACLE_LOADER<br>\n     DEFAULT DIRECTORY EXTERNORA<br>\n     ACCESS PARAMETERS <br>\n       (records delimited BY &#8216;\\r\\n&#8217; <br>\n           NOBADFILE<br>\n           NODISCARDFILE<br>\n           NOLOGFILE<br>\n           skip 1 <br>\n           fields terminated BY &#8216;|&#8217;<br>\n           OPTIONALLY ENCLOSED BY &#8216;&#8221;&#8216; AND &#8216;&#8221;&#8216;<br>\n           lrtrim<br>\n           missing field VALUES are NULL<br>\n           ( EMPLOYEE_ID CHAR(4000),<br>\n             FIRST_NAME CHAR(4000),<br>\n             LAST_NAME CHAR(4000),<br>\n             EMAIL CHAR(4000),<br>\n             PHONE_NUMBER CHAR(4000),<br>\n             HIRE_DATE CHAR(4000),<br>\n             JOB_ID CHAR(4000),<br>\n             SALARY CHAR(4000),<br>\n             COMMISSION_PCT CHAR(4000),<br>\n             MANAGER_ID CHAR(4000),<br>\n             DEPARTMENT_ID CHAR(4000)<br>\n           )<br>\n       )<br>\n     LOCATION (&#8216;export.csv&#8217;)<br>\n  )<br>\n  REJECT LIMIT UNLIMITED;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>An external table is a flat file outside the Oracle database. If properly described in Oracle, it can be read as an Oracle table. The syntax consists of 3 elements: a create table part an ORGANIZATION EXTERNAL part that indicates that we are discussing an external table a set of attributes that discusses how the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-3231","post","type-post","status-publish","format-standard","hentry","category-allgemein"],"_links":{"self":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/3231","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3231"}],"version-history":[{"count":0,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/3231\/revisions"}],"wp:attachment":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3231"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}