{"id":18947,"date":"2021-07-25T08:14:01","date_gmt":"2021-07-24T22:14:01","guid":{"rendered":"https:\/\/database.guide\/?p=18947"},"modified":"2021-07-25T08:16:16","modified_gmt":"2021-07-24T22:16:16","slug":"initcap-function-in-oracle","status":"publish","type":"post","link":"https:\/\/database.guide\/initcap-function-in-oracle\/","title":{"rendered":"INITCAP() Function in Oracle"},"content":{"rendered":"\n<p>In Oracle, the <code>INITCAP()<\/code> function returns its argument with the first letter of each word in uppercase, and all other letters in lowercase.<\/p>\n\n\n\n<p>For <meta charset=\"utf-8\">special linguistic requirements for case conversions, you may want to try the <code><a href=\"https:\/\/database.guide\/nls_initcap-function-in-oracle\/\" data-type=\"post\" data-id=\"19025\">NLS_INITCAP()<\/a><\/code> function instead.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">Syntax<\/h2>\n\n\n\n<p>The syntax goes like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>INITCAP(char)<\/code><\/pre>\n\n\n\n<p>Where <em><code>char<\/code><\/em>&nbsp;can be of any of the data types&nbsp;<code>CHAR<\/code>,&nbsp;<code>VARCHAR2<\/code>,&nbsp;<code>NCHAR<\/code>, or&nbsp;<code>NVARCHAR2<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example<\/h2>\n\n\n\n<p>Here&#8217;s a simple example to demonstrate:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT INITCAP('ponzi investment house')\nFROM DUAL;<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">   INITCAP('PONZIINVESTMENTHOUSE') \n__________________________________ \nPonzi Investment House            <\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">What if I Pass All UPPERCASE Letters?<\/h2>\n\n\n\n<p>Passing all uppercase letters doesn&#8217;t change the result:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT INITCAP('PONZI INVESTMENT HOUSE')\nFROM DUAL;<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">   INITCAP('PONZIINVESTMENTHOUSE') \n__________________________________ \nPonzi Investment House            <\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Null Values<\/h2>\n\n\n\n<p>Passing <code>null<\/code> returns <code>null<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SET NULL 'null';\n\nSELECT INITCAP(null)\nFROM DUAL;<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">   INITCAP(NULL) \n________________ \nnull            <\/pre>\n\n\n\n<p>By default, SQLcl and SQL*Plus return a blank space whenever <code>null<\/code> occurs as a result of a SQL <code><a href=\"https:\/\/database.guide\/sql-select-for-beginners\/\" data-type=\"post\" data-id=\"11928\">SELECT<\/a><\/code> statement. <\/p>\n\n\n\n<p>However, you can use <code><a href=\"https:\/\/database.guide\/set-null-specify-a-string-to-return-whenever-a-null-value-occurs-in-sqlcl-sqlplus\/\">SET NULL<\/a><\/code> to specify a different string to be returned. Here I specified that the string <code>null<\/code> should be returned.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Incorrect Argument Count<\/h2>\n\n\n\n<p>Calling <code>INITCAP()<\/code> without passing any arguments returns an error:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT INITCAP()\nFROM DUAL;<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Error starting at line : 1 in command -\nSELECT INITCAP()\nFROM DUAL\nError at Command Line : 1 Column : 8\nError report -\nSQL Error: ORA-00909: invalid number of arguments\n00909. 00000 -  \"invalid number of arguments\"\n*Cause:    \n*Action:<\/pre>\n\n\n\n<p>And passing the wrong number of arguments results in an error:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT INITCAP('Gosh', 'Dang', 'Investments')\nFROM DUAL;<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Error starting at line : 1 in command -\nSELECT INITCAP('Gosh', 'Dang', 'Investments')\nFROM DUAL\nError at Command Line : 1 Column : 8\nError report -\nSQL Error: ORA-00909: invalid number of arguments\n00909. 00000 -  \"invalid number of arguments\"\n*Cause:    \n*Action:<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In Oracle, the INITCAP() function returns its argument with the first letter of each word in uppercase, and all other letters in lowercase. For special linguistic requirements for case conversions, you may want to try the NLS_INITCAP() function instead.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41],"tags":[93,67,20],"class_list":["post-18947","post","type-post","status-publish","format-standard","hentry","category-oracle","tag-functions","tag-string-functions","tag-what-is"],"_links":{"self":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/18947","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/comments?post=18947"}],"version-history":[{"count":6,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/18947\/revisions"}],"predecessor-version":[{"id":19053,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/18947\/revisions\/19053"}],"wp:attachment":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/media?parent=18947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/categories?post=18947"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/tags?post=18947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}