{"id":3249,"date":"2020-01-16T11:54:15","date_gmt":"2020-01-16T10:54:15","guid":{"rendered":"http:\/\/van-maanen.com\/?p=3249"},"modified":"2020-01-16T11:54:15","modified_gmt":"2020-01-16T10:54:15","slug":"oracle-create-loader-file","status":"publish","type":"post","link":"http:\/\/archief.van-maanen.com\/?p=3249","title":{"rendered":"Oracle create loader file"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Creating a loader file is tedious. The syntax is complicated. Moreover, small errors lead to a rejection of records. Luckily, we have the possibility to generate them from SQL Developer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One possibility is to use the SQL Loader. This facility has an import\/ export module that allows to create such files.  If one would like to export data to have them imported elsewhere, one may use the export facility with subsequent parameters:<\/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-8-1-1.png\" alt=\"\" class=\"wp-image-3250\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">One then gets a control file that looks like:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">OPTIONS (ERRORS=50)\nLOAD DATA \nINFILE 'C:\\Users\\tmaanen\\Downloads\\EMPLOYEES_BU_DATA_TABLE_1.ldr' \"str '\\r\\n'\"\nAPPEND\nCONTINUEIF NEXT(1:1) = '#'\nINTO TABLE \"HR\".\"EMPLOYEES_BU\"\nFIELDS TERMINATED BY'|'\nOPTIONALLY ENCLOSED BY '\"' AND '\"'\nTRAILING NULLCOLS ( \n\"EMPLOYEE_ID\" ,\n\"FIRST_NAME\" CHAR (20),\n\"LAST_NAME\" CHAR (25),\n\"EMAIL\" CHAR (25),\n\"PHONE_NUMBER\" CHAR (20),\n\"HIRE_DATE\" DATE \"YYYY-MM-DD HH24:MI:SS\" ,\n\"JOB_ID\" CHAR (10),\n\"SALARY\" ,\n\"COMMISSION_PCT\" ,\n\"MANAGER_ID\" ,\n\"DEPARTMENT_ID\" )<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">I then truncated the table to see if the system works. I fired a command to load the records. I got:<\/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-9-1-1.png\" alt=\"\" class=\"wp-image-3251\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Success.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Another possibility is to use the import  facility. This is useful if one has a dataset for which a SQL Loader script is requested. One has several screens. One of them allows to select the SQL Loader.<\/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-10-1-1.png\" alt=\"\" class=\"wp-image-3252\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The generated script is:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">load data \ninfile 'export.csv' \"str '\\r\\n'\"\nappend\ninto table FLIP\nfields terminated by '|'\nOPTIONALLY ENCLOSED BY '\"' AND '\"'\ntrailing nullcols\n           ( EMPLOYEE_ID,\n             FIRST_NAME CHAR(4000),\n             LAST_NAME CHAR(4000),\n             EMAIL CHAR(4000),\n             PHONE_NUMBER CHAR(4000),\n             HIRE_DATE DATE \"RRRRMMDD\",\n             JOB_ID CHAR(4000),\n             SALARY,\n             COMMISSION_PCT,\n             MANAGER_ID,\n             DEPARTMENT_ID\n           )<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This can be executed with desired results:<\/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-11-1-1.png\" alt=\"\" class=\"wp-image-3253\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Creating a loader file is tedious. The syntax is complicated. Moreover, small errors lead to a rejection of records. Luckily, we have the possibility to generate them from SQL Developer. One possibility is to use the SQL Loader. This facility has an import\/ export module that allows to create such files. If one would like [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-3249","post","type-post","status-publish","format-standard","hentry","category-data-warehousing"],"_links":{"self":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/3249","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=3249"}],"version-history":[{"count":0,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/3249\/revisions"}],"wp:attachment":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3249"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3249"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}