{"id":18889,"date":"2021-07-27T08:08:21","date_gmt":"2021-07-26T22:08:21","guid":{"rendered":"https:\/\/database.guide\/?p=18889"},"modified":"2021-07-27T08:08:21","modified_gmt":"2021-07-26T22:08:21","slug":"sqrt-function-in-oracle","status":"publish","type":"post","link":"https:\/\/database.guide\/sqrt-function-in-oracle\/","title":{"rendered":"SQRT() Function in Oracle"},"content":{"rendered":"\n<p>In Oracle, the <code>SQRT()<\/code>&nbsp;function returns the square root of its argument.<\/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>SQRT(n)<\/code><\/pre>\n\n\n\n<p>Where <code><em>n<\/em><\/code> can be any numeric data type or any nonnumeric data type that can be implicitly converted to a numeric data type.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example<\/h2>\n\n\n\n<p>Here&#8217;s an example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT SQRT(64)\nFROM DUAL;<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">   SQRT(64) \n___________ \n          8<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Non-Numeric Argument<\/h2>\n\n\n\n<p>As mentioned, the argument can be any numeric data type or any nonnumeric data type that can be implicitly converted to a numeric data type. <\/p>\n\n\n\n<p>Here&#8217;s what happens when we provide a non-numeric argument that can&#8217;t be converted to a numeric data type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT SQRT('One')\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 SQRT('One')\nFROM DUAL\nError report -\nORA-01722: invalid number<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Null Values<\/h2>\n\n\n\n<p>Passing <code>null<\/code> to <code>SQRT()<\/code> returns <code>null<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SET NULL 'null';\n\nSELECT SQRT(null)\nFROM DUAL;<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">   SQRT(NULL) \n_____________ \n         null <\/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>SQRT()<\/code> without passing any arguments returns an error:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT SQRT()\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 SQRT()\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 SQRT(1, 2)\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 SQRT(1, 2)\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 SQRT()&nbsp;function returns the square root of its argument.<\/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,71,20],"class_list":["post-18889","post","type-post","status-publish","format-standard","hentry","category-oracle","tag-functions","tag-numeric-functions","tag-what-is"],"_links":{"self":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/18889","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=18889"}],"version-history":[{"count":2,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/18889\/revisions"}],"predecessor-version":[{"id":19094,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/18889\/revisions\/19094"}],"wp:attachment":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/media?parent=18889"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/categories?post=18889"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/tags?post=18889"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}