{"id":1673,"date":"2018-08-15T07:58:07","date_gmt":"2018-08-15T07:58:07","guid":{"rendered":"https:\/\/vinish.dev\/?p=1673"},"modified":"2025-04-16T19:49:15","modified_gmt":"2025-04-16T14:19:15","slug":"how-to-split-a-string-in-pl-sql","status":"publish","type":"post","link":"https:\/\/vinish.dev\/how-to-split-a-string-in-pl-sql","title":{"rendered":"How to Split a String in PL\/SQL?"},"content":{"rendered":"<p>In this article, I am giving an example of a function which I mostly use to split a string in PL\/SQL. Especially, when I am writing a program to import a delimited file. Here are that function and an example of how to use it.<\/p>\n<h3>PL\/SQL Function to Split a String<\/h3>\n<p>This function takes four parameters, and the details of these parameters are as under:<\/p>\n<ol>\n<li><strong>Source_String<\/strong>: String to Split<\/li>\n<li><strong>Field_Position<\/strong>: Delimiter Position<\/li>\n<li><strong>UnTerminated<\/strong>: False by default, but if you pass True, then it will add the specified delimiter at the end of the string.<\/li>\n<li><strong>Delimiter<\/strong>: Default is Comma ',', you can pass any other delimiter.<\/li>\n<\/ol>\n<pre>CREATE OR REPLACE FUNCTION GetString (\r\nSource_string IN VARCHAR2,\r\nField_position IN NUMBER,\r\nUnTerminated IN BOOLEAN DEFAULT FALSE,\r\nDelimiter IN VARCHAR2 DEFAULT ',')\r\nRETURN VARCHAR2\r\nIS\r\niPtrEnd PLS_INTEGER := 0;\r\niPtrStart PLS_INTEGER := 0;\r\nvcSourceStrCopy VARCHAR2 (4000) := Source_string;\r\nBEGIN\r\nIF UnTerminated\r\nTHEN\r\nvcSourceStrCopy := vcSourceStrCopy || Delimiter;\r\nEND IF;\r\n\r\nIF Field_Position &gt; 1\r\nTHEN\r\niPtrStart :=\r\nINSTR (vcSourceStrCopy,\r\nDelimiter,\r\n1,\r\nField_Position - 1)\r\n+ LENGTH (Delimiter);\r\nELSE\r\niPtrStart := 1;\r\nEND IF;\r\n\r\niPtrEnd :=\r\nINSTR (vcSourceStrCopy,\r\nDelimiter,\r\n1,\r\nField_Position);\r\nRETURN SUBSTR (vcSourceStrCopy, iPtrStart, (iPtrEnd - iPtrStart));\r\nEND GetString;<\/pre>\n<h3>Example: Use This Function in PL\/SQL Program<\/h3>\n<pre>SET SERVEROUTPUT ON;\r\n\r\nDECLARE\r\n   v_string      VARCHAR2 (1000) := 'Java|.Net|C|Oracle|PHP';\r\n\r\n   TYPE t_string IS TABLE OF VARCHAR2 (1000)\r\n                       INDEX BY BINARY_INTEGER;\r\n\r\n   t_str_array   t_string;\r\nBEGIN\r\n   FOR i IN 1 .. 5\r\n   LOOP\r\n      t_str_array (i) :=\r\n         getstring (v_string,\r\n                    i,\r\n                    TRUE,\r\n                    '|');\r\n   END LOOP;\r\n\r\n   FOR j IN t_str_array.FIRST .. t_str_array.LAST\r\n   LOOP\r\n      DBMS_OUTPUT.put_Line (t_str_array (j));\r\n   END LOOP;\r\nEND;\r\n\/<\/pre>\n<h4>Output:<\/h4>\n<pre>Java\r\n.Net\r\nC\r\nOracle\r\nPHP\r\nPL\/SQL procedure successfully completed.<\/pre>\n<h4>See also:<\/h4>\n<ul>\n<li><a href=\"https:\/\/vinish.dev\/export-data-into-json-file-in-oracle-11g-using-pl-sql\">Export Data into JSON using PL\/SQL in Oracle 11g<\/a><\/li>\n<li><a href=\"https:\/\/vinish.dev\/pl-sql-program-to-print-employee-details\">PL\/SQL Program to Print Employee details<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In this article, I am giving an example of a function which I mostly use to split a string in PL\/SQL. Especially, when I am writing a program to import a delimited file. Here are that function and an example of how to use it. PL\/SQL Function to Split a String This function takes four [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-1673","post","type-post","status-publish","format-standard","hentry","category-plsql"],"blocksy_meta":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Split a String in PL\/SQL? &#8226; Vinish.Dev<\/title>\n<meta name=\"description\" content=\"In this article, a PL\/SQL function example is given to split a string with any delimiter.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/vinish.dev\/how-to-split-a-string-in-pl-sql\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Split a String in PL\/SQL? &#8226; Vinish.Dev\" \/>\n<meta property=\"og:description\" content=\"In this article, a PL\/SQL function example is given to split a string with any delimiter.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/vinish.dev\/how-to-split-a-string-in-pl-sql\" \/>\n<meta property=\"og:site_name\" content=\"Vinish.Dev\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/foxinfotech2014\" \/>\n<meta property=\"article:published_time\" content=\"2018-08-15T07:58:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-16T14:19:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/vinish.dev\/wp-content\/uploads\/2024\/09\/homepage-vinish.dev_.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"693\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Vinish Kapoor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/x.com\/vinish_kapoor\" \/>\n<meta name=\"twitter:site\" content=\"@foxinfotech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Vinish Kapoor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/vinish.dev\\\/how-to-split-a-string-in-pl-sql#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vinish.dev\\\/how-to-split-a-string-in-pl-sql\"},\"author\":{\"name\":\"Vinish Kapoor\",\"@id\":\"https:\\\/\\\/vinish.dev\\\/#\\\/schema\\\/person\\\/a7790479716d2a54131ca873f8483d3f\"},\"headline\":\"How to Split a String in PL\\\/SQL?\",\"datePublished\":\"2018-08-15T07:58:07+00:00\",\"dateModified\":\"2025-04-16T14:19:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/vinish.dev\\\/how-to-split-a-string-in-pl-sql\"},\"wordCount\":144,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/vinish.dev\\\/#\\\/schema\\\/person\\\/df5e5ca816f6f4302efc03cf58dc97b4\"},\"articleSection\":[\"PLSQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/vinish.dev\\\/how-to-split-a-string-in-pl-sql#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/vinish.dev\\\/how-to-split-a-string-in-pl-sql\",\"url\":\"https:\\\/\\\/vinish.dev\\\/how-to-split-a-string-in-pl-sql\",\"name\":\"How to Split a String in PL\\\/SQL? &#8226; Vinish.Dev\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vinish.dev\\\/#website\"},\"datePublished\":\"2018-08-15T07:58:07+00:00\",\"dateModified\":\"2025-04-16T14:19:15+00:00\",\"description\":\"In this article, a PL\\\/SQL function example is given to split a string with any delimiter.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/vinish.dev\\\/how-to-split-a-string-in-pl-sql#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/vinish.dev\\\/how-to-split-a-string-in-pl-sql\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/vinish.dev\\\/how-to-split-a-string-in-pl-sql#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/vinish.dev\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PLSQL\",\"item\":\"https:\\\/\\\/vinish.dev\\\/category\\\/plsql\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How to Split a String in PL\\\/SQL?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/vinish.dev\\\/#website\",\"url\":\"https:\\\/\\\/vinish.dev\\\/\",\"name\":\"Vinish.Dev\",\"description\":\"Vinish Kapoor&#039;s Blog: Best Oracle Blog for Developers\",\"publisher\":{\"@id\":\"https:\\\/\\\/vinish.dev\\\/#\\\/schema\\\/person\\\/df5e5ca816f6f4302efc03cf58dc97b4\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/vinish.dev\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/vinish.dev\\\/#\\\/schema\\\/person\\\/df5e5ca816f6f4302efc03cf58dc97b4\",\"name\":\"Vinish Kapoor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/vinish.dev\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/vinishprofile.png\",\"url\":\"https:\\\/\\\/vinish.dev\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/vinishprofile.png\",\"contentUrl\":\"https:\\\/\\\/vinish.dev\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/vinishprofile.png\",\"width\":192,\"height\":192,\"caption\":\"Vinish Kapoor\"},\"logo\":{\"@id\":\"https:\\\/\\\/vinish.dev\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/vinishprofile.png\"},\"description\":\"Vinish Kapoor is a seasoned software development professional and a fervent enthusiast of artificial intelligence (AI). His impressive career spans over 25+ years, marked by a relentless pursuit of innovation and excellence in the field of information technology. As an Oracle ACE, Vinish has distinguished himself as a leading expert in Oracle technologies, a title awarded to individuals who have demonstrated their deep commitment, leadership, and expertise in the Oracle community.\",\"sameAs\":[\"https:\\\/\\\/vinish.dev\\\/\",\"https:\\\/\\\/www.facebook.com\\\/foxinfotech2014\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/vinish-kapoor\\\/\",\"https:\\\/\\\/x.com\\\/foxinfotech\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/vinish.dev\\\/#\\\/schema\\\/person\\\/a7790479716d2a54131ca873f8483d3f\",\"name\":\"Vinish Kapoor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a67232caa79b11f24f16c371866a96cfb575e011ebda6fa6e3d088a837a31bde?s=96&d=identicon&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a67232caa79b11f24f16c371866a96cfb575e011ebda6fa6e3d088a837a31bde?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a67232caa79b11f24f16c371866a96cfb575e011ebda6fa6e3d088a837a31bde?s=96&d=identicon&r=g\",\"caption\":\"Vinish Kapoor\"},\"description\":\"Vinish Kapoor is a seasoned software development professional and a fervent enthusiast of artificial intelligence (AI). His impressive career spans over 25+ years, marked by a relentless pursuit of innovation and excellence in the field of information technology. As an Oracle ACE, Vinish has distinguished himself as a leading expert in Oracle technologies, a title awarded to individuals who have demonstrated their deep commitment, leadership, and expertise in the Oracle community.\",\"sameAs\":[\"https:\\\/\\\/vinish.dev\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/vinish-kapoor\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/x.com\\\/vinish_kapoor\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Split a String in PL\/SQL? &#8226; Vinish.Dev","description":"In this article, a PL\/SQL function example is given to split a string with any delimiter.","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:\/\/vinish.dev\/how-to-split-a-string-in-pl-sql","og_locale":"en_US","og_type":"article","og_title":"How to Split a String in PL\/SQL? &#8226; Vinish.Dev","og_description":"In this article, a PL\/SQL function example is given to split a string with any delimiter.","og_url":"https:\/\/vinish.dev\/how-to-split-a-string-in-pl-sql","og_site_name":"Vinish.Dev","article_publisher":"https:\/\/www.facebook.com\/foxinfotech2014","article_published_time":"2018-08-15T07:58:07+00:00","article_modified_time":"2025-04-16T14:19:15+00:00","og_image":[{"width":1200,"height":693,"url":"https:\/\/vinish.dev\/wp-content\/uploads\/2024\/09\/homepage-vinish.dev_.png","type":"image\/png"}],"author":"Vinish Kapoor","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/x.com\/vinish_kapoor","twitter_site":"@foxinfotech","twitter_misc":{"Written by":"Vinish Kapoor","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/vinish.dev\/how-to-split-a-string-in-pl-sql#article","isPartOf":{"@id":"https:\/\/vinish.dev\/how-to-split-a-string-in-pl-sql"},"author":{"name":"Vinish Kapoor","@id":"https:\/\/vinish.dev\/#\/schema\/person\/a7790479716d2a54131ca873f8483d3f"},"headline":"How to Split a String in PL\/SQL?","datePublished":"2018-08-15T07:58:07+00:00","dateModified":"2025-04-16T14:19:15+00:00","mainEntityOfPage":{"@id":"https:\/\/vinish.dev\/how-to-split-a-string-in-pl-sql"},"wordCount":144,"commentCount":0,"publisher":{"@id":"https:\/\/vinish.dev\/#\/schema\/person\/df5e5ca816f6f4302efc03cf58dc97b4"},"articleSection":["PLSQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/vinish.dev\/how-to-split-a-string-in-pl-sql#respond"]}]},{"@type":"WebPage","@id":"https:\/\/vinish.dev\/how-to-split-a-string-in-pl-sql","url":"https:\/\/vinish.dev\/how-to-split-a-string-in-pl-sql","name":"How to Split a String in PL\/SQL? &#8226; Vinish.Dev","isPartOf":{"@id":"https:\/\/vinish.dev\/#website"},"datePublished":"2018-08-15T07:58:07+00:00","dateModified":"2025-04-16T14:19:15+00:00","description":"In this article, a PL\/SQL function example is given to split a string with any delimiter.","breadcrumb":{"@id":"https:\/\/vinish.dev\/how-to-split-a-string-in-pl-sql#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/vinish.dev\/how-to-split-a-string-in-pl-sql"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/vinish.dev\/how-to-split-a-string-in-pl-sql#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/vinish.dev\/"},{"@type":"ListItem","position":2,"name":"PLSQL","item":"https:\/\/vinish.dev\/category\/plsql"},{"@type":"ListItem","position":3,"name":"How to Split a String in PL\/SQL?"}]},{"@type":"WebSite","@id":"https:\/\/vinish.dev\/#website","url":"https:\/\/vinish.dev\/","name":"Vinish.Dev","description":"Vinish Kapoor&#039;s Blog: Best Oracle Blog for Developers","publisher":{"@id":"https:\/\/vinish.dev\/#\/schema\/person\/df5e5ca816f6f4302efc03cf58dc97b4"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/vinish.dev\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/vinish.dev\/#\/schema\/person\/df5e5ca816f6f4302efc03cf58dc97b4","name":"Vinish Kapoor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/vinish.dev\/wp-content\/uploads\/2023\/12\/vinishprofile.png","url":"https:\/\/vinish.dev\/wp-content\/uploads\/2023\/12\/vinishprofile.png","contentUrl":"https:\/\/vinish.dev\/wp-content\/uploads\/2023\/12\/vinishprofile.png","width":192,"height":192,"caption":"Vinish Kapoor"},"logo":{"@id":"https:\/\/vinish.dev\/wp-content\/uploads\/2023\/12\/vinishprofile.png"},"description":"Vinish Kapoor is a seasoned software development professional and a fervent enthusiast of artificial intelligence (AI). His impressive career spans over 25+ years, marked by a relentless pursuit of innovation and excellence in the field of information technology. As an Oracle ACE, Vinish has distinguished himself as a leading expert in Oracle technologies, a title awarded to individuals who have demonstrated their deep commitment, leadership, and expertise in the Oracle community.","sameAs":["https:\/\/vinish.dev\/","https:\/\/www.facebook.com\/foxinfotech2014","https:\/\/www.linkedin.com\/in\/vinish-kapoor\/","https:\/\/x.com\/foxinfotech"]},{"@type":"Person","@id":"https:\/\/vinish.dev\/#\/schema\/person\/a7790479716d2a54131ca873f8483d3f","name":"Vinish Kapoor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/a67232caa79b11f24f16c371866a96cfb575e011ebda6fa6e3d088a837a31bde?s=96&d=identicon&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/a67232caa79b11f24f16c371866a96cfb575e011ebda6fa6e3d088a837a31bde?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a67232caa79b11f24f16c371866a96cfb575e011ebda6fa6e3d088a837a31bde?s=96&d=identicon&r=g","caption":"Vinish Kapoor"},"description":"Vinish Kapoor is a seasoned software development professional and a fervent enthusiast of artificial intelligence (AI). His impressive career spans over 25+ years, marked by a relentless pursuit of innovation and excellence in the field of information technology. As an Oracle ACE, Vinish has distinguished himself as a leading expert in Oracle technologies, a title awarded to individuals who have demonstrated their deep commitment, leadership, and expertise in the Oracle community.","sameAs":["https:\/\/vinish.dev\/","https:\/\/www.linkedin.com\/in\/vinish-kapoor\/","https:\/\/x.com\/https:\/\/x.com\/vinish_kapoor"]}]}},"_links":{"self":[{"href":"https:\/\/vinish.dev\/wp-json\/wp\/v2\/posts\/1673","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vinish.dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vinish.dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vinish.dev\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vinish.dev\/wp-json\/wp\/v2\/comments?post=1673"}],"version-history":[{"count":1,"href":"https:\/\/vinish.dev\/wp-json\/wp\/v2\/posts\/1673\/revisions"}],"predecessor-version":[{"id":17553,"href":"https:\/\/vinish.dev\/wp-json\/wp\/v2\/posts\/1673\/revisions\/17553"}],"wp:attachment":[{"href":"https:\/\/vinish.dev\/wp-json\/wp\/v2\/media?parent=1673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vinish.dev\/wp-json\/wp\/v2\/categories?post=1673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vinish.dev\/wp-json\/wp\/v2\/tags?post=1673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}