{"id":111,"date":"2011-07-03T19:50:34","date_gmt":"2011-07-03T16:50:34","guid":{"rendered":"http:\/\/fatihacar.com\/blog\/?p=111"},"modified":"2011-07-05T03:14:16","modified_gmt":"2011-07-05T00:14:16","slug":"xml-file-export-with-stored-procedure-in-oracle","status":"publish","type":"post","link":"https:\/\/www.fatihacar.com\/blog\/xml-file-export-with-stored-procedure-in-oracle\/","title":{"rendered":"XML file export with stored procedure in Oracle"},"content":{"rendered":"<p>This example provides export xml file. You must create a directory before create procedure. After, you must give grant for user. Finally, You can create procedure and execute.<\/p>\n<p><strong>Create Directory and Grant<\/strong><\/p>\n<blockquote><p>\nYou must be sys user and can execute this queries;<\/p>\n<p>CREATE DIRECTORY XMLDUMP AS &#8216;C:\\XmlDirectoryFileName&#8217;;<br \/>\nSELECT * FROM DBA_DIRECTORIES;<br \/>\nGRANT READ,WRITE ON DIRECTORY XMLDUMP TO HR;<\/p><\/blockquote>\n<p><strong>Create Procedure<\/strong><\/p>\n<blockquote><p>CREATE OR REPLACE PROCEDURE PR_XMLEXPORT<br \/>\nIS<br \/>\nCURSOR CRS IS<br \/>\nSELECT first_name,last_name,salary FROM employees;<\/p>\n<p>REC CRS%ROWTYPE;<br \/>\nXML_CONTENT  VARCHAR2(10000) := &#8221;;<br \/>\nFILENAME varchar2(100) := &#8217;employees_salary.xml&#8217;;<br \/>\nFILEWRITE UTL_FILE.FILE_TYPE;<\/p>\n<p>BEGIN<\/p>\n<p>    OPEN CRS;<\/p>\n<p>    XML_CONTENT := XML_CONTENT || &#8216;< ?xml version=\"1.0\" encoding=\"ISO-8859-9\" ? ><employees>&#8216;;<\/p>\n<p>        LOOP<br \/>\n            FETCH  CRS INTO REC;<br \/>\n            EXIT WHEN CRS%NOTFOUND;<\/p>\n<p>            XML_CONTENT := XML_CONTENT || &#8216;< employee>&#8216;;<br \/>\n            XML_CONTENT := XML_CONTENT || &#8216;< first_name>&#8216;||TO_CHAR(REC.FIRST_NAME)||&#8217;< \/first_name>&#8216;;<br \/>\n            XML_CONTENT := XML_CONTENT || &#8216;< last_name>&#8216;||TO_CHAR(REC.LAST_NAME)||&#8217;< \/last_name>&#8216;;<br \/>\n            XML_CONTENT := XML_CONTENT || &#8216;< salary>&#8216;||TO_CHAR(REC.SALARY)||&#8217;< \/salary>&#8216;;<br \/>\n            XML_CONTENT := XML_CONTENT || &#8216;< \/employee>&#8216;;<\/p>\n<p>        END LOOP;<\/p>\n<p>    XML_CONTENT := XML_CONTENT || &#8216;< \/employees >&#8216;;<\/p>\n<p>    FILEWRITE := UTL_FILE.FOPEN(&#8216;XMLDUMP&#8217;,&#8217;sehirleregorenes.xml&#8217;,&#8217;w&#8217;,32767);<br \/>\n    UTL_FILE.PUTF(FILEWRITE,XML_CONTENT);<br \/>\n    UTL_FILE.FCLOSE(FILEWRITE);<\/p>\n<p>    COMMIT;<\/p>\n<p>    CLOSE CRS;<\/p>\n<p>END;<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>This example provides export xml file. You must create a directory before create procedure. After, you must give grant for user. Finally, You can create procedure and execute. Create Directory and Grant You must be sys user and can execute this queries; CREATE DIRECTORY XMLDUMP AS &#8216;C:\\XmlDirectoryFileName&#8217;; SELECT * FROM DBA_DIRECTORIES; GRANT READ,WRITE ON DIRECTORY&#8230;<\/p>\n","protected":false},"author":37,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[12],"tags":[90,91,13],"class_list":["post-111","post","type-post","status-publish","format-standard","hentry","category-oracle-procedure","tag-oracle","tag-oracle-sql","tag-stored-procedure"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p39NFI-1N","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/users\/37"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/comments?post=111"}],"version-history":[{"count":16,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/111\/revisions"}],"predecessor-version":[{"id":113,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/111\/revisions\/113"}],"wp:attachment":[{"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/media?parent=111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/categories?post=111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/tags?post=111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}