Home » SQL & PL/SQL » SQL & PL/SQL » Get data from various partitions with having one extra column (Oracle, Oracle Database 11g Express Edition Release 11.2.0.2.0 ,Win 7 Pro)
Get data from various partitions with having one extra column [message #639505] Wed, 08 July 2015 18:35 Go to next message
shumail
Messages: 149
Registered: September 2012
Location: Canada
Senior Member
HI All

I did my interview and interviewer asked me the following question:
How to Fetch table data in 10 partitions with having one extra  column


but unfortunately I didn't understand the above question but I'm curious what should be the answer for this question, Please guide.

So far I tried to do it by using Oracle 11g express but I think express edition not supported this feature, see below the steps I took and advice me accordingly


Sample Data
CREATE TABLE test2 
(sal NUMBER(5)
)
PARTITION BY RANGE(sal)
(
PARTITION sal_100 VALUES LESS THAN (101),
PARTITION sal_200 VALUES LESS THAN (201)
)
;


Query on single partition



select * from test2 partition ( sal_100);

Query on Multiple partition
select * from test2 partition ( sal_100)
union all
select * from test2 partition ( sal_200)


Please correct me if you find me wrong....

Regards

Muzz
Re: Get data from various partitions with having one extra column [message #639507 is a reply to message #639505] Thu, 09 July 2015 00:28 Go to previous messageGo to next message
Michel Cadot
Messages: 68776
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

The answer is: in the same way than with a non-partitioned table: using SELECT.

[Updated on: Thu, 09 July 2015 00:28]

Report message to a moderator

Re: Get data from various partitions with having one extra column [message #639519 is a reply to message #639507] Thu, 09 July 2015 02:59 Go to previous messageGo to next message
shumail
Messages: 149
Registered: September 2012
Location: Canada
Senior Member
Thanks Michel, you mean to say we have to use the following command in order to select data from partitions, see below

select * from test2 partition ( sal_100)
union all
select * from test2 partition ( sal_200)

or just use
select * from test2

Re: Get data from various partitions with having one extra column [message #639520 is a reply to message #639519] Thu, 09 July 2015 03:22 Go to previous messageGo to next message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
What Michel means is that you don't change your sql just because you're selecting from a partitioned table.
Imagine your table had no partitions and you wanted to get all of the data where salary was less than 200.
Would you
select *
from table where sal between 100 and 200
union
select *
from table where sal between 0 and 100;

Or would you select *
from table
where sal <200;

Re: Get data from various partitions with having one extra column [message #639527 is a reply to message #639520] Thu, 09 July 2015 04:07 Go to previous messageGo to next message
shumail
Messages: 149
Registered: September 2012
Location: Canada
Senior Member
Thanks for the reply but why oracle doc says that in order to select data from partition table you need to use the following query:
Query
select * from test2 partition ( sal_100);

Note:- sal_100 is a partition name
Re: Get data from various partitions with having one extra column [message #639529 is a reply to message #639527] Thu, 09 July 2015 04:24 Go to previous messageGo to next message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
shumail wrote on Thu, 09 July 2015 10:07
Thanks for the reply but why oracle doc says that in order to select data from partition table you need to use the following query:
Query
select * from test2 partition ( sal_100);

Note:- sal_100 is a partition name

Please link to the doc that says that, thanks (my bet is that, read in context, that's not actually what it's saying)
Re: Get data from various partitions with having one extra column [message #639530 is a reply to message #639529] Thu, 09 July 2015 04:41 Go to previous messageGo to next message
shumail
Messages: 149
Registered: September 2012
Location: Canada
Senior Member
Please see below:
http://docs.oracle.com/cd/E18283_01/server.112/e16541/part_admin001.htm

check out the following example under this document:

Example 4-21 Creating a multicolumn range-partitioned table
Re: Get data from various partitions with having one extra column [message #639531 is a reply to message #639530] Thu, 09 July 2015 04:48 Go to previous messageGo to next message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
OK, can you point out where it says that you need to use that method to access the table? Sorry, I can't see that bit. I can see that it is using that method as an example of how the table can be queried.
Re: Get data from various partitions with having one extra column [message #639532 is a reply to message #639531] Thu, 09 July 2015 04:58 Go to previous messageGo to next message
shumail
Messages: 149
Registered: September 2012
Location: Canada
Senior Member
Actually in this documents , I can see only this method for select data from partition table but as you and Michel said that I can access any partition table just like regular table so next time whenever interviewer asks me such kind of question then I will tell him or her that we use partition table just like a normal regular table . Please correct me if you find me wrong...
Re: Get data from various partitions with having one extra column [message #639533 is a reply to message #639532] Thu, 09 July 2015 05:06 Go to previous messageGo to next message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
IMHO, you are absolutely correct. To quote a very knowledgeable guy (Billy~Verreynne) oft seen over on OTN:
"It is wrong to use the partition clause in standard end-user or application SQL, for a very sound reason.

That reason is that the end-user and/or application: DOES NOT NEED TO KNOW THE PHYSICAL STORAGE CHARACTERISTICS OF THE OBJECTS BEING QUERIED.

Just as end-user/app does not need to know whether EMP is a synonym, a view, an index organised table, a hash table, or whatever else.. an end-user/app does not need to know in what partition data is to be found.
"
Re: Get data from various partitions with having one extra column [message #639534 is a reply to message #639533] Thu, 09 July 2015 05:10 Go to previous messageGo to next message
cookiemonster
Messages: 13975
Registered: September 2008
Location: Rainy Manchester
Senior Member
Personally I'm more curious about the one extra-column bit. I suspect some context got lost because I have no ides what he could have been driving at.
Re: Get data from various partitions with having one extra column [message #639535 is a reply to message #639533] Thu, 09 July 2015 05:11 Go to previous messageGo to next message
shumail
Messages: 149
Registered: September 2012
Location: Canada
Senior Member
Great. Thank you very much for this valuable information and I really appreciate your and Michel guidelines....
Re: Get data from various partitions with having one extra column [message #639537 is a reply to message #639534] Thu, 09 July 2015 05:18 Go to previous message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
Must admit, I just assumed 'lost in translation'
Previous Topic: Partition table - High_Value in DD-MON-YYYY format
Next Topic: Interesting explain plan output/puzzle
Goto Forum:
  


Current Time: Fri Aug 07 20:44:41 CDT 2026