Solved

Creating Oracle partitioned table

Posted on 2012-04-02
6
443 Views
Last Modified: 2012-04-11
I need to create a partition table that will have a Hash partition on batch_id .. Have a question..

Here is the table creation command that I plan to use:

CREATE TABLE mytab1
   (BATCH_ID NUMBER DEFAULT -1,
     ID number NUMBER(*,0),
     Field1 varchar2(10)
)
   PARTITION BY HASH(BATCH_ID)
STORE IN (MyTablespaceName1);


Is this a correct command to create the partitioned  table on BATCH_ID? The table gets created as above.

Does it create multiple partitions for separate group of  BATCH_ID values when they are inserted into the table?
Thank you...
0
Comment
Question by:toooki
  • 3
  • 2
6 Comments
 
LVL 8

Accepted Solution

by:
Christoffer Swanström earned 500 total points
ID: 37797814
You should add the number of partitions you want, e.g.:

CREATE TABLE mytab1
   (BATCH_ID NUMBER DEFAULT -1,
     ID number NUMBER(*,0),
     Field1 varchar2(10)
)
   PARTITION BY HASH(BATCH_ID) PARTITIONS 64
STORE IN (MyTablespaceName1);

If you don't include that you will get only 1 partition (not much of a partitioning...)
0
 

Author Comment

by:toooki
ID: 37797893
Thanks a lot. Ok if I use PARTITIONS 64

I wanted to know if the table has 100 different BATCH_ID values, does it still create only 64 partitions at the max? so there are multiple rows in the table with same BATCH_ID values that reside in the same partition?

Thank you.
0
 
LVL 8

Expert Comment

by:Christoffer Swanström
ID: 37798068
Yes, it will only create the number of partitions you define. Typically you will have lots of distinct key values for each partition.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 5

Expert Comment

by:Bajwa
ID: 37800958
You will have as many partitions as distinct value of batch_id
0
 
LVL 8

Expert Comment

by:Christoffer Swanström
ID: 37800993
Bajwa: that's not correct. If you do not specify the number of partitions, you will get one partition only, no matter how many distinct values you have for the the column that the table is partitioned on. If you specify the number of partitions, you will get exactly the number of partitions you specified, no more nor less.

You can verify the number of partitions you get when you do not specify the PARTITIONS clause by running the following:

DROP TABLE swc_tst;
CREATE TABLE swc_tst (
col1 NUMBER
)
PARTITION BY HASH(col1)
;

SELECT * FROM all_tab_partitions WHERE table_name = 'SWC_TST';

INSERT INTO SWC_TST VALUES(1);
INSERT INTO SWC_TST VALUES(2);
INSERT INTO SWC_TST VALUES(3);
INSERT INTO SWC_TST VALUES(4);
INSERT INTO SWC_TST VALUES(5);
COMMIT;

SELECT * FROM all_tab_partitions WHERE table_name = 'SWC_TST';

You still have only one partition after inserting multiple values...
0
 

Author Comment

by:toooki
ID: 37835255
Thanks a lot!! I now understand.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Oracle 12c patching 1 59
help on oracle query 5 30
SQL query question 8 31
Oracle - SQL Parse String 5 15
APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now