On Oracle 11g, you can partition on a virtual column, and this feature is useful, and here's a test:
Sql> select * from V$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0-64bit Production
PL/SQL Release 11.2.0.1.0-production
CORE 11.2.0.1.0 Production
TNS for Linux:version 11.2.0.1.0-production
Nlsrtl Version 11.2.0.1.0-production
sql> drop table test purge;
Sql> CREATE TABLE Test
(Bureau_code varchar2 () NOT NULL,
Province_code as (CAST (SUBSTR (bureau_code,0,2) as VARCHAR2 (2)))
)
Partition by list (Province_code)
(
Partition P1 values (' 01 '),
Partition P2 values (' 02 '),
Partition P3 VALUES (' 03 '),
Partition P4 values (' 04 '),
Partition P5 values (' 05 ')
);
sql> INSERT INTO Test (Bureau_code) VALUES (' 0101 ');
sql> INSERT INTO Test (Bureau_code) VALUES (' 0102 ');
sql> INSERT INTO Test (Bureau_code) VALUES (' 0202 ');
sql> INSERT INTO Test (Bureau_code) VALUES (' 0202 ');
sql> INSERT INTO Test (Bureau_code) VALUES (' 0302 ');
sql> INSERT INTO Test (Bureau_code) VALUES (' 0302 ');
sql> INSERT INTO Test (Bureau_code) VALUES (' 0402 ');
sql> INSERT INTO Test (Bureau_code) VALUES (' 0502 ');
sql> commit;
Sql> SELECT * FROM Test partition (P1);
Bureau_code PR
-------------------- --
0101 01
0102 01
Sql> Set Autotrace traceonly
Sql> SELECT * FROM Test partition (P1);
Execution plan
----------------------------------------------------------
Plan Hash value:213508695
----------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU) | Time | Pstart| Pstop |
----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2 | 30 | 4 (0) | 00:00:01 | | |
| 1 | PARTITION LIST single| | 2 | 30 | 4 (0) | 00:00:01 |1 | 1 |
| 2 | TABLE ACCESS Full | TEST | 2 | 30 | 4 (0) | 00:00:01 |1 | 1 | --to prove that the partition was gone
----------------------------------------------------------------------------------------------
Note
-----
-Dynamic sampling used for this statement (level=2)
Statistical information
----------------------------------------------------------
0 Recursive calls
0 db Block gets
8 Consistent gets
0 physical Reads
0 Redo Size
434 Bytes sent via sql*net to client
338 Bytes received via sql*net from client
2 sql*net roundtrips To/from Client
0 Sorts (memory)
0 Sorts (disk)
2 rows processed
Oracle 11g Virtual column built-in partitioning