{"id":1087,"date":"2018-06-15T15:06:10","date_gmt":"2018-06-15T07:06:10","guid":{"rendered":"http:\/\/www.821121.com\/?p=1087"},"modified":"2020-12-15T16:12:23","modified_gmt":"2020-12-15T08:12:23","slug":"oracle-external-tables","status":"publish","type":"post","link":"http:\/\/www.821121.com\/?p=1087","title":{"rendered":"\u4f7f\u7528Oracle External\u00a0Tables\u5b9e\u73b0\u6570\u636e\u5e93\u76f4\u63a5\u8bfb\u53d6\u6587\u672c\u6587\u4ef6"},"content":{"rendered":"<p>\u5177\u4f53\u9700\u6c42\uff1a\u5c06\u4e00\u4e2atxt\u6587\u4ef6\uff0c\u5bfc\u5165\u5230oracle\u6570\u636e\u5e93<br \/>\n\u89e3\u51b3\u601d\u8def\uff1a\u4f7f\u7528Oracle External\u00a0Tables<br \/>\n\u64cd\u4f5c\u6b65\u9aa4\uff1a<br \/>\n1\uff09\u786e\u8ba4txt\u7684\u6570\u636e\uff0c\u660e\u786e\u6570\u636e\u5b57\u6bb5\u7c7b\u578b<br \/>\n[oracle@hammer ~]$ cat sh_sales.dat<br \/>\n20201215001|02|2020\/12\/15|aa|98|36|1000|3000|9999<br \/>\n\u53ef\u4ee5\u770b\u51fa\uff0c\u5404\u4e2a\u5b57\u6bb5\u7528\u201c|\u201d\u9694\u79bb\uff0c\u7b2c\u4e09\u5217\u4e3a\u65e5\u671f\u578b\u6570\u636e\uff0c\u7b2c\u56db\u5217\u4e3a\u5b57\u7b26\u578b\uff0c\u5176\u4ed6\u5747\u4e3a\u6570\u5b57\u578b\uff0c\u5176\u4e2d\u540e\u4e09\u5217\u9700\u8981\u4fdd\u75592\u4f4d\u5c0f\u6570\u70b9<br \/>\n2\uff09\u786e\u8ba4txt\u7684\u8def\u5f84<br \/>\n[oracle@hammer ~]$ pwd<br \/>\n\/home\/oracle<br \/>\n3\uff09\u521b\u5efaDIRECTORY<br \/>\nCREATE OR REPLACE DIRECTORY data_file_dir  AS '\/home\/oracle';<br \/>\nGRANT WRITE ON DIRECTORY data_file_dir TO public;<br \/>\n4\uff09\u521b\u5efa\u5916\u90e8\u8868sales_transactions_ext<br \/>\nconn system\/xxxxxx<br \/>\nCREATE TABLE sales_transactions_ext<br \/>\n(PROD_ID NUMBER,<br \/>\nCUST_ID NUMBER,<br \/>\nTIME_ID DATE,<br \/>\nCHANNEL_ID varchar2(20),<br \/>\nPROMO_ID NUMBER,<br \/>\nQUANTITY_SOLD NUMBER,<br \/>\nAMOUNT_SOLD NUMBER(10,2),<br \/>\nUNIT_COST NUMBER(10,2),<br \/>\nUNIT_PRICE NUMBER(10,2))<br \/>\nORGANIZATION external<br \/>\n(TYPE oracle_loader<br \/>\nDEFAULT DIRECTORY data_file_dir<br \/>\nACCESS PARAMETERS<br \/>\n(RECORDS DELIMITED BY NEWLINE<br \/>\nCHARACTERSET US7ASCII<br \/>\nBADFILE data_file_dir:'sh_sales.bad_xt'<br \/>\nLOGFILE data_file_dir:'sh_sales.log_xt'<br \/>\nFIELDS TERMINATED BY &quot;|&quot; LDRTRIM<br \/>\n( PROD_ID,<br \/>\nCUST_ID,<br \/>\nTIME_ID         DATE(10) &quot;YYYY\/MM\/DD&quot;,<br \/>\nCHANNEL_ID,<br \/>\nPROMO_ID,<br \/>\nQUANTITY_SOLD,<br \/>\nAMOUNT_SOLD,<br \/>\nUNIT_COST,<br \/>\nUNIT_PRICE))<br \/>\nlocation ('sh_sales.dat')<br \/>\n)REJECT LIMIT UNLIMITED;<\/p>\n<p>5\uff09\u9a8c\u8bc1<br \/>\nselect * from system.sales_transactions_ext;<br \/>\n<img decoding=\"async\" src=\"\/wp-content\/uploads\/2020\/12\/image-1608018805496.png\" alt=\"file\" \/><\/p>\n<p>\u6ce8\uff1a<\/p>\n<ol>\n<li>\u6587\u4ef6\u76ee\u5f55\u548c\u65e5\u5fd7\u76ee\u5f55\u53ef\u4ee5\u662f\u4e0d\u540c\u7684\u8def\u5f84\uff0c\u4e5f\u5c31\u662f\u591a\u5efa\u51e0\u4e2aDIRECTORY\uff0c\u672c\u5b9e\u9a8c\u4e3a\u4e86\u65b9\u4fbf\u7edf\u4e00\u6210\u4e00\u4e2a<\/li>\n<li>TXT\u6587\u4ef6\u82e5\u91c7\u7528\u5176\u4ed6\u7b26\u53f7\u4f5c\u4e3a\u5206\u9694\u7b26\uff0c\u53ef\u4ee5\u5728\u5efa\u8868\u8bed\u53e5\u7684\u8fd9\u4e2a\u4f4d\u7f6e\u8fdb\u884c\u4fee\u6539FIELDS TERMINATED BY &quot;|&quot; LDRTRIM\uff0c\u628a|\u6539\u4e3a\u5b9e\u9645\u7684\u5206\u9694\u7b26\uff0c\u6bd4\u5982\u7a7a\u683c\u6216\u8005\uff0c\u4ec0\u4e48\u7684<\/li>\n<li>\u5b98\u65b9\u6587\u6863\u91cc\u63d0\u5230\u7684\u5b9e\u9a8c\uff0c\u8fd8\u591a\u4e2a\u89e3\u538b\u7684\u64cd\u4f5c\uff0c\u5b9e\u9645\u60c5\u51b5\u4e0d\u4f1a\u90a3\u4e48\u9a9a\uff0c\u672c\u5b9e\u9a8c\u5c31\u7b80\u5316\u4e86\u3002\u5177\u4f53\u53ef\u4ee5\u53c2\u8003\u6587\u7ae0\u672b\u5c3e\u770b\u4e0b\u5b98\u6863\u3002<\/li>\n<li>\u5916\u90e8\u6587\u4ef6\u662f\u53ea\u8bfb\u7684<\/li>\n<\/ol>\n<p>\u53ef\u53c2\u800311g\u5b98\u65b9\u6587\u6863<br \/>\nAdministrator's Guide--&gt;20\u00a0Managing\u00a0Tables--&gt;Managing\u00a0External\u00a0Tables<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5177\u4f53\u9700\u6c42\uff1a\u5c06\u4e00\u4e2atxt\u6587\u4ef6\uff0c\u5bfc\u5165\u5230oracle\u6570\u636e<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,40],"tags":[],"class_list":["post-1087","post","type-post","status-publish","format-standard","hentry","category-oracle-11g","category--oracle-11g"],"_links":{"self":[{"href":"http:\/\/www.821121.com\/index.php?rest_route=\/wp\/v2\/posts\/1087","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.821121.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.821121.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.821121.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.821121.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1087"}],"version-history":[{"count":3,"href":"http:\/\/www.821121.com\/index.php?rest_route=\/wp\/v2\/posts\/1087\/revisions"}],"predecessor-version":[{"id":1102,"href":"http:\/\/www.821121.com\/index.php?rest_route=\/wp\/v2\/posts\/1087\/revisions\/1102"}],"wp:attachment":[{"href":"http:\/\/www.821121.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1087"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.821121.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1087"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.821121.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1087"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}