# Virtual partitioning

## If you want to divide a table into an equal number of partitions by rowid range then you can use this SQL.

If you want to divide a table into an equal number of partitions by rowid range then you can use the following...

SQL. Just replace the with the actual table and run. When asked for input, enter the number of rows you want in each partition.

```
1 select
2  (CASE WHEN (
3     case when rnum = 1 OR mod(rnum,&&PART)= 1 then ceil(rnum/&&PART) end)
4          IS NOT NULL AND
5            (case when mod(rnum,&&PART)= 0 OR mod(rnum,total) = 0 then
6                    ceil(rnum/&&PART) end) IS NOT NULL
7       THEN
8            (NVL((case when rnum = 1 OR mod(rnum,&&PART)= 1 then
9                                  ceil(rnum/&&PART) end),0) +
10             NVL((case when mod(rnum,&&PART)= 0 OR mod(rnum,total) = 0 then
11                              ceil(rnum/&&PART) end),0))/2
12       ELSE
13            (NVL((case when rnum = 1 OR mod(rnum,&&PART)= 1 then
14                                  ceil(rnum/&&PART) end),0) +
15            NVL((case when mod(rnum,&&PART)= 0 OR mod(rnum,total) = 0 then
16                              ceil(rnum/&&PART) end),0))
17       END) seq
18  ,MAX((case when rnum = 1 OR mod(rnum,&&PART)= 1 THEN b.rid end)) lrowid
19  ,MAX((CASE WHEN mod(rnum,&&PART)= 0 OR mod(rnum,total) = 0
20                    THEN b.rid end)) hrowid
21  ,MAX((case when rnum = 1 OR mod(rnum,&&PART)= 1 THEN b.rnum end)) lrnum
22  ,MAX((CASE WHEN mod(rnum,&&PART)= 0 OR mod(rnum,total) = 0
23                    THEN b.rnum end)) hrnum
24  ,(MAX((CASE WHEN mod(rnum,&&PART)= 0 OR mod(rnum,total) = 0
25                    THEN b.rnum end))
26  -MAX((case when rnum = 1 OR mod(rnum,&&PART)= 1 THEN b.rnum end))+1) recnum
27  from (
28  select rid,total,rnum from
29  (
30  select rowid rid
31  ,count(rowid) over () total
32  ,row_number() over (order by rowid) rnum
33  from <TABLE_NAME>
34  ) )b
35  where b.rnum IN (1,total
36  ,case when mod(rnum,&&PART) = 0 OR mod(rnum-1,&&PART) = 0 then rnum end)
37  group by
38      (CASE WHEN (
39        case when rnum = 1 OR mod(rnum,&&PART)= 1 then ceil(rnum/&&PART) end)
40                    IS NOT NULL AND
41                (case when mod(rnum,&&PART)= 0 OR mod(rnum,total) = 0 then
42                                     ceil(rnum/&&PART) end) IS NOT NULL THEN
43       ( NVL((case when rnum = 1 OR mod(rnum,&&PART)= 1 then
44                                  ceil(rnum/&&PART) end),0) +
45         NVL((case when mod(rnum,&&PART)= 0 OR mod(rnum,total) = 0 then
46                              ceil(rnum/&&PART) end),0))/2
47       ELSE
48       ( NVL((case when rnum = 1 OR mod(rnum,&&PART)= 1 then
49                                  ceil(rnum/&&PART) end),0) +
50         NVL((case when mod(rnum,&&PART)= 0 OR mod(rnum,total) = 0 then
51                              ceil(rnum/&&PART) end),0))
52       END)
53  /
```

• The Best Oracle Web Links: tips, tutorials, scripts, and more.
• Have an Oracle tip to offer your fellow DBA's and developers? The best tips submitted will receive a cool prize--submit your tip today!
• Check out our Ask the Experts feature: Our SQL, database design, Oracle, SQL Server, DB2, metadata, and data warehousing gurus are waiting to answer your toughest questions.

This was last published in December 2001

## Content

Find more PRO+ content and other member only offers, here.

#### Start the conversation

Send me notifications when other members comment.

## SearchDataManagement

