How do I partition an Oracle 11g Table?


 
Thread Tools Search this Thread
Top Forums Programming How do I partition an Oracle 11g Table?
# 1  
Old 12-08-2014
How do I partition an Oracle 11g Table?

Hello,

I have a database called "audit_database" and I want to create two tables.

Table 1 = Table 1
Table 2 = Audit

I want to partition the Audit table into partitions grouped by month. I'm not familiar with table partitioning but doing some reading online shows that it can be done but how would I do this?

Code:
create table audit (month number(12),
  partition by range (month)
  partition 1 = january ...?

# 2  
Old 12-08-2014
If you are using 11g, then you want to use interval partitioning. Oracle will create a new partition every month for that months data. However, you might find that partitioning by day will work better, since you are working with audit data you might only look at the last day or last couple of days when querying the data. Having smaller level of granularity when used with partition pruning will likely lead to fewer io operator per query. Hence more efficient queries. You might also want to partition by month and sub partition by day. This will make it easier to drop a month at a time when you truncate old data, assuming that you do. You should be able to find plenty of examples for what you want on the web.

https://docs.oracle.com/cd/E18283_01...1.htm#BAJHFFBE
# 3  
Old 12-10-2014
Thanks for checking. I have this query and I thought i understood the interval partitioning, but it's giving me the following error. Can you help with the proper syntax please?


Code:
SQL Error: ORA-14752: Interval expression is not a constant of the correct type


Here is the statement.

Code:
CREATE TABLE "AUDIT_COLLECTION_EVENTS" 
   ("AUDIT_TS" TIMESTAMP (6) DEFAULT sysdate, 
    "AUDIT_ID" NUMBER(20,0) DEFAULT -1, 
     "EVENT_NAME" VARCHAR2(48 CHAR) DEFAULT (null), 
     "EVENT_VALUE" VARCHAR2(256 CHAR) DEFAULT (null), 
    "TABLE_TXN_ID" NUMBER(20,0)
   )
  TABLESPACE "AUDIT"
  
  PARTITION BY RANGE ("AUDIT_TS") INTERVAL (NUMTODSINTERVAL(1,'MONTH')) 
 (PARTITION "PART1"  VALUES LESS THAN (TO_DATE('2014-12-01', 'YYYY-MM-DD'));


Last edited by bbbngowc; 12-10-2014 at 10:27 AM..
# 4  
Old 12-10-2014
Quote:
Originally Posted by bbbngowc
Thanks for checking. I have this query and I thought i understood the interval partitioning, but it's giving me the following error. Can you help with the proper syntax please?


Code:
SQL Error: ORA-14752: Interval expression is not a constant of the correct type


Here is the statement.

Code:
CREATE TABLE "AUDIT_COLLECTION_EVENTS" 
   ("AUDIT_TS" TIMESTAMP (6) DEFAULT sysdate, 
    "AUDIT_ID" NUMBER(20,0) DEFAULT -1, 
     "EVENT_NAME" VARCHAR2(48 CHAR) DEFAULT (null), 
     "EVENT_VALUE" VARCHAR2(256 CHAR) DEFAULT (null), 
    "TABLE_TXN_ID" NUMBER(20,0)
   )
  TABLESPACE "AUDIT"
 
  PARTITION BY RANGE ("AUDIT_TS") INTERVAL (NUMTODSINTERVAL(1,'MONTH')) 
 (PARTITION "PART1"  VALUES LESS THAN (TO_DATE('2014-12-01', 'YYYY-MM-DD'));

You're using "NUMTODSINTERVAL"
you probably want to use: "NUMTOYMINTERVAL"
instead Smilie

Data Types
# 5  
Old 12-10-2014
wow. Simple as that. It worked.

Thanks a mil.
Login or Register to Ask a Question

Previous Thread | Next Thread

2 More Discussions You Might Find Interesting

1. Solaris

need help in oracle upgrade from 10g to 11g

Hi , situation has come where in i want to upgrade my database from 10g to 11g ,my code heavily depends on Pro*C , i just want to know if i upgrade my DB from 10g to 11g , will there be any changes in my pro*c compiler ..? if so then wat are the prerequisites i need to check ..? thanks ... (2 Replies)
Discussion started by: senkerth
2 Replies

2. Shell Programming and Scripting

Switching user to oracle to connect Oracle 11g DB with 'sysdba'

I need to connect my Oracle 11g DB from shell script with 'sysdba' permissions. To do this I have to switch user from 'root' to 'oracle'. I've tried the following with no success. su - oracle -c "<< EOF1 sqlplus -s "/ as sysdba" << EOF2 whenever sqlerror exit sql.sqlcode;... (2 Replies)
Discussion started by: NetBear
2 Replies
Login or Register to Ask a Question