Ny way to use “like” operator during oracle table partitioning

oraclepartitioning

I am using Oracle 11g database and I have 45 million records. I want to partition the table, but if it's possible for partitioning to support the like operator then it will be much helpful for me.

In my table one column is URI, and for that column I want to use the like operator during partition so that it can help during insertion, because it contains different type of uris such as model://a/b or list://a/b.

I want something like:

CREATE TABLE table_name (
    URI varchar2(20);
)
PARTITION BY LIST ( URI )
      (PARTITION part_mod VALUES (like 'model://%'),
       PARTITION part_list VALUES (like 'list://%'),
       PARTITION part_def VALUES (default)
       );

I tried using Virtual Column-Based Partitioning but didn't get any success. Partitions were created, but during insertion no data is going into corresponding partitions; everything is going into part_def.

So is it possible to use the like operator to partition a table in oracle database?

Best Answer

Virtual column partitioning:

create table table_name (
    uri varchar2(20),
    part as (
      case 
        when uri like 'model://%' then 'mod'
        when uri like 'list://%' then 'list'
        else 'def'
      end
    )
)
partition by list (part) (
  partition part_mod values ('mod'),
  partition part_list values ('list'),
  partition part_def values ('def')
);

Seems to work:

insert into table_name (uri) values ('model://abc');
insert into table_name (uri) values ('list://abc');
insert into table_name (uri) values ('test://abc');

select * from table_name partition (part_mod);
select * from table_name partition (part_list);
select * from table_name partition (part_def);

Inserted rows are returned from correct partitions.