{"id":16727,"date":"2021-10-05T20:49:46","date_gmt":"2021-10-05T18:49:46","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/select-from-dual-oracle-performance-and-tuning\/"},"modified":"2021-10-05T20:49:46","modified_gmt":"2021-10-05T18:49:46","slug":"select-from-dual-oracle-performance-and-tuning","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/select-from-dual-oracle-performance-and-tuning\/","title":{"rendered":"SELECT FROM DUAL : Oracle Performance And Tuning"},"content":{"rendered":"<p>The DUAL table is automatically created by Oracle and contains one column (DUMMY) and one row (x value).<\/p>\n<p>This table is often used by SQL developer in PL\/SQL code (Package, Functions, Trigger) to initialize variables storing technical information such as for example SYSDATE, USER or HOSTNAME.<\/p>\n<p>Querying DUAL table is generally faster\u00a0 as we can see below:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">SQL&gt; select sysdate from dual;\n\nSYSDATE\n---------\n05-OCT-21\n\nElapsed: 00:00:00.01\n\nExecution Plan\n----------------------------------------------------------\nPlan hash value: 1388734953\n\n-----------------------------------------------------------------\n| Id  | Operation        | Name | Rows  | Cost (%CPU)| Time     |\n-----------------------------------------------------------------\n|   0 | SELECT STATEMENT |      |     1 |     2   (0)| 00:00:01 |\n|   1 |  FAST DUAL       |      |     1 |     2   (0)| 00:00:01 |\n-----------------------------------------------------------------\n\n\nStatistics\n----------------------------------------------------------\n          1  recursive calls\n          0  db block gets\n          0  consistent gets\n          0  physical reads\n          0  redo size\n        554  bytes sent via SQL*Net to client\n        386  bytes received via SQL*Net from client\n          2  SQL*Net roundtrips to\/from client\n          0  sorts (memory)\n          0  sorts (disk)\n          1  rows processed\n\n<\/pre>\n<p>&nbsp;<\/p>\n<p>But what happens when this &#8220;SELECT FROM DUAL&#8221; is executed several times into the application :<\/p>\n<p>Let&#8217;s execute it for 100, 1000, 10000, 100000 and 1000000 executions<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">SQL&gt; declare\n        v_date date;\nbegin\n for rec in 1..100 loop\n        select sysdate into v_date from dual;\n  end loop;\nend;  2    3    4    5    6    7\n  8  \/\n\nPL\/SQL procedure successfully completed.\n\nElapsed: 00:00:00.01\nSQL&gt; declare\n        v_date date;\nbegin\n for rec in 1..1000 loop\n        select sysdate into v_date from dual;\n  end loop;\nend;  2    3    4    5    6    7\n  8  \/\n\nPL\/SQL procedure successfully completed.\n\nElapsed: 00:00:00.01\nSQL&gt; declare\n        v_date date;\nbegin\n for rec in 1..10000 loop\n        select sysdate into v_date from dual;\n  end loop;\nend;\n  2    3    4    5    6    7    8\n  9  \/\n\nPL\/SQL procedure successfully completed.\n\nElapsed: 00:00:00.08\nSQL&gt; declare\n        v_date date;\nbegin\n for rec in 1..100000 loop\n        select sysdate into v_date from dual;\n  end loop;\nend;  2    3    4    5    6    7\n  8  \/\n\nPL\/SQL procedure successfully completed.\n\nElapsed: 00:00:00.85\nSQL&gt; declare\n        v_date date;\nbegin\n for rec in 1..1000000 loop\n        select sysdate into v_date from dual;\n  end loop;\nend;\n  2    3    4    5    6    7    8\n  9  \/\n\nPL\/SQL procedure successfully completed.\n\nElapsed: 00:00:08.34\nSQL&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p>Let&#8217;s execute now a PL\/SQL block to assign directly the variable v_date with SYSDATE instead of using &#8220;SELECT FROM DUAL&#8221;:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">SQL&gt; declare\n        v_date date;\nbegin\n for rec in 1..100 loop\n        v_date := sysdate;\n  end loop;\nend;\n  2    3    4    5    6    7    8\n  9  \/\n\nPL\/SQL procedure successfully completed.\n\nElapsed: 00:00:00.00\nSQL&gt; declare\n        v_date date;\nbegin\n for rec in 1..1000 loop\n        v_date := sysdate;\n  end loop;\nend;\n  2    3    4    5    6    7    8\n  9  \/\n\nPL\/SQL procedure successfully completed.\n\nElapsed: 00:00:00.00\nSQL&gt; declare\n        v_date date;\nbegin\n for rec in 1..10000 loop\n        v_date := sysdate;\n  end loop;\nend;\n  2    3    4    5    6    7    8\n  9  \/\n\nPL\/SQL procedure successfully completed.\n\nElapsed: 00:00:00.01\nSQL&gt; declare\n        v_date date;\nbegin\n for rec in 1..100000 loop\n        v_date := sysdate;\n  end loop;\nend;\n  2    3    4    5    6    7    8\n  9  \/\n\nPL\/SQL procedure successfully completed.\n\nElapsed: 00:00:00.14\nSQL&gt; declare\n        v_date date;\nbegin\n for rec in 1..1000000 loop\n        v_date := sysdate;\n  end loop;\nend;\n  2    3    4    5    6    7    8\n  9  \/\n\nPL\/SQL procedure successfully completed.\n\nElapsed: 00:00:01.28\nSQL&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Conclusion:<\/strong><\/p>\n<table style=\"border-collapse: collapse;width: 100%\">\n<tbody>\n<tr>\n<td style=\"width: 33.3333%;text-align: center\"><strong>Nb of executions<\/strong><\/td>\n<td style=\"width: 33.3333%;text-align: center\"><strong>SELECT FROM DUAL<\/strong><\/td>\n<td style=\"width: 33.3333%;text-align: center\"><strong>Assigning variable<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.3333%;text-align: center\">100<strong><br \/>\n<\/strong><\/td>\n<td style=\"width: 33.3333%;text-align: center\">1 ms<strong><br \/>\n<\/strong><\/td>\n<td style=\"width: 33.3333%;text-align: center\">0 ms<strong><br \/>\n<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.3333%;text-align: center\">1000<\/td>\n<td style=\"width: 33.3333%;text-align: center\">1 ms<strong><br \/>\n<\/strong><\/td>\n<td style=\"width: 33.3333%;text-align: center\">0 ms<strong><br \/>\n<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.3333%;text-align: center\">10000<\/td>\n<td style=\"width: 33.3333%;text-align: center\">8 ms<strong><br \/>\n<\/strong><\/td>\n<td style=\"width: 33.3333%;text-align: center\">1 ms<strong><br \/>\n<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.3333%;text-align: center\">100000<\/td>\n<td style=\"width: 33.3333%;text-align: center\">85 ms<strong><br \/>\n<\/strong><\/td>\n<td style=\"width: 33.3333%;text-align: center\">14 ms<strong><br \/>\n<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.3333%;text-align: center\">1000000<\/td>\n<td style=\"width: 33.3333%;text-align: center\">8.34 sec<strong><br \/>\n<\/strong><\/td>\n<td style=\"width: 33.3333%;text-align: center\">1.28 sec<strong><br \/>\n<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>&#8220;SELECT FROM DUAL&#8221; is always slower than &#8220;Assigning variable&#8221;:<\/p>\n<ul>\n<li>8 times more slower for 10000 executions<\/li>\n<li>6 times more slower for 100000 executions<\/li>\n<li>More than 8 times more slower for 1000000 executions<\/li>\n<\/ul>\n<p>From a performance point of vew, &#8220;SELECT FROM DUAL&#8221; must be avoided to initialize variable because when you query the DUAL table in a PL\/SQL block, oracle optimizer does a roundtrip between the PL\/SQL engine and the SQL engine. For few rows, it&#8217;s fast, but for several rows (Ex.: 1000000) the &#8220;SELECT FROM DUAL&#8221; is inefficient because oracle will do 1000000 roundtrips between the PL\/SQL engine and the SQL engine.<\/p>\n<p>I have seen plenty of applications where the &#8220;SELECT FROM DUAL&#8221; is used everywhere (Ex. : &#8220;SELECT FROM DUAL&#8221; in a Logon trigger !!!) while we can use a simple &#8220;Assigning variable&#8221; and changing the code has increased the performance of the application significantly.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The DUAL table is automatically created by Oracle and contains one column (DUMMY) and one row (x value). This table is often used by SQL developer in PL\/SQL code (Package, Functions, Trigger) to initialize variables storing technical information such as for example SYSDATE, USER or HOSTNAME. Querying DUAL table is generally faster\u00a0 as we can [&hellip;]<\/p>\n","protected":false},"author":27,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[229,368,59],"tags":[1192,96,644,24,98,1974,1218],"type_dbi":[],"class_list":["post-16727","post","type-post","status-publish","format-standard","hentry","category-database-administration-monitoring","category-development-performance","category-oracle","tag-optimization","tag-oracle","tag-performance-tuning","tag-pl-sql","tag-sql","tag-sql-database","tag-tuning"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>SELECT FROM DUAL : Oracle Performance And Tuning - dbi Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/select-from-dual-oracle-performance-and-tuning\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SELECT FROM DUAL : Oracle Performance And Tuning\" \/>\n<meta property=\"og:description\" content=\"The DUAL table is automatically created by Oracle and contains one column (DUMMY) and one row (x value). This table is often used by SQL developer in PL\/SQL code (Package, Functions, Trigger) to initialize variables storing technical information such as for example SYSDATE, USER or HOSTNAME. Querying DUAL table is generally faster\u00a0 as we can [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/select-from-dual-oracle-performance-and-tuning\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2021-10-05T18:49:46+00:00\" \/>\n<meta name=\"author\" content=\"Oracle Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Oracle Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/select-from-dual-oracle-performance-and-tuning\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/select-from-dual-oracle-performance-and-tuning\/\"},\"author\":{\"name\":\"Oracle Team\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"headline\":\"SELECT FROM DUAL : Oracle Performance And Tuning\",\"datePublished\":\"2021-10-05T18:49:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/select-from-dual-oracle-performance-and-tuning\/\"},\"wordCount\":274,\"commentCount\":0,\"keywords\":[\"Optimization\",\"Oracle\",\"Performance Tuning\",\"PL\/SQL\",\"SQL\",\"SQL Database\",\"tuning\"],\"articleSection\":[\"Database Administration &amp; Monitoring\",\"Development &amp; Performance\",\"Oracle\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/select-from-dual-oracle-performance-and-tuning\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/select-from-dual-oracle-performance-and-tuning\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/select-from-dual-oracle-performance-and-tuning\/\",\"name\":\"SELECT FROM DUAL : Oracle Performance And Tuning - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"datePublished\":\"2021-10-05T18:49:46+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/select-from-dual-oracle-performance-and-tuning\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/select-from-dual-oracle-performance-and-tuning\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/select-from-dual-oracle-performance-and-tuning\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SELECT FROM DUAL : Oracle Performance And Tuning\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\",\"name\":\"Oracle Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"caption\":\"Oracle Team\"},\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/oracle-team\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"SELECT FROM DUAL : Oracle Performance And Tuning - dbi Blog","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:\/\/www.dbi-services.com\/blog\/select-from-dual-oracle-performance-and-tuning\/","og_locale":"en_US","og_type":"article","og_title":"SELECT FROM DUAL : Oracle Performance And Tuning","og_description":"The DUAL table is automatically created by Oracle and contains one column (DUMMY) and one row (x value). This table is often used by SQL developer in PL\/SQL code (Package, Functions, Trigger) to initialize variables storing technical information such as for example SYSDATE, USER or HOSTNAME. Querying DUAL table is generally faster\u00a0 as we can [&hellip;]","og_url":"https:\/\/www.dbi-services.com\/blog\/select-from-dual-oracle-performance-and-tuning\/","og_site_name":"dbi Blog","article_published_time":"2021-10-05T18:49:46+00:00","author":"Oracle Team","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Oracle Team","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/select-from-dual-oracle-performance-and-tuning\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/select-from-dual-oracle-performance-and-tuning\/"},"author":{"name":"Oracle Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"headline":"SELECT FROM DUAL : Oracle Performance And Tuning","datePublished":"2021-10-05T18:49:46+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/select-from-dual-oracle-performance-and-tuning\/"},"wordCount":274,"commentCount":0,"keywords":["Optimization","Oracle","Performance Tuning","PL\/SQL","SQL","SQL Database","tuning"],"articleSection":["Database Administration &amp; Monitoring","Development &amp; Performance","Oracle"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/select-from-dual-oracle-performance-and-tuning\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/select-from-dual-oracle-performance-and-tuning\/","url":"https:\/\/www.dbi-services.com\/blog\/select-from-dual-oracle-performance-and-tuning\/","name":"SELECT FROM DUAL : Oracle Performance And Tuning - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2021-10-05T18:49:46+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/select-from-dual-oracle-performance-and-tuning\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/select-from-dual-oracle-performance-and-tuning\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/select-from-dual-oracle-performance-and-tuning\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"SELECT FROM DUAL : Oracle Performance And Tuning"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee","name":"Oracle Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","caption":"Oracle Team"},"url":"https:\/\/www.dbi-services.com\/blog\/author\/oracle-team\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/16727","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=16727"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/16727\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=16727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=16727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=16727"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=16727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}