• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 973
  • Last Modified:

Index problem : max lenght exceed


I'm working with Oracle 8.1, and I have a little problem.
I need to create an index (UNIQUE) on 10 columns. The problem is that 3 of this columns have are VARCHAR2 (255).

So each time I tried to create my table I have this error message : ORA-01450: maximum key length (758) exceeded.

I've tried to create the constrainte in Alter table instead in the create table... but it gives the same message.

And I cannot remove any field in the constraint... there's a way to do the job ?




ALTER TABLE InterventionPlans
    ADD CONSTRAINT UniqueInterventionPlans
    UNIQUE(AgencyId, ResponseTypeId, RecommendationId, Data1,
      Data2, Data3, AlarmLevel, FromWeekDay, FromTime, ToWeekDay, ToTime)
1 Solution
This primarily depends upon your DB_BLOCK_SIZE. I think your DB_BLOCK_SIZE is set to 2K. Here are the maximum key length associated with the DB_BLOCK_SIZE value. If possible change the BLOCK size and create the database again to acheive the higher value.

NOTE: You cannot change the DB_BLOCK_SIZE once the database has been created. To change it, you need to create the entire database again.

2K (2048)         758 Bytes
4K (4096)         1578 Bytes
8K (8192)         3218 Bytes
16K (16384)       6498 Bytes

From a Oracle document:

This is how is the max. number calculated?

The maximum key size means:

The total index length + length of the key (2 Bytes) + ROWID (6 Bytes) + the length of the rowid (1 byte).

The total index length is computed as the sum of the width of all indexed columns plus the number of indexed columns. Date fields have a length of 7, character fields have their defined length, and numeric fields have a length of 22. Numeric length = (precision/2) + 1. If negative, add +1. For Funtion-based indexes, we must calculate the length of the return type.

This index key size is limited by the value of db_block_size, because a key value may not span multiple blocks. In fact, it is required that any index block must contain at least TWO index entries per block.

Therefore, the maximum key length for an index will be less than half of the DB_BLOCK_SIZE. The Oracle 8i Administrator's Guide states that the maximum size of a single index entry is approximately one-half the data block size. However, when considering that we must also leave space in the blockaccording to PCTFREE, INITRANS, and space for block overhead (Block Header,ROW Directory, Table Directory, etc) the actual space that can be used for the Index key is actually just over 1/3 of the DB_BLOCK_SIZE.

Using default values for these storage options, the maximum length for indexes is as follows for different block sizes:

DB_BLOCK_SIZE: Maximum Index Key Length:
=============== =====================

2K (2048) 758 Bytes
4K (4096) 1578 Bytes
8K (8192) 3218 Bytes
16K (16384) 6498 Bytes

If you hit a maximum key length in an index according to the DB_BLOCK_SIZE, you may need to recreate the database with a larger block size. The otheralternative is to limit the size of the index. This is slightly more difficult with a Function-based index, when the return type is a varchar or RAW.

To limit the size of a function-based index you should consider using the SUBSTR or SUBSTRB function, to limit the number of Characters or Bytes returned. For more information on SUBTR and SUBSTRB, refer to the Oracle8i SQL Reference Guide.

Hope this helps!


There might be something wrong in your design if you have that many columns in your key. You might want to use a system-generated sequence number instead and store the other columns as not null attributes. With that many columns, joins will be real messy.
Please update and finalize this old, open question. Please:

1) Award points ... if you need Moderator assistance to split points, comment here with details please or advise us in Community Support with a zero point question and this question link.
2) Ask us to delete it if it has no value to you or others
3) Ask for a refund so that we can move it to our PAQ at zero points if it did not help you but may help others.



** Mindphaser - Community Support Moderator **

P.S.  Click your Member Profile, choose View Question History to go through all your open and locked questions to update them.
Recommended disposition:

    Accept mathavra's comment(s) as an answer.

DanRollins -- EE database cleanup volunteer
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now