• ### With better scaling, semantic technology knocks on enterprise's door

Cambridge Semantics CTO Sean Martin says better scalability can lead to richer representations of data. Such advances are behind ...

• ### Big data management and analytics weather tumult -- with more in store

Cloud had a big impact on big data management and analytics last year. Machine learning and streaming designs will contribute to ...

• ### Embedded analytics to feel widest impact of machine learning projects

Ovum analyst Tony Baer discusses machine learning tools, IoT-driven streaming analytics and Hadoop in the cloud, all of which ...

• ### Cognitive computing applications present new business challenges

When implementing cognitive software, enterprises need to worry just as much -- if not more -- about the business implications, ...

• ### Researchers work on AI algorithms to detect fake news

A new challenge to identify fake news will test the boundaries of AI technology and offer a proving ground for innovative new ...

• ### Don't let a data-driven approach ax judgment from analytics equation

Data analytics can help improve decision-making in organizations. But human intuition and judgment need to be part of the picture...

## SearchSAP

• ### SAP HANA, express edition makes HANA easier for non-SAP developers

Relaxed RAM and licensing requirements and the ability to run on local machines could help popularize the HANA in-memory platform...

• ### SAP futurists name five future technology trends to plan for now

Three SAP futurists explain what future technology trends in augmented reality, blockchain, AI, robotics, and contingent labor ...

• ### Abakus acquisition beefs up SAP Hybris marketing portfolio

SAP acquires Abakus marketing measurement software for SAP Hybris marketing suite; openSAP adds new courses for S/4HANA, data ...

## SearchSQLServer

• ### Four trends that will impact SQL Server DBAs in 2017

Flash storage adoption, cloud computing's growth, Linux's increased importance and broader big data integration are a few trends ...

• ### DATEADD and DATEDIFF SQL functions for datetime values

DATEADD and DATEDIFF SQL functions allow you to easily perform calculations, like adding a time interval from a datetime value. ...

• ### SQL Server on Linux signals Microsoft's changing development landscape

Expert Joey D'Antoni explains what SQL Server on Linux and the addition of some Enterprise Edition features to the database's ...

## TheServerSide

• ### Is JSON and XML your REST performance bottleneck?

Learn how ASCII encoding formats like JSON and REST can adversely impact server application performance compared with emerging ...

• ### Making multi-cloud deployment a reality at Netflix with Spinnaker

Learn how Netflix leveraged automation and Spinnaker to perform 4,000 multi-cloud deployments per day.

• ### The benefits of Java microservices in a Docker and DevOps world

To seasoned developers, microservices may sound like SOA by another name. But Java microservices apps delivered via Docker ...

## SearchDataCenter

• ### What should my dimensions be for a data center building design?

Don't get hung up on data center dimensions in the design phase. Focus on length-to-width ratios to get the most out of data ...

• ### Use a Linux file system journal for data integrity, performance

Understand the three different file system journaling modes for Linux, as well as which mount option provides the best levels of ...

• ### Test yourself on modern data center networking architecture

Evolving business needs demand a new approach to data center networking. Keep yourself updated on SDN, VXLAN and other ...

## SearchContentManagement

• ### Using Microsoft MyAnalytics to improve workers' time management

Microsoft MyAnalytics has been hailed as the next great thing for analyzing worker productivity. But how can employees be assured...

• ### Is the Drupal content management system right for your business?

The open source Drupal content management system offers users responsive design and WYSIWYG content and web development tools, as...

• ### Manage your content with the IBM Digital Experience WCM platform

IBM Digital Experience is a WCM platform that offers users features for creating and managing digital content that can be ...

## SearchFinancialApplications

• ### Group-chat software sees explosive growth and intense competition

Microsoft Teams and Workplace by Facebook are facing off against rivals such as HipChat and Slack in a high-stakes competition ...

• ### HR to face sea change in online learning software and accent on teams

Deloitte predicts far-reaching trends for HR, including innovations in learning, an expansion of artificial intelligence, and an ...

• ### Experts lack consensus on discrimination risks of video interviewing

When used too early in the hiring process, video can lead to discrimination based on race, age or sex, but it can have positive ...

Close