Partition Interval by Month as Number
I have a table partitioned on a NUMBER field. The number values are Dates in the format of YYYYMM (so 201105 for May, 2011).
My question is can I setup a Partition Interval that can increment based on this format? I can't use NUMTOYMINTERVAL since this is a NUMBER field, but I also can't just use INTERVAL(1), since 201112 will not increment correctly to 201201 for this format.
How can I set this up to work or is it even possible?
Thanks for any help or advice!
Lazzrith, I think your assumption that you can't use an interval of 1 is incorrect. I don't see any reason not to use 1 as the interval. The whole point of interval partitioning is that Oracle will automatically create partitions to hold the data in your table, and nothing besides the data in your table. So, as 201112 rolls over into 201201 and you start inserting rows with 2012 dates, your table will get a new partition for the 201201 range. You won't also get partitions for 201113, 201114,...,201199 because no such dates exist in your table. As long as you don't accidentally insert a row with an invalid date, you will get exactly one partition for each month of the year, no more, no less.
Similar Messages
-
Hi experts,
i need a fm to convert the interval of two dates into months.
I have found RH_PM_CONVERT_DATE_TO_MONTH
for this. But i couldnt make it work from se37.
Can u help me ? Anyone can u make it work and say these are the parameters to enter.
Or u can tell me another fm for this
Thanks alothi check this..
REPORT ZDATEDIFF.
DATA: EDAYS LIKE VTBBEWE-ATAGE,
EMONTHS LIKE VTBBEWE-ATAGE,
EYEARS LIKE VTBBEWE-ATAGE.
PARAMETERS: FROMDATE LIKE VTBBEWE-DBERVON,
TODATE LIKE VTBBEWE-DBERBIS DEFAULT SY-DATUM.
call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
exporting
i_date_from = FROMDATE
i_date_to = TODATE
I_FLG_SEPARATE = ' '
IMPORTING
E_DAYS = EDAYS
E_MONTHS = EMONTHS
E_YEARS = EYEARS.
WRITE:/ 'Difference in Days ', EDAYS.
WRITE:/ 'Difference in Months ', EMONTHS.
WRITE:/ 'Difference in Years ', EYEARS.
INITIALIZATION.
FROMDATE = SY-DATUM - 60. -
How to get the number of days of a month belonging to a date interval
Hi, i am getting mad around a problem, i have 2 dates and a month, i wanto to retrieve the number of days belonging to the month that are in the interval.
eg:
month january 2011 . begin_date = 11/JAN/2011, END_DATE 30/MAY/2011 result is 21
month january 2011 . begin_date = 11/DEC/2010, END_DATE 10/JAN/2011 result 10
month january 2011 .begin_date = 02/FEB/2011 , END_DATE 25/may/2011 result 0
month january 2011. begin_date = 03/JAN/2011 , END DATE 05/JAN/2011 result 3
and so on ...
i appreciate any suggestion
thank you
AndreaOh, I didnt see your result.
SQL> with t as
2 (select to_date('11/01/11','dd/mm/yy') from_dt,
3 to_date('30/05/11','dd/mm/yy') to_dt,
4 'Jan-11' mnth from dual
5 union all
6 select to_date('11/12/10','dd/mm/yy') from_dt,
7 to_date('10/01/11','dd/mm/yy') to_dt,
8 'Jan-11' mnth from dual
9 union all
10 select to_date('02/02/11','dd/mm/yy') from_dt,
11 to_date('25/05/11','dd/mm/yy') to_dt,
12 'Jan-11' mnth from dual
13 union all
14 select to_date('03/01/11','dd/mm/yy') from_dt,
15 to_date('05/01/11','dd/mm/yy') to_dt,
16 'Jan-11' mnth from dual
17 )
18 select from_dt,to_dt,mnth,
19 greatest(
20 least(last_day(to_date(mnth,'Mon-yy')),to_dt)
21 -
22 greatest(to_date(mnth,'Mon-yy'),from_dt)+1
23 ,0) cnt
24 from t;
FROM_DT TO_DT MNTH CNT
11-JAN-11 30-MAY-11 Jan-11 21
11-DEC-10 10-JAN-11 Jan-11 10
02-FEB-11 25-MAY-11 Jan-11 0
03-JAN-11 05-JAN-11 Jan-11 3 -
Creating interval parition to existing range partition
I have a table which has range partition on a number column.
CREATE TABLE TEST(
id INT NOT NULL,
start INT NOT NULL
PARTITION BY RANGE (start)
PARTITION old_Data VALUES LESS THAN (1000000) TABLESPACE old,
PARTITION new_Data VALUES LESS THAN (MAXVALUE) TABLESPACE new
I would like to create monthly interval partition in old_data partition. Is this possible? Don't see any syntax for supporting this scenario.Welcome to the forum!
Whenever you post provide your 4 digit Oracle version.
>
I have a table which has range partition on a number column.
CREATE TABLE TEST(
id INT NOT NULL,
start INT NOT NULL
PARTITION BY RANGE (start)
PARTITION old_Data VALUES LESS THAN (1000000) TABLESPACE old,
PARTITION new_Data VALUES LESS THAN (MAXVALUE) TABLESPACE new
I would like to create monthly interval partition in old_data partition. Is this possible? Don't see any syntax for supporting this scenario.
>
No - it is not possible. There isn't any syntax for supporting that because integers do have have 'months' so how would Oracle partition an integer 'monthly'?
If those integers are supposed to represent Unix 'epoch' date values then in 11g you can create a virtual column of DATE datatype and partition on that.
But you will need to either recreate the table or, if you needed to do it online, use the DBMS_REDEFINITION package. Either approach results in a new table with the correct partitioning that includes the existing data.
Here is a similar table to yours with a VIRTUAL column that is partitioned by day:
drop table some_table_int
create table some_table_int (
column_1 nvarchar2(50),
start_t number(38,0),
column_n number,
start_date DATE GENERATED ALWAYS AS (
to_timestamp(to_char( to_date('01011970','ddmmyyyy') + 1/24/60/60 * start_t, 'DD-MON-YYYY HH24:MI:SS'),'DD-MON-YYYY HH24:MI:SS')
) VIRTUAL
partition by range (start_date) interval (NUMTODSINTERVAL(7,'day'))
(partition p_19700105 values less than (to_date('19700105', 'yyyymmdd'))
/That VIRTUAL column is an ordinary DATE column and your ranges will be dates rather than numbers that have no meaning for anyone.
The VIRTUAL column is only a data dictionary entry so it won't affect any actual data. -
Hi,
Using Oracle 11.20.3
We wish to have a range-hash composite partitioned table, one partition for each month.
However, want to esnure are always a partition tehrfore would like to use range interval partitioning.
Have a few questions, if have partition say 201301 to 201312 but get somew rosw which have value in date in June 2014 would it create
a new partition for each month i.e 201401, 201402 etc or just one for 201406?
Wanyt esnure system can cope automatically with following scenario
Daty1 have partitions 201301 to 201312
Day2 get record for 201406 (June 2014)
Day 3 get record for 201403 (March 2014)
We have no control of the range of dates we could get but don't want tpo have to manually create partitions fro all tehse dates in advance - want system to handled it automatically.
Also can you simply rename the system generated partition names to something more meaningful later.>
Using Oracle 11.20.3
We wish to have a range-hash composite partitioned table, one partition for each month.
However, want to esnure are always a partition tehrfore would like to use range interval partitioning.
Have a few questions, if have partition say 201301 to 201312 but get somew rosw which have value in date in June 2014 would it create
a new partition for each month i.e 201401, 201402 etc or just one for 201406?
Wanyt esnure system can cope automatically with following scenario
Daty1 have partitions 201301 to 201312
Day2 get record for 201406 (June 2014)
Day 3 get record for 201403 (March 2014)
We have no control of the range of dates we could get but don't want tpo have to manually create partitions fro all tehse dates in advance - want system to handled it automatically.
>
Do NOT be afraid of breaking Oracle by actually trying things yourself.
DROP TABLE emp_part
CREATE TABLE emp_part (empno number(4), ename varchar2(10),
deptno number(2), created_date DATE default sysdate)
partition by range (created_date)
SUBPARTITION BY HASH(deptno) subpartitions 4
( partition p_prior_to_2014 values less than (to_date('01-01-2014', 'mm-dd-yyyy')));Add some data for 2014 and see for yourself what happens.
>
Also can you simply rename the system generated partition names to something more meaningful later.
>
Yes - assuming you mean more meaninful to a human. Oracle doesn't care what the name is.
And you can just as easily manipulate the partition (delete, insert, drop truncate) regardless of the name since you don't need to use the name to do those things.
You either know the date for the partition you want to work with or you don't. If you know then just tell Oracle and it will work with the correct partition. If you don't believe me try it with the sample code I gave you. Add some data to get a couple of interval partitions created and then drop one of them using Oracle's extended partition syntax. See this example in the 'Dropping Interval Partitions in the VLDB and Partitioning Guide
http://docs.oracle.com/cd/B28359_01/server.111/b32024/part_admin.htm#i1007479
>
The following example drops the September 2007 interval partition from the sales table. There are only local indexes so no indexes will be invalidated.
ALTER TABLE sales DROP PARTITION FOR(TO_DATE('01-SEP-2007','dd-MON-yyyy'));
>
That code doesn't require the partition name. You just need to specify a date that falls IN the partition that you want to drop. You have to do that whether you know the name of the partition or not. Don't 'gunk up' your system with code to rename things unless there is some real need to. -
Range partiotion using interval partitioning
Hi all,
I am trying to create a partitioned table so that a number (which date converted to number ) partition is created on inserting a new row for release_date column.
But please note that release_date column is having number data type (as per design) and people want to create an interval based partition on this.
Any work around for this?
They want data type NOT to be altered.
create table product(
prod_id number,
prod_code varchar2(3),
release_date number)
partition by range(release_date)
interval(NUMTOYMINTERVAL (1,'MONTH'))
(partition p0 values less than (20120101))
Thanks in advance>
I am trying to create a partitioned table so that a number (which date converted to number ) partition is created on inserting a new row for release_date column.
But please note that release_date column is having number data type (as per design) and people want to create an interval based partition on this.
>
You can't use interval partitioning on the NUMBER column but you can add a VIRTUAL column based on it that uses DATE datatype.
create table product(
prod_id number,
prod_code varchar2(3),
release_date number,
rel_date DATE as (to_date(to_char(release_date), 'yyyymmdd')) VIRTUAL
partition by range(rel_date)
interval(NUMTOYMINTERVAL (1,'MONTH'))
partition p0 values less than (to_date('20120101', 'yyyymmdd'))
)The virtual column is a metadata only column (i.e. no data is stored for it).
NOTE: you will need to modify your queries to use the 'REL_DATE' column in order to get partition pruning:
insert into product (prod_id, prod_code, release_date) values (1,'abc', 20110502)
insert into product (prod_id, prod_code, release_date) values (1,'abc', 20120502)
-- this query does NOT prune
select * from product where release_date < 20120101
| 0 | SELECT STATEMENT | | 1 | 38 | 4 (0)| 00:00:01 | | |
| 1 | PARTITION RANGE ALL| | 1 | 38 | 4 (0)| 00:00:01 | 1 |1048575|
|* 2 | TABLE ACCESS FULL | PRODUCT | 1 | 38 | 4 (0)| 00:00:01 | 1 |1048575|
-- this query DOES prune
select * from product where rel_date < to_date('20120101', 'yyyymmdd')
| 0 | SELECT STATEMENT | | 1 | 38 | 3 (0)| 00:00:01 | | |
| 1 | PARTITION RANGE SINGLE| | 1 | 38 | 3 (0)| 00:00:01 | 1 | 1 |
|* 2 | TABLE ACCESS FULL | PRODUCT | 1 | 38 | 3 (0)| 00:00:01 | 1 | 1 | -
We have tables that are interval range partitioned on a DATE column, with a partition for each day - all very standard and straight out of Oracle doc.
A 3rd party application queries the tables to find number of rows based on date range that is on the column used for the partition key.
This application uses date range specified relative to current date - i.e. for last two days would be "..startdate > SYSDATE -2 " - but partition pruning does not take place and the explain plan shows that every partition is included.
By presenting the query using the date in a variable partition pruning does table place, and query obviously performs much better.
DB is 11.2.0.3 on RHEL6, and default parameters set - i.e. nothing changed that would influence optimizer behavior to something unusual.
I can't work out why this would be so. It very easy to reproduce with simple test case below.
I'd be very interested to hear any thoughts on why it is this way and whether anything can be done to permit the partition pruning to work with a query including SYSDATE as it would be difficult to get the application code changed.
Furthermore to make a case to change the code I would need an explanation of why querying using SYSDATE is not good practice, and I don't know of any such information.
1) Create simple partitioned table
CREATETABLE part_test
(id NUMBER NOT NULL,
starttime DATE NOT NULL,
CONSTRAINT pk_part_test PRIMARY KEY (id))
PARTITION BY RANGE (starttime) INTERVAL (NUMTODSINTERVAL(1,'day')) (PARTITION p0 VALUES LESS THAN (TO_DATE('01-01-2013','DD-MM-YYYY')));
2) Populate table 1million rows spread between 10 partitions
BEGIN
FOR i IN 1..1000000
LOOP
INSERT INTO part_test (id, starttime) VALUES (i, SYSDATE - DBMS_RANDOM.value(low => 1, high => 10));
END LOOP;
END;
EXEC dbms_stats.gather_table_stats('SUPER_CONF','PART_TEST');
3) Query the Table for data from last 2 days using SYSDATE in clause
EXPLAIN PLAN FOR
SELECT count(*)
FROM part_test
WHERE starttime >= SYSDATE - 2;
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
| 0 | SELECT STATEMENT | | 1 | 8 | 7895 (1)| 00:00:01 | | |
| 1 | SORT AGGREGATE | | 1 | 8 | | | | |
| 2 | PARTITION RANGE ITERATOR| | 111K| 867K| 7895 (1)| 00:00:01 | KEY |1048575|
|* 3 | TABLE ACCESS FULL | PART_TEST | 111K| 867K| 7895 (1)| 00:00:01 | KEY |1048575|
Predicate Information (identified by operation id):
3 - filter("STARTTIME">=SYSDATE@!-2)
4) Now do the same query but with SYSDATE - 2 presented as a literal value.
This query returns the same answer but very different cost.
EXPLAIN PLAN FOR
SELECT count(*)
FROM part_test
WHERE starttime >= (to_date('23122013:0950','DDMMYYYY:HH24MI'))-2;
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
| 0 | SELECT STATEMENT | | 1 | 8 | 131 (0)| 00:00:01 | | |
| 1 | SORT AGGREGATE | | 1 | 8 | | | | |
| 2 | PARTITION RANGE ITERATOR| | 111K| 867K| 131 (0)| 00:00:01 | 356 |1048575|
|* 3 | TABLE ACCESS FULL | PART_TEST | 111K| 867K| 131 (0)| 00:00:01 | 356 |1048575|
Predicate Information (identified by operation id):
3 - filter("STARTTIME">=TO_DATE(' 2013-12-21 09:50:00', 'syyyy-mm-dd hh24:mi:ss'))
thanks in anticipation
JimAs Jonathan has already pointed out there are situations where the CBO knows that partition pruning will occur but is unable to identify those partitions at parse time. The CBO will then use a dynamic pruning which means determine the partitions to eliminate dynamically at run time. This is why you see the KEY information instead of a known partition number. This is to occur mainly when you compare a function to your partition key i.e. where partition_key = function. And SYSDATE is a function. For the other bizarre PSTOP number (1048575) see this blog
http://hourim.wordpress.com/2013/11/08/interval-partitioning-and-pstop-in-execution-plan/
Best regards
Mohamed Houri -
INTERVAL YEAR TO MONTH datatype gives errors
when I run the following it complains about INTERVAL YEAR TO MONTH datatype ???
CREATE TABLE product_information
( product_id NUMBER(6)
, product_name VARCHAR2(50)
, product_description VARCHAR2(2000)
, category NUMBER(2)
, weight_class NUMBER(1)
, warranty_period INTERVAL YEAR TO MONTH
, supplier_id NUMBER(6)
, product_status VARCHAR2(20)
, list_price NUMBER(8,2)
, min_price NUMBER(8,2)
, catalog_url VARCHAR2(50)
, CONSTRAINT product_status_lov
CHECK (product_status in ('orderable','planned','under development','obsolete')
) ;I wasn't aware that INTERVAL is a datatype. The SQL reference manual discusses INTERVAL in the context of functions and literal constants.
null -
How to switch Skype number from 3-month plan to an...
A friend initially subscribed to 3-months Skype number plan. Now she would like to change to 1-year subscription. However, there does not seem to be any option to do this. The initial 3 months just passed and an automatic charge appeared on her payment card. There does not seem to be any "modify" subscription option (not even a "cancel" subscription option). There is no Skype/Microsoft support readily available. This is very bad experience for her and it seems to be rather common issue. I am actually surprised by this and have expected more from Skype/Microsoft. Any ideas about how to change the subscription?
Hi, PetrVeprek, and welcome to the Community,
As strange as this sounds, the short-term Skype Number contract needs to be cancelled. When the subscription ends, the Skype Number is held in reserve for a period of 90 days, during which timeframe the number can be renewed for an annual term.
If all else fails, please contact Skype customer service for further assistance. I would report to Customer Service that the renewal e-mails were not received - after checking that the account's registered e-mail address is correct! You would not believe the number of enquiries I read where a Skype account's registered e-mail address has fallen into disuse, not updated, and therefore resulting in no communications received from Skype.
Regards,
Elaine
Was your question answered? Please click on the Accept as a Solution link so everyone can quickly find what works! Like a post or want to say, "Thank You" - ?? Click on the Kudos button!
Trustworthy information: Brian Krebs: 3 Basic Rules for Online Safety and Consumer Reports: Guide to Internet Security Online Safety Tip: Change your passwords often! -
Problem in Number range Interval in VF02
Hi All,
I am using Number range USEREXIT for invoice creation- VF01.
So, while creating invoice, userexit will trigger, as per our logic provided,system generating numbers as expected.- which is working fine.
Where as, in VF02, transaction , i was trying to release invoice to Accounting,
system prompts with the below error message.
Fyi, in my invoice doc type: Number range- interval-19, which has numbers mentioned in the error message below:
am expecting, that when i release invoice to accounting from VF02 transaction, system triggering number range from invoice doc type,- But I dont understand, why it is triggering number range interval again, for which number is already createed in VF01
Error Message:
Incorrect doc.no.: 9003000002. Select document number between 0090000000 and 0094999999
Can someone, have any inputs??
Thanks in advanceHi,
You can make use of exit userexit_number_range inside RV60AFZZ.
Regards,
Babul. -
How to extract the number of employees (Head count) in a particulr month
Hi Experts,
We are trying to have a customized report on Having the employee headcount for a particular month with number of employees joined on the month and number of employees left the organisation.What is the way to get it.
Please advice.
V Sai.Hi Vicky Sai,
The standard report is S_PH9_46000223 - EEs Entered and Left
If you want to obtain the numbers in the same screen you should do the following1
1 - access the report
2 - further selection button - select Action type and move it to the Selection fields (you will get it on the screen)
3 - select action Hiring and action Leaving (so that the report will only count these elements)
4 - Period - current month
5 - run the report
6 - you will now have to see the number of employees (unfortunately you cannot do Sum here as you could do in a Querry that you would build as you would add the Count field so we need to do a little trick)
7 - Change layout icon - View tab- select Preferred view instead of SAP List viewer ->Microsoft Excel
8 - Select a template - press save
9 - You will see now the report in the Excel format. You can do sums if you want, add formulas, or you simply delete the first line and just look at the latest line filled in (total number of EE who left or were hired during the month)
If you do your own Querry - you can skip the Excel part and make a screen variant with the Sums.
At least now you have 2 options that you can choose from
Regards,
Adriana -
Subject: Number Range interval deleted automatically
Hi
At the time of Accounting Document Posting system is giving error message for maintaining number ranges interval for the corresponding Number Ranges (For example: 50, 51, 49, 19) for the fiscal year 2010. But Number range interval has already been maintained in the Tcode FBN1 for the fiscal year 2010.
After maintaining Number range interval again for the corresponding number range in Tcode FBN1, when we are trying to post accounting document system is again giving one error message that document number (5000000000) is already been used. When we are looking into Tcode FBN1 the current number status is 0.
So to resolve this problem we have to provide the Number range status into FBN1 manually (suppose if 10 doc are already existing in the system for number range 50 then we have enter the number range 5000000010 manually in FBN1).
After Number range status setting in FBN1 System is allowing to post the Accounting Document.
Along with this one more issue is appearing related to MM posting period.
The current posting period in the system is 08/2010 and the initial period in the system is 08/2007. System is automatically going back to the initial posting period 08/2007. After opening the Posting Period with Tcode MMPV we can post the document only.
Both Issues are appearing repeatedly.
Plese help
Thanks..
BRSRDear If you have already maintained number range for particular period then again for same period and series system should not allow to maintain but as you said above it is allowed so i feel it was not done correctly first time and the given series number could have already been used so when changed the current number in status it's working fine.
For MM posting period issue please check transactions MMRV,OMSY,OMWD with your MM consultant
Cheers
KK
Edited by: kiran kumar on Oct 19, 2010 8:32 PM -
How To Split One Record into 30 Records(Number of days in a Month)
Hi Experts,
we are getting the montly(yearmonth) Forecast data from flat file we need to generate the report which shows the daily Forecast data,
For example for the month of June Forecast we have 150EA.
Flat file data is like this
0calday Qty
201006 150
we need to show the report like datawise
Calday Forecast qty
20100601 5
20100602 5
20100603 5
20100604 5
20100605 5
20100606 5
20100630 5
its like month forecast / Number of days in a month.
we can achive these in two ways as per my knowledge
1. At the time loading data
2. Reporting level
Which is the best way
how can we achive this.
Thanks
ChandraHey. There was a similar posting I gave a suggestion on a while back. Here is the link...
Re: Spliting records into cube
As far as the correct time of doing this, I would definitely do this at the time of data load and not time of reporting.
Hope you find it helpful.
Thanks -
Online Number, 12 month subscription
I paid $80.00 for a 12 month Online number - I am not sure what this means & how it works & what I am entitled to do with it (pretty naive hey). I am confuses with this & another payment I made that entitles me to use Sype to make mobile voice calls where I paid $15.00 & that shows me each time I log on that now I have about $9.00 worth of credit left - what is the difference & how do I use each one?? I am very confused together with voice calls & video calls?? Please help me understand it is all too much I need a simple basic answers please - cheers Jack
An online number is for inbound calls only. Say I call you and you can answer on skype.
Do you have a subscription, and if you do what kind of subscription do you have? If it is a world subscription most mobiles are not covered. So you need skype credit. Hope this helps.
If you found a post useful, please give Kudos. If it helped to fix your issue, mark it as a solution to help others.
Thank You! -
Change monthly partitions to daily
My table is partitioned on a monthly base. They asked to change those partitions in days.
How can I do ?
I was thinking to create a temporary table...
I'm using 10gR2Of course you can create that temp table with the new day partition;
then move the data from your monthly partitioned table to temp table;
Finally rename your monthly partitioned table to "your_old_monthly_table" and temp table to your current montly partitioned table.
Maybe you are looking for
-
#WORKSPACE_IMAGES# ussage question?
When we use #WORKSPACE_IMAGES#, picture is retrieved from database, issuing db_connection and select on database. When we use #IMAGE_PREFIX# pictures are retrieved from classic file system. When should we use #WORKSPACE_IMAGES#, which require more sy
-
How to fix the Timing issue in Discoverer reports
Hi, While running the discoverer report in Discoverer plus is taking more than 1 hour to complete( Gen.time + Extract to excel) where as the same report completes quickly in discoverer desktop. how to fix the timing issue in discoverer plus Thanks S
-
MY Photo Editor will not open.
In my Photoshop Elements 12 - the ORGANIZER program wil open OK, but the PHOTO EDITOR will not open.
-
I have a simple question. Can someone tell me how to access the management port on the css 11150? I configured the ip and mask on the management port and condigured my laptop for a ip on the same network. But i am unable to connect.
-
Main Out EQ to compensate for my room's emphasis?
Hello. I recently purchased and set up a pair of M-Audio BX5as for my home studio. After running a few tests, I discovered some distinct frequencies that are extremely emphasized by the space I am working in. I wondering if there is a software soluti