{"id":4621,"date":"2014-03-18T18:29:05","date_gmt":"2014-03-18T12:59:05","guid":{"rendered":"http:\/\/erpschools.com\/?p=4621"},"modified":"2014-12-26T08:59:37","modified_gmt":"2014-12-26T08:59:37","slug":"utl_file-write-example","status":"publish","type":"post","link":"https:\/\/erpschools.com\/erps\/scripts\/utl_file\/utl_file-write-example","title":{"rendered":"UTL_FILE Write Example"},"content":{"rendered":"<p>The below example illustrates how to write a line to a file using UTL_FILE.<\/p>\n<p>1. Create Directory on your server (ex: Linux, Unix)<br \/>\n2. Give writable permissions to the directory created. If you register this code as a concurrent program then you need to make sure your applmgr user has write permissions to this directory.<br \/>\n3. Create DIRECTORY object in database using below command. This is different from the physical directory you created in step1.<\/p>\n<p><code><br \/>\nCREATE OR REPLACE DIRECTORY ERPS_OUT_DIR AS '\/home\/haritha'<br \/>\n<\/code><\/p>\n<p>You can see the existing directory objects using below query<br \/>\n<code><br \/>\nselect * from dba_directories;<br \/>\n<\/code><\/p>\n<p>UTL_FILE Write Example:<br \/>\n<code><br \/>\nDECLARE<br \/>\nl_file_handler UTL_FILE.FILE_TYPE;<br \/>\nl_txt VARCHAR2(1000) := 'Demo to write to a file using UTL_FILE';<br \/>\nl_file_name VARCHAR2(50) := 'ERPSFILE.txt';<br \/>\nBEGIN<\/code><\/p>\n<p>&#8211;Open the file in Write mode<br \/>\nl_file_handler := UTL_FILE.FOPEN(&#8216;ERPS_OUT_DIR&#8217;,l_file_name,&#8217;W&#8217;);<\/p>\n<p>&#8211;Write to the file<br \/>\nUTL_FILE.Put_LINE(l_file_handler,l_txt);<\/p>\n<p>&#8211;Once the writing is done, close the file<br \/>\nIF UTL_FILE.IS_OPEN(l_file_handler) THEN<br \/>\nUTL_FILE.FCLOSE(l_file_handler);<br \/>\nEND IF;<\/p>\n<p>EXCEPTION<\/p>\n<p>WHEN UTL_FILE.invalid_mode THEN<br \/>\nraise_application_error (-20051, &#8216;Invalid Mode Parameter&#8217;);<\/p>\n<p>WHEN UTL_FILE.invalid_path THEN<br \/>\nraise_application_error (-20052, &#8216;Invalid File Location&#8217;);<\/p>\n<p>WHEN UTL_FILE.invalid_filehandle THEN<br \/>\nraise_application_error (-20053, &#8216;Invalid Filehandle&#8217;);<\/p>\n<p>WHEN UTL_FILE.invalid_operation THEN<br \/>\nraise_application_error (-20054, &#8216;Invalid Operation&#8217;);<\/p>\n<p>WHEN UTL_FILE.write_error THEN<br \/>\nraise_application_error (-20055, &#8216;Write Error&#8217;);<\/p>\n<p>WHEN UTL_FILE.internal_error THEN<br \/>\nraise_application_error (-20057, &#8216;Internal Error&#8217;);<\/p>\n<p>WHEN UTL_FILE.charsetmismatch THEN<br \/>\nraise_application_error (-20058, &#8216;Opened With FOPEN_NCHAR But Later I\/O Inconsistent&#8217;);<\/p>\n<p>WHEN UTL_FILE.file_open THEN<br \/>\nraise_application_error (-20059, &#8216;File Already Opened&#8217;);<\/p>\n<p>WHEN UTL_FILE.invalid_maxlinesize THEN<br \/>\nraise_application_error (-20060, &#8216;Line Size Exceeds 32K&#8217;);<\/p>\n<p>WHEN UTL_FILE.invalid_filename THEN<br \/>\nraise_application_error (-20061, &#8216;Invalid File Name&#8217;);<\/p>\n<p>WHEN UTL_FILE.access_denied THEN<br \/>\nraise_application_error (-20062, &#8216;File Access Denied By&#8217;);<\/p>\n<p>WHEN UTL_FILE.invalid_offset THEN<br \/>\nraise_application_error (-20063, &#8216;FSEEK Param Less Than 0&#8217;);<\/p>\n<p>WHEN OTHERS THEN<br \/>\nraise_application_error (-20099, &#8216;Unknown UTL_FILE Error&#8217;||sqlerrm);<\/p>\n<p>END;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The below example illustrates how to write a line to a file using UTL_FILE. 1. Create Directory on your server (ex: Linux, Unix) 2. Give writable permissions to the directory created. If you register this code as a concurrent program then you need to make sure your applmgr user has write permissions to this directory. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[518],"tags":[206,207],"class_list":["post-4621","post","type-post","status-publish","format-standard","hentry","category-utl_file","tag-utl_file","tag-write"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>UTL_FILE Write Example - erpSchools<\/title>\n<meta name=\"description\" content=\"UTL_FILE Write Example\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/erpschools.com\/erps\/scripts\/utl_file\/utl_file-write-example\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prudhvi\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/erpschools.com\/erps\/scripts\/utl_file\/utl_file-write-example#article\",\"isPartOf\":{\"@id\":\"https:\/\/erpschools.com\/erps\/scripts\/utl_file\/utl_file-write-example\"},\"author\":{\"name\":\"Prudhvi\",\"@id\":\"https:\/\/erpschools.com\/erps\/#\/schema\/person\/dbed9bb7fb66aa7a700fc565da024512\"},\"headline\":\"UTL_FILE Write Example\",\"datePublished\":\"2014-03-18T12:59:05+00:00\",\"dateModified\":\"2014-12-26T08:59:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/erpschools.com\/erps\/scripts\/utl_file\/utl_file-write-example\"},\"wordCount\":323,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/erpschools.com\/erps\/#organization\"},\"keywords\":[\"UTL_FILE\",\"WRITE\"],\"articleSection\":[\"UTL_FILE\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/erpschools.com\/erps\/scripts\/utl_file\/utl_file-write-example#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/erpschools.com\/erps\/scripts\/utl_file\/utl_file-write-example\",\"url\":\"https:\/\/erpschools.com\/erps\/scripts\/utl_file\/utl_file-write-example\",\"name\":\"UTL_FILE Write Example - erpSchools\",\"isPartOf\":{\"@id\":\"https:\/\/erpschools.com\/erps\/#website\"},\"datePublished\":\"2014-03-18T12:59:05+00:00\",\"dateModified\":\"2014-12-26T08:59:37+00:00\",\"description\":\"UTL_FILE Write Example\",\"breadcrumb\":{\"@id\":\"https:\/\/erpschools.com\/erps\/scripts\/utl_file\/utl_file-write-example#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/erpschools.com\/erps\/scripts\/utl_file\/utl_file-write-example\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/erpschools.com\/erps\/scripts\/utl_file\/utl_file-write-example#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/erpschools.com\/erps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"UTL_FILE Write Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/erpschools.com\/erps\/#website\",\"url\":\"https:\/\/erpschools.com\/erps\/\",\"name\":\"erpSchools\",\"description\":\"Oracle Apps\",\"publisher\":{\"@id\":\"https:\/\/erpschools.com\/erps\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/erpschools.com\/erps\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/erpschools.com\/erps\/#organization\",\"name\":\"erpSchools\",\"url\":\"https:\/\/erpschools.com\/erps\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/erpschools.com\/erps\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/erpschools.com\/erps\/wp-content\/uploads\/img\/erps_logo7.png\",\"contentUrl\":\"https:\/\/erpschools.com\/erps\/wp-content\/uploads\/img\/erps_logo7.png\",\"width\":250,\"height\":60,\"caption\":\"erpSchools\"},\"image\":{\"@id\":\"https:\/\/erpschools.com\/erps\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"http:\/\/facebook.com\/erpschools\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/erpschools.com\/erps\/#\/schema\/person\/dbed9bb7fb66aa7a700fc565da024512\",\"name\":\"Prudhvi\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/erpschools.com\/erps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/488cec3605845b95cb20e60c67a8f5c7e74b65a305525c8006315d524f120db9?s=96&d=blank&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/488cec3605845b95cb20e60c67a8f5c7e74b65a305525c8006315d524f120db9?s=96&d=blank&r=g\",\"caption\":\"Prudhvi\"},\"sameAs\":[\"http:\/\/www.erpschools.com\"],\"url\":\"https:\/\/erpschools.com\/erps\/author\/prudhvi\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"UTL_FILE Write Example - erpSchools","description":"UTL_FILE Write Example","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/erpschools.com\/erps\/scripts\/utl_file\/utl_file-write-example","twitter_misc":{"Written by":"Prudhvi","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/erpschools.com\/erps\/scripts\/utl_file\/utl_file-write-example#article","isPartOf":{"@id":"https:\/\/erpschools.com\/erps\/scripts\/utl_file\/utl_file-write-example"},"author":{"name":"Prudhvi","@id":"https:\/\/erpschools.com\/erps\/#\/schema\/person\/dbed9bb7fb66aa7a700fc565da024512"},"headline":"UTL_FILE Write Example","datePublished":"2014-03-18T12:59:05+00:00","dateModified":"2014-12-26T08:59:37+00:00","mainEntityOfPage":{"@id":"https:\/\/erpschools.com\/erps\/scripts\/utl_file\/utl_file-write-example"},"wordCount":323,"commentCount":0,"publisher":{"@id":"https:\/\/erpschools.com\/erps\/#organization"},"keywords":["UTL_FILE","WRITE"],"articleSection":["UTL_FILE"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/erpschools.com\/erps\/scripts\/utl_file\/utl_file-write-example#respond"]}]},{"@type":"WebPage","@id":"https:\/\/erpschools.com\/erps\/scripts\/utl_file\/utl_file-write-example","url":"https:\/\/erpschools.com\/erps\/scripts\/utl_file\/utl_file-write-example","name":"UTL_FILE Write Example - erpSchools","isPartOf":{"@id":"https:\/\/erpschools.com\/erps\/#website"},"datePublished":"2014-03-18T12:59:05+00:00","dateModified":"2014-12-26T08:59:37+00:00","description":"UTL_FILE Write Example","breadcrumb":{"@id":"https:\/\/erpschools.com\/erps\/scripts\/utl_file\/utl_file-write-example#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/erpschools.com\/erps\/scripts\/utl_file\/utl_file-write-example"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/erpschools.com\/erps\/scripts\/utl_file\/utl_file-write-example#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/erpschools.com\/erps"},{"@type":"ListItem","position":2,"name":"UTL_FILE Write Example"}]},{"@type":"WebSite","@id":"https:\/\/erpschools.com\/erps\/#website","url":"https:\/\/erpschools.com\/erps\/","name":"erpSchools","description":"Oracle Apps","publisher":{"@id":"https:\/\/erpschools.com\/erps\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/erpschools.com\/erps\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/erpschools.com\/erps\/#organization","name":"erpSchools","url":"https:\/\/erpschools.com\/erps\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/erpschools.com\/erps\/#\/schema\/logo\/image\/","url":"https:\/\/erpschools.com\/erps\/wp-content\/uploads\/img\/erps_logo7.png","contentUrl":"https:\/\/erpschools.com\/erps\/wp-content\/uploads\/img\/erps_logo7.png","width":250,"height":60,"caption":"erpSchools"},"image":{"@id":"https:\/\/erpschools.com\/erps\/#\/schema\/logo\/image\/"},"sameAs":["http:\/\/facebook.com\/erpschools"]},{"@type":"Person","@id":"https:\/\/erpschools.com\/erps\/#\/schema\/person\/dbed9bb7fb66aa7a700fc565da024512","name":"Prudhvi","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/erpschools.com\/erps\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/488cec3605845b95cb20e60c67a8f5c7e74b65a305525c8006315d524f120db9?s=96&d=blank&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/488cec3605845b95cb20e60c67a8f5c7e74b65a305525c8006315d524f120db9?s=96&d=blank&r=g","caption":"Prudhvi"},"sameAs":["http:\/\/www.erpschools.com"],"url":"https:\/\/erpschools.com\/erps\/author\/prudhvi"}]}},"_links":{"self":[{"href":"https:\/\/erpschools.com\/erps\/wp-json\/wp\/v2\/posts\/4621","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/erpschools.com\/erps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/erpschools.com\/erps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/erpschools.com\/erps\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/erpschools.com\/erps\/wp-json\/wp\/v2\/comments?post=4621"}],"version-history":[{"count":0,"href":"https:\/\/erpschools.com\/erps\/wp-json\/wp\/v2\/posts\/4621\/revisions"}],"wp:attachment":[{"href":"https:\/\/erpschools.com\/erps\/wp-json\/wp\/v2\/media?parent=4621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/erpschools.com\/erps\/wp-json\/wp\/v2\/categories?post=4621"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/erpschools.com\/erps\/wp-json\/wp\/v2\/tags?post=4621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}