Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Index on partial field?

Re: Index on partial field?

From: Barry P. Grove <barry_grove_at_mindlink.bc.ca>
Date: 1997/01/31
Message-ID: <32F2C1D7.4633@mindlink.bc.ca>#1/1

Barbara Hiles wrote:
>
> Is it possible to create an index using part of a field?
> For example: 9 character ssn.
> I need an index on last 4 first 5.
> Can I do this if I've defined a 9 char ssn field? (and if so - how? substr?)
>
> tia - barb.

Hi Barb,

My first choice would be to define another field, and populate using a row trigger
that reorders the ssn in the format you described (last 4, first 5). Index this
field as well. eg:

  create or replace trigger yourtable_ssn     after insert or update of ssn
    on yourtable
    for each row
  begin
    if rtrim(:new.ssn) is not null then
      :new.ssn_reordered := substr(:new.ssn,6,4) || :substr(:new.ssn,1,5);

    end if;
  end;
  /

Yes, it would be nice of Oracle allowed for indexing of partial fields or
expressions, but we make do with what we've got.

Hope this helps....

-- 
Barry P. Grove                                  BCTEL  (604)432-4468
barry_grove_at_mindlink.bc.ca                      Human Resources
Consulting
Developer, Oracle DBA, Unix Sysadmin            6-3777 Kingsway,
Burnaby, BC
Received on Fri Jan 31 1997 - 00:00:00 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US