{"id":3153,"date":"2019-09-03T22:01:59","date_gmt":"2019-09-03T20:01:59","guid":{"rendered":"http:\/\/van-maanen.com\/?p=3153"},"modified":"2019-09-03T22:01:59","modified_gmt":"2019-09-03T20:01:59","slug":"oracle-writing-to-a-file","status":"publish","type":"post","link":"http:\/\/archief.van-maanen.com\/?p=3153","title":{"rendered":"Oracle: writing to a file"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Oracle has a package that allows you to write to a file. Oracle uses the concept of a directory (here &#8220;External&#8221;) that acts as a logical description of a directory. One of the properties of such directory is the physical location.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That file can be opened, written to and closed. Subsequent programme provides an example.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">create or replace PROCEDURE writeEmployee as\n  TextRecord   VARCHAR2(2000);\n  TextFile     utl_file.FILE_TYPE;\n  CURSOR EmployeeList IS\n     SELECT EName, Sal, Comm\n     FROM emp e\n     ORDER BY EName;\n  TYPE EmployeeRecordType IS RECORD\n     (EmpName   emp.EName%TYPE,\n      EmpSalary emp.Sal%TYPE,\n      Commission  emp.Comm%TYPE);\n  EmployeeRecord   EmployeeRecordType;\nBEGIN \n  OPEN EmployeeList;\n  TextFile := utl_file.fopen ('EXTERNAL', 'Employees.csv', 'w', 32767);\n  LOOP\n    FETCH EmployeeList INTO EmployeeRecord;\n    EXIT WHEN EmployeeList%NOTFOUND;\n    TextRecord := EmployeeRecord.EmpName || ',' ||\n                  EmployeeRecord.EmpSalary  || ',' ||\n                  EmployeeRecord.Commission;\n    utl_file.put_line (TextFile, TextRecord);\n  END LOOP;\n  CLOSE EmployeeList;\n  utl_file.fclose (TextFile);\nEXCEPTION\n  WHEN OTHERS THEN\n    dbms_output.put_line (sqlcode);\n    dbms_output.put_line (sqlerrm);\nEND; \n\/<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Oracle has a package that allows you to write to a file. Oracle uses the concept of a directory (here &#8220;External&#8221;) that acts as a logical description of a directory. One of the properties of such directory is the physical location. That file can be opened, written to and closed. Subsequent programme provides an example. [&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-3153","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\/3153","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=3153"}],"version-history":[{"count":0,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/3153\/revisions"}],"wp:attachment":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3153"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}