{"id":2682,"date":"2019-02-17T22:10:25","date_gmt":"2019-02-17T21:10:25","guid":{"rendered":"http:\/\/van-maanen.com\/?p=2682"},"modified":"2019-02-17T22:10:25","modified_gmt":"2019-02-17T21:10:25","slug":"writing-content-from-oracle","status":"publish","type":"post","link":"http:\/\/archief.van-maanen.com\/?p=2682","title":{"rendered":"Writing content from Oracle"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This note provides a PL\/SQL programme that writes the the content of a table to a file. It also uses a steering table (emp_ids) that contains a series of ids that can be used in a susequent query from which the content can be generated.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let me first provide the code:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">create or replace PROCEDURE print_emp_name_dpmt AS<br>   CURSOR id_cur<br>   IS SELECT distinct department_id  FROM HR.emp_ids;<br>   emp_rec id_cur%ROWTYPE;<br>   CURSOR id_dpt <br>   IS SELECT employee_id, first_name FROM employees WHERE department_id = emp_rec.department_id;<br>   dpt_rec id_dpt%ROWTYPE;<br> BEGIN<br>  OPEN id_cur;<br>  LOOP<br>    FETCH id_cur INTO emp_rec;<br>    EXIT WHEN id_cur%NOTFOUND;<br>    OPEN id_dpt;<br>    LOOP<br>      FETCH id_dpt INTO dpt_rec;<br>      EXIT WHEN id_dpt%NOTFOUND;<br>      dbms_output.put_line('The employee ' || dpt_rec.first_name ||';'||emp_rec.department_id||';'||dpt_rec.employee_id);<br>    END LOOP;<br>    CLOSE id_dpt;<br>  END LOOP;<br> END;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">I created two cursors. One cursor contains the query outcomes from the steering table. A second cursor contains the outcomes from a query that must be written to a file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The two cursors are interwoven in two loops. Each loop fetches a record from a query. In the centre, the results are written.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If one executes this PL\/SQL procedure in SQL plus with a spool on-command, one captures the results.  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>This note provides a PL\/SQL programme that writes the the content of a table to a file. It also uses a steering table (emp_ids) that contains a series of ids that can be used in a susequent query from which the content can be generated. Let me first provide the code: create or replace PROCEDURE [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-2682","post","type-post","status-publish","format-standard","hentry","category-nice-to-know"],"_links":{"self":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/2682","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=2682"}],"version-history":[{"count":0,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/2682\/revisions"}],"wp:attachment":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2682"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}