{"id":3822,"date":"2023-08-08T19:46:23","date_gmt":"2023-08-08T19:46:23","guid":{"rendered":"http:\/\/van-maanen.com\/?p=3822"},"modified":"2023-08-08T19:46:23","modified_gmt":"2023-08-08T19:46:23","slug":"partitions-in-oracle","status":"publish","type":"post","link":"http:\/\/archief.van-maanen.com\/?p=3822","title":{"rendered":"Partitions in Oracle"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Oracle has the concept of partitions: the idea that a set of records is stored in one partition, that is directly accessible. This avoids the situation that large segments of data must be investigated before a record is found.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The code to generate such table is:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">CREATE TABLE \"HR\".\"FCT_BLN_ALLOC_USAGE\"\n( \"PROCESSING_DATE_SK\" NUMBER,\n\"INCREMENT_OFFSET_SEC\" NUMBER,\n\"ETL_REFRESH_DATE\" DATE,\n\"USG_ID\" VARCHAR2(50 CHAR),\n\"BLN_ID\" VARCHAR2(50 CHAR),\n\"ALN_ID\" VARCHAR2(50 CHAR),\n\"SOURCE_SYSTEM_ID\" VARCHAR2(3 CHAR)\n) PARTITION BY RANGE (\"PROCESSING_DATE_SK\") INTERVAL (1)\n(PARTITION \"P_FIRST\" VALUES LESS THAN (1)) ;\n\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"block-db8cda9b-b221-477f-807f-8fed9594ab43\">Based on the values that we enter for PROCESSING_DATE_SK, the record is positioned in one partition or another. <br><br>We can derive the partition names from next query:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">SELECT partition_name FROM dba_tab_partitions WHERE table_name = 'FCT_BLN_ALLOC_USAGE'; \n\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The partition names can then be used in a sql that derives the records from a certain partitiopn:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">select * from FCT_BLN_ALLOC_USAGE partition (SYS_P2932)\n\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">However, such action requires two steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Retrieve the partition names (which is often not allowed)<\/li>\n\n\n\n<li>Use the partition name in a sql statement.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">A more step is to retrieve the records in one statement. This looks like:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">SELECT *<br>FROM FCT_BLN_ALLOC_USAGE PARTITION FOR (2);<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Oracle has the concept of partitions: the idea that a set of records is stored in one partition, that is directly accessible. This avoids the situation that large segments of data must be investigated before a record is found. The code to generate such table is: CREATE TABLE &#8220;HR&#8221;.&#8221;FCT_BLN_ALLOC_USAGE&#8221; ( &#8220;PROCESSING_DATE_SK&#8221; NUMBER, &#8220;INCREMENT_OFFSET_SEC&#8221; NUMBER, &#8220;ETL_REFRESH_DATE&#8221; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-3822","post","type-post","status-publish","format-standard","hentry","category-niet-gecategoriseerd"],"_links":{"self":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/3822","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3822"}],"version-history":[{"count":0,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/3822\/revisions"}],"wp:attachment":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3822"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3822"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3822"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}