|
Re: How to partition Table Data Alphabetically [message #615194 is a reply to message #615192] |
Sat, 31 May 2014 03:32 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
And who is going to provide the test case? If not, at least create and insert statements please?
jgjeetu wrote on Sat, 31 May 2014 13:50my requirement is that name that starts with A should go in partition 1 , name starts with B should go in partition 2 and so on.
What if the name starts with 'a' and not 'A'? Don't you think they are different?
[Updated on: Sat, 31 May 2014 04:27] Report message to a moderator
|
|
|
|
|
Re: How to partition Table Data Alphabetically [message #615201 is a reply to message #615200] |
Sat, 31 May 2014 06:17 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
Solomon Yakobson wrote on Sat, 31 May 2014 16:32
PARTITION BY RANGE(NAME)
(
PARTITION A VALUES LESS THAN('B')
This would not only insert names starting with 'A', but would also insert if any name starts with numbers or a blank or any character with ASCII value less than 'B'.
And more importantly, it will not allow names starting with 'a' in lower case.
SQL> DROP TABLE myemp;
Table dropped
SQL> CREATE TABLE myemp (
2 empno NUMBER PRIMARY KEY,
3 ename VARCHAR2(30),
4 deptno NUMBER)
5 PARTITION BY RANGE (ename) (
6 PARTITION pa VALUES LESS THAN('B'));
Table created
SQL> INSERT INTO myemp SELECT 122, 'ALLEN', 30 FROM dual; -- normal case, goes to correct partition
1 row inserted
SQL> INSERT INTO myemp SELECT 123, 'aLLEN', 30 FROM dual; -- won't insert
INSERT INTO myemp SELECT 123, 'aLLEN', 30 FROM dual
ORA-14400: inserted partition key does not map to any partition
SQL> INSERT INTO myemp SELECT 124, '1LLEN', 30 FROM dual; -- would get inserted, so incorrect
1 row inserted
SQL> INSERT INTO myemp SELECT 125, ' LLEN', 30 FROM dual; -- would get inserted, so incorrect
1 row inserted
SQL> SELECT * FROM myemp PARTITION (pa);
EMPNO ENAME DEPTNO
---------- ------------------------------ ----------
122 ALLEN 30
124 1LLEN 30
125 LLEN 30
'aLLEN' is not inserted. And it mapped '1LLEN' and ' LLEN' partition key to partition 'pa'.
|
|
|
|
Re: How to partition Table Data Alphabetically [message #615203 is a reply to message #615202] |
Sat, 31 May 2014 07:37 |
John Watson
Messages: 8931 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
One could list partition on a virtual column of substr(ename,1,1) with 26 partitions plus a default partition for all the cases Lalit mentioned. That would be a precise solution. It does, however, make assumptions on character set. OP has not said how one should handle diacritics such as Ä .
|
|
|
|
|
Re: How to partition Table Data Alphabetically [message #615206 is a reply to message #615205] |
Sat, 31 May 2014 08:18 |
Solomon Yakobson
Messages: 3273 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
Solomon Yakobson wrote on Sat, 31 May 2014 08:51In general, we can create virtual column on any Oracle version supporting FBI.
Oops, after thinking about it for a moment, it wouldn't be possible to implement partitioning via FBI added column since we get catch 22. You can't create FBI before the table and we can't partition table without having FBI added virtual column.
SY.
|
|
|
|
Re: How to partition Table Data Alphabetically [message #615246 is a reply to message #615244] |
Sun, 01 June 2014 07:06 |
Solomon Yakobson
Messages: 3273 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
EdStevens wrote on Sun, 01 June 2014 07:34- There will not be an even distribution. For example, in the US, there are far, far more Smith's than Zagrobelny's.
And? Why partitions have to be of similar size? And if OP wants to do that, then S partition can be split into SA_to_SK, SL_to_SP, ...
EdStevens wrote on Sun, 01 June 2014 07:34- Even if, by convention, "most" names start with upper-case, that is not always the case. (d'Sousa, d'Angelo). And you certainly can't guarantee that some data entry person won't create a name with lower-case initial letter.
Then OP would have to create partition for d', de, al, etc. if there is a need to keep it that way or put check constraint enforcing upper case or a trigger uppercasing names.
SY.
[Updated on: Sun, 01 June 2014 07:09] Report message to a moderator
|
|
|
Re: How to partition Table Data Alphabetically [message #615297 is a reply to message #615246] |
Sun, 01 June 2014 15:01 |
|
EdStevens
Messages: 1376 Registered: September 2013
|
Senior Member |
|
|
Solomon,
I probably wasn't as clear as I should have been. I didn't mean to suggest that data had to be evenly distributed across partitions. It just seemed to me (perhaps reading too much between the lines) that even distribution was what the OP is trying to achieve, and I was trying to point out that his plan would not achieve that. My overall point was that we all need to step back from the technical problems of implementation and find out what the OP is really trying to achieve and why - and why he thinks partitioning by first letter of last name will do it.
|
|
|