{"id":11398,"date":"2018-07-05T19:29:17","date_gmt":"2018-07-05T17:29:17","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/18c-order-by-in-with-clause-is-not-preserved\/"},"modified":"2018-07-05T19:29:17","modified_gmt":"2018-07-05T17:29:17","slug":"18c-order-by-in-with-clause-is-not-preserved","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/18c-order-by-in-with-clause-is-not-preserved\/","title":{"rendered":"18c: Order by in WITH clause is not preserved"},"content":{"rendered":"<h2>By Franck Pachot<\/h2>\n<p>.<br \/>\nFor a <a href=\"https:\/\/www.dbi-services.com\/blog\/18c-some-optimization-about-redo-size\/\" target=\"_blank\" rel=\"noopener noreferrer\">previous post<\/a> I&#8217;ve run on 18c a script of mine to get the V$MYSTAT delta values between two queries. This script (new version available on <a href=\"https:\/\/github.com\/FranckPachot\/scripts\/blob\/master\/administration\/generate_mystat_diff.sql\" target=\"_blank\" rel=\"noopener noreferrer\">GitHub<\/a>) generates the queries to store some values and subtract them on the next execution. But I had to fix it for 18c because I relied on some order by in a CTE which is lost in 18c.<br \/>\nThe idea was to get the statistic names in a Common Table Expression (CTE):<\/p>\n<pre><code>\nwith stats as (\n  select rownum n,stat_id,name from (select stat_id,name from v$statname where name in (&amp;names) order by stat_id)\n)\n<\/code><\/pre>\n<p>and query it from different parts of the UNION ALL which generates the script:<\/p>\n<pre><code>\nselect 'select ' from dual\nunion all\nselect '   '||decode(n,1,' ',',')||'\"CUR'||stat_id||'\" - '||'&amp;'||'LAG'||stat_id||' \"DIF'||stat_id||'\"' from stats\nunion all\nselect '   '||',nvl(\"CUR'||stat_id||'\",0) \"CUR'||stat_id||'\"' from stats\nunion all\n<\/code><\/pre>\n<p>The rowum in the WITH clause is used later to add the comma for all rows except the first one &#8211; using decode(n,1,&#8217; &#8216;,&#8217;,&#8217;)<\/p>\n<p>But this relied on two assumptions:<\/p>\n<ol>\n<li>the WITH keeps the rows ordered<\/li>\n<li>the UNION ALL keeps the rows ordered<\/li>\n<\/ol>\n<p>Of course, it would be better to add a number on each part and an ORDER BY at the end of the query. But for better readability, I didn&#8217;t.<\/p>\n<p>However, the first assumption is wrong since 12.2 where the optimizer introduced In-Memory Cursor Duration Temp Tables. In the query above, the CTE is materialized because it is used multiple times. And this optimization keeps it in memory. But it seems that this structure does not keep the rows ordered.<\/p>\n<p>Here is an example where I have a 4 rows table:<\/p>\n<pre><code>\nSQL&gt; create table DEMO as select rownum id from xmltable('1 to 4');\nTable DEMO created.\n&nbsp;\nSQL&gt; select  * from DEMO order by id;\n&nbsp;\n        ID\n----------\n         1\n         2\n         3\n         4\n<\/code><\/pre>\n<p>When I put the same query in a WITH clause, with its ORDER BY, and query it from 2 union all statements, the rows are not ordered anymore:<\/p>\n<pre><code>\nSQL&gt; with cte as ( select * from DEMO order by id)\n     select rownum,id from cte\n     union all\n     select rownum,id from cte ;\n&nbsp;\n    ROWNUM         ID\n---------- ----------\n         1          4\n         2          3\n         3          2\n         4          1\n         1          4\n         2          3\n         3          2\n         4          1\n<\/code><\/pre>\n<p>The execution plan shows the materialization of the CTE result, and mentions that it is an In-Memory Cursor Duration Temp Table (CURSOR DURATION MEMORY)<\/p>\n<pre><code>\nSQL&gt; select * from dbms_xplan.display_cursor(format=&gt;'+projection');\n&nbsp;\nPLAN_TABLE_OUTPUT\n---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\nSQL_ID  9uwc06ana6trn, child number 0\n-------------------------------------\nwith cte as ( select * from DEMO order by id)   select rownum,id from\ncte   union all  select rownum,id from cte\n&nbsp;\nPlan hash value: 4025392480\n&nbsp;\n----------------------------------------------------------------------------------------------------------------------\n| Id  | Operation                                | Name                      | Rows  | Bytes | Cost (%CPU)| Time     |\n----------------------------------------------------------------------------------------------------------------------\n|   0 | SELECT STATEMENT                         |                           |       |       |     4 (100)|          |\n|   1 |  TEMP TABLE TRANSFORMATION               |                           |       |       |            |          |\n|   2 |   LOAD AS SELECT (CURSOR DURATION MEMORY)| SYS_TEMP_0FD9D6640_23D74B |       |       |            |          |\n|   3 |    SORT ORDER BY                         |                           |     4 |    12 |     4  (25)| 00:00:01 |\n|   4 |     TABLE ACCESS FULL                    | DEMO                      |     4 |    12 |     3   (0)| 00:00:01 |\n|   5 |   UNION-ALL                              |                           |       |       |            |          |\n|   6 |    COUNT                                 |                           |       |       |            |          |\n|   7 |     VIEW                                 |                           |     4 |    52 |     2   (0)| 00:00:01 |\n|   8 |      TABLE ACCESS FULL                   | SYS_TEMP_0FD9D6640_23D74B |     4 |    12 |     2   (0)| 00:00:01 |\n|   9 |    COUNT                                 |                           |       |       |            |          |\n|  10 |     VIEW                                 |                           |     4 |    52 |     2   (0)| 00:00:01 |\n|  11 |      TABLE ACCESS FULL                   | SYS_TEMP_0FD9D6640_23D74B |     4 |    12 |     2   (0)| 00:00:01 |\n----------------------------------------------------------------------------------------------------------------------\n&nbsp;\nColumn Projection Information (identified by operation id):\n-----------------------------------------------------------\n   1 - STRDEF[22], STRDEF[22]\n   2 - SYSDEF[4], SYSDEF[0], SYSDEF[1], SYSDEF[120], SYSDEF[0]\n   3 - (#keys=1) \"DEMO\".\"ID\"[NUMBER,22]\n   4 - (rowset=256) \"DEMO\".\"ID\"[NUMBER,22]\n   5 - STRDEF[22], STRDEF[22]\n   6 - \"ID\"[NUMBER,22], ROWNUM[8]\n   7 - \"ID\"[NUMBER,22]\n   8 - \"C0\"[NUMBER,22]\n   9 - \"ID\"[NUMBER,22], ROWNUM[8]\n  10 - \"ID\"[NUMBER,22]\n  11 - \"C0\"[NUMBER,22]\n<\/code><\/pre>\n<h3>\/*+ inline *\/<\/h3>\n<p>If the CTE is not materialized, the rows are ordered, bit the table is read two times:<\/p>\n<pre><code>\nSQL&gt; with cte as ( select \/*+ inline *\/ * from DEMO order by id)\n  2   select rownum,id from cte\n  3   union all\n  4   select rownum,id from cte ;\n&nbsp;\n    ROWNUM         ID\n---------- ----------\n         1          1\n         2          2\n         3          3\n         4          4\n         1          1\n         2          2\n         3          3\n         4          4\n&nbsp;\n8 rows selected.\n&nbsp;\nSQL&gt;\nSQL&gt; select * from dbms_xplan.display_cursor(format=&gt;'+projection');\n&nbsp;\nPLAN_TABLE_OUTPUT\n---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\nSQL_ID  0dad0vwg3k0th, child number 0\n-------------------------------------\nwith cte as ( select \/*+ inline *\/ * from DEMO order by id)   select\nrownum,id from cte   union all  select rownum,id from cte\n&nbsp;\nPlan hash value: 2913170750\n&nbsp;\n------------------------------------------------------------------------------\n| Id  | Operation             | Name | Rows  | Bytes | Cost (%CPU)| Time     |\n------------------------------------------------------------------------------\n|   0 | SELECT STATEMENT      |      |       |       |     8 (100)|          |\n|   1 |  UNION-ALL            |      |       |       |            |          |\n|   2 |   COUNT               |      |       |       |            |          |\n|   3 |    VIEW               |      |     4 |    52 |     4  (25)| 00:00:01 |\n|   4 |     SORT ORDER BY     |      |     4 |    12 |     4  (25)| 00:00:01 |\n|   5 |      TABLE ACCESS FULL| DEMO |     4 |    12 |     3   (0)| 00:00:01 |\n|   6 |   COUNT               |      |       |       |            |          |\n|   7 |    VIEW               |      |     4 |    52 |     4  (25)| 00:00:01 |\n|   8 |     SORT ORDER BY     |      |     4 |    12 |     4  (25)| 00:00:01 |\n|   9 |      TABLE ACCESS FULL| DEMO |     4 |    12 |     3   (0)| 00:00:01 |\n------------------------------------------------------------------------------\n&nbsp;\nColumn Projection Information (identified by operation id):\n-----------------------------------------------------------\n&nbsp;\n   1 - STRDEF[22], STRDEF[22]\n   2 - \"ID\"[NUMBER,22], ROWNUM[8]\n   3 - \"ID\"[NUMBER,22]\n   4 - (#keys=1) \"DEMO\".\"ID\"[NUMBER,22]\n   5 - (rowset=256) \"DEMO\".\"ID\"[NUMBER,22]\n   6 - \"ID\"[NUMBER,22], ROWNUM[8]\n   7 - \"ID\"[NUMBER,22]\n   8 - (#keys=1) \"DEMO\".\"ID\"[NUMBER,22]\n   9 - (rowset=256) \"DEMO\".\"ID\"[NUMBER,22]\n<\/code><\/pre>\n<h3>&#8220;_in_memory_cdt&#8221;=off<\/h3>\n<p>If the CTE is materialized, but the new feature to keep it in memory is disabled, the rows are ordered (but probably by chance &#8211; there si no guarantee):<\/p>\n<pre><code>\nSQL&gt; alter session set \"_in_memory_cdt\"=off;\n&nbsp;\nSession altered.\n&nbsp;\nSQL&gt;\nSQL&gt; with cte as ( select \/*+ materialize *\/ * from DEMO order by id)\n  2   select rownum,id from cte\n  3   union all\n  4   select rownum,id from cte ;\n&nbsp;\n    ROWNUM         ID\n---------- ----------\n         1          1\n         2          2\n         3          3\n         4          4\n         1          1\n         2          2\n         3          3\n         4          4\n&nbsp;\n8 rows selected.\n&nbsp;\nSQL&gt; select * from dbms_xplan.display_cursor(format=&gt;'+projection');\n&nbsp;\nPLAN_TABLE_OUTPUT\n---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\nSQL_ID  9uwc06ana6trn, child number 1\n-------------------------------------\nwith cte as ( select * from DEMO order by id)   select rownum,id from\ncte   union all  select rownum,id from cte\n&nbsp;\nPlan hash value: 4025392480\n&nbsp;\n--------------------------------------------------------------------------------------------------------\n| Id  | Operation                  | Name                      | Rows  | Bytes | Cost (%CPU)| Time     |\n--------------------------------------------------------------------------------------------------------\n|   0 | SELECT STATEMENT           |                           |       |       |     4 (100)|          |\n|   1 |  TEMP TABLE TRANSFORMATION |                           |       |       |            |          |\n|   2 |   LOAD AS SELECT           | SYS_TEMP_0FD9D664D_23D74B |       |       |            |          |\n|   3 |    SORT ORDER BY           |                           |     4 |    12 |     4  (25)| 00:00:01 |\n|   4 |     TABLE ACCESS FULL      | DEMO                      |     4 |    12 |     3   (0)| 00:00:01 |\n|   5 |   UNION-ALL                |                           |       |       |            |          |\n|   6 |    COUNT                   |                           |       |       |            |          |\n|   7 |     VIEW                   |                           |     4 |    52 |     2   (0)| 00:00:01 |\n|   8 |      TABLE ACCESS FULL     | SYS_TEMP_0FD9D664D_23D74B |     4 |    12 |     2   (0)| 00:00:01 |\n|   9 |    COUNT                   |                           |       |       |            |          |\n|  10 |     VIEW                   |                           |     4 |    52 |     2   (0)| 00:00:01 |\n|  11 |      TABLE ACCESS FULL     | SYS_TEMP_0FD9D664D_23D74B |     4 |    12 |     2   (0)| 00:00:01 |\n--------------------------------------------------------------------------------------------------------\n&nbsp;\nColumn Projection Information (identified by operation id):\n-----------------------------------------------------------\n&nbsp;\n   1 - STRDEF[22], STRDEF[22]\n   2 - SYSDEF[4], SYSDEF[0], SYSDEF[1], SYSDEF[120], SYSDEF[0]\n   3 - (#keys=1) \"DEMO\".\"ID\"[NUMBER,22]\n   4 - (rowset=256) \"DEMO\".\"ID\"[NUMBER,22]\n   5 - STRDEF[22], STRDEF[22]\n   6 - \"ID\"[NUMBER,22], ROWNUM[8]\n   7 - \"ID\"[NUMBER,22]\n   8 - \"C0\"[NUMBER,22]\n   9 - \"ID\"[NUMBER,22], ROWNUM[8]\n  10 - \"ID\"[NUMBER,22]\n  11 - \"C0\"[NUMBER,22]\n<\/code><\/pre>\n<h3>So what?<\/h3>\n<p>We should never rely on the preservation of the row order except when explicitly documented (like rownum over a subquery with order by). And this In-Memory Cursor Duration Temporary table also works in parallel and RAC, so we can understand that the rows are not read in the same order as they were stored. This is always a problem when we migrate. When something works by chance in a version and not in the newer versions, people usually incriminate the migration, rather than recognizing an old bug in the application, just because it was working before.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>By Franck Pachot . For a previous post I&#8217;ve run on 18c a script of mine to get the V$MYSTAT delta values between two queries. This script (new version available on GitHub) generates the queries to store some values and subtract them on the next execution. But I had to fix it for 18c because&hellip;&nbsp;<\/p>\n","protected":false},"author":27,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","neve_meta_reading_time":"","_themeisle_gutenberg_block_has_review":false,"footnotes":""},"categories":[59],"tags":[222,1184],"class_list":["post-11398","post","type-post","status-publish","format-standard","category-oracle","tag-in-memory","tag-oracle-18c"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v28.9 (Yoast SEO v28.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>18c: Order by in WITH clause is not preserved - dbi services 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\/18c-order-by-in-with-clause-is-not-preserved\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"18c: Order by in WITH clause is not preserved\" \/>\n<meta property=\"og:description\" content=\"By Franck Pachot . For a previous post I&#8217;ve run on 18c a script of mine to get the V$MYSTAT delta values between two queries. This script (new version available on GitHub) generates the queries to store some values and subtract them on the next execution. But I had to fix it for 18c because&hellip;&nbsp;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/18c-order-by-in-with-clause-is-not-preserved\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi services Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/dbiservices\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-07-05T17:29:17+00:00\" \/>\n<meta name=\"author\" content=\"Oracle Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@dbiservices\" \/>\n<meta name=\"twitter:site\" content=\"@dbiservices\" \/>\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=\"6 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\\\/18c-order-by-in-with-clause-is-not-preserved\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/18c-order-by-in-with-clause-is-not-preserved\\\/\"},\"author\":{\"name\":\"Oracle Team\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/person\\\/bf7c7eb0bec165183207237c9d0ee1d5\"},\"headline\":\"18c: Order by in WITH clause is not preserved\",\"datePublished\":\"2018-07-05T17:29:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/18c-order-by-in-with-clause-is-not-preserved\\\/\"},\"wordCount\":439,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/#organization\"},\"keywords\":[\"In-Memory\",\"Oracle 18c\"],\"articleSection\":[\"Oracle\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/18c-order-by-in-with-clause-is-not-preserved\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/18c-order-by-in-with-clause-is-not-preserved\\\/\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/18c-order-by-in-with-clause-is-not-preserved\\\/\",\"name\":\"18c: Order by in WITH clause is not preserved - dbi services Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#website\"},\"datePublished\":\"2018-07-05T17:29:17+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/18c-order-by-in-with-clause-is-not-preserved\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/18c-order-by-in-with-clause-is-not-preserved\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/18c-order-by-in-with-clause-is-not-preserved\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"18c: Order by in WITH clause is not preserved\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/\",\"name\":\"dbi services Blog\",\"description\":\"#BeSharing\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/#organization\"},\"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\":\"Organization\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/#organization\",\"name\":\"dbi services\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/dbi-services-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/dbi-services-logo.png\",\"width\":512,\"height\":512,\"caption\":\"dbi services\"},\"image\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/dbiservices\\\/\",\"https:\\\/\\\/x.com\\\/dbiservices\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/dbi-services\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/dbiservices\"],\"description\":\"Swiss IT consulting and services company specialized in efficient data infrastructures and platforms: databases, application servers, cloud, DevOps, digitalization, analytics, data quality and monitoring. Headquartered in Del\u00e9mont with offices in Nyon, Basel, Bern and Zurich.\",\"email\":\"info@dbi-services.com\",\"telephone\":\"+41 32 422 96 00\",\"legalName\":\"dbi services SA\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/person\\\/bf7c7eb0bec165183207237c9d0ee1d5\",\"name\":\"Oracle Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/oracle-square.png\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/oracle-square.png\",\"contentUrl\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/oracle-square.png\",\"caption\":\"Oracle Team\"},\"description\":\"Posts published under the Oracle Team account are collective contributions by the dbi services Oracle consultants. The practice covers the full Oracle Database lifecycle: architecture, migration and upgrade, high availability with RAC and Data Guard, backup and recovery, performance tuning, and engineered systems such as Oracle Database Appliance and Exadata. The team holds Oracle certifications up to Certified Master level and operates customer platforms under service level agreements.\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/author\\\/oracle-team\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"18c: Order by in WITH clause is not preserved - dbi services 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\/18c-order-by-in-with-clause-is-not-preserved\/","og_locale":"en_US","og_type":"article","og_title":"18c: Order by in WITH clause is not preserved","og_description":"By Franck Pachot . For a previous post I&#8217;ve run on 18c a script of mine to get the V$MYSTAT delta values between two queries. This script (new version available on GitHub) generates the queries to store some values and subtract them on the next execution. But I had to fix it for 18c because&hellip;&nbsp;","og_url":"https:\/\/www.dbi-services.com\/blog\/18c-order-by-in-with-clause-is-not-preserved\/","og_site_name":"dbi services Blog","article_publisher":"https:\/\/www.facebook.com\/dbiservices\/","article_published_time":"2018-07-05T17:29:17+00:00","author":"Oracle Team","twitter_card":"summary_large_image","twitter_creator":"@dbiservices","twitter_site":"@dbiservices","twitter_misc":{"Written by":"Oracle Team","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/18c-order-by-in-with-clause-is-not-preserved\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/18c-order-by-in-with-clause-is-not-preserved\/"},"author":{"name":"Oracle Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/bf7c7eb0bec165183207237c9d0ee1d5"},"headline":"18c: Order by in WITH clause is not preserved","datePublished":"2018-07-05T17:29:17+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/18c-order-by-in-with-clause-is-not-preserved\/"},"wordCount":439,"commentCount":0,"publisher":{"@id":"https:\/\/www.dbi-services.com\/#organization"},"keywords":["In-Memory","Oracle 18c"],"articleSection":["Oracle"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/18c-order-by-in-with-clause-is-not-preserved\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/18c-order-by-in-with-clause-is-not-preserved\/","url":"https:\/\/www.dbi-services.com\/blog\/18c-order-by-in-with-clause-is-not-preserved\/","name":"18c: Order by in WITH clause is not preserved - dbi services Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2018-07-05T17:29:17+00:00","breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/18c-order-by-in-with-clause-is-not-preserved\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/18c-order-by-in-with-clause-is-not-preserved\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/18c-order-by-in-with-clause-is-not-preserved\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"18c: Order by in WITH clause is not preserved"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi services Blog","description":"#BeSharing","publisher":{"@id":"https:\/\/www.dbi-services.com\/#organization"},"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":"Organization","@id":"https:\/\/www.dbi-services.com\/#organization","name":"dbi services","url":"https:\/\/www.dbi-services.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/09\/dbi-services-logo.png","contentUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/09\/dbi-services-logo.png","width":512,"height":512,"caption":"dbi services"},"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/dbiservices\/","https:\/\/x.com\/dbiservices","https:\/\/www.linkedin.com\/company\/dbi-services\/","https:\/\/www.youtube.com\/user\/dbiservices"],"description":"Swiss IT consulting and services company specialized in efficient data infrastructures and platforms: databases, application servers, cloud, DevOps, digitalization, analytics, data quality and monitoring. Headquartered in Del\u00e9mont with offices in Nyon, Basel, Bern and Zurich.","email":"info@dbi-services.com","telephone":"+41 32 422 96 00","legalName":"dbi services SA"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/bf7c7eb0bec165183207237c9d0ee1d5","name":"Oracle Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/12\/oracle-square.png","url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/12\/oracle-square.png","contentUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/12\/oracle-square.png","caption":"Oracle Team"},"description":"Posts published under the Oracle Team account are collective contributions by the dbi services Oracle consultants. The practice covers the full Oracle Database lifecycle: architecture, migration and upgrade, high availability with RAC and Data Guard, backup and recovery, performance tuning, and engineered systems such as Oracle Database Appliance and Exadata. The team holds Oracle certifications up to Certified Master level and operates customer platforms under service level agreements.","url":"https:\/\/www.dbi-services.com\/blog\/author\/oracle-team\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/11398","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=11398"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/11398\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=11398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=11398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=11398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}