Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6750133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:46:20+00:00 2026-05-26T12:46:20+00:00

In oracle: I have a table rel with these columns (object_id1, object_id2) that relates

  • 0

In oracle: I have a table rel with these columns (object_id1, object_id2) that relates pairs of objects in a system. The object_ids are varchars and the first 3 chars identifies the type of the object. E.g. users start with 001 and books start with 002 but there are many more types. Now I’d like to get all user-book pairs that are related in this table with this query:

SELECT * FROM rel WHERE rel.object_id1 LIKE '001%' AND rel.object_id2 LIKE '002%'

To do this I’d need a b-tree index index on the first three chars of object_id1 and on object_id2. Is it possible to have an index on part of a column, in this case the first 3 chars? How?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:46:21+00:00Added an answer on May 26, 2026 at 12:46 pm

    You could create a function-based index

    CREATE INDEX idx_rel_obj_id
       ON( substr( object_id1, 1, 3 ),
           substr( object_id2, 1, 3 ) );
    

    But then your queries would need to use the same function calls

    SELECT *
      FROM rel
     WHERE substr( rel.object_id1, 1, 3 ) = '001'
       AND substr( rel.object_id2, 1, 3 ) = '002'
    

    Normally, you would create user-defined functions (i.e. get_object_type) that were marked as deterministic and would use those user-defined functions in both the index definition and the queries in order to ensure that someone doesn’t inadvertently use a different construct in order to get the first three characters of a field which would prevent the function-based index from being used.

    All that being said, having a column in a table where the first three characters represents some other data element is a violation of basic normalization. You’d almost always be better off storing the first three characters in a separate column rather than trying to parse the composite column at runtime.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table A in Oracle that has a primary key (id). I need
I have a table in an Oracle Database that has, among others, a DATE
(Using Oracle) I have a table with key/value pairs like this: create table MESSAGE_INDEX
I have a table in Oracle 10g that contains some information as follows: SQL>
I have an oracle table with nested tables in some of the columns. Now,
I have a table in an Oracle database that contains actions performed by users
I have a table with 14 columns in Oracle. All the columns are of
Ok this is the scenario... I have a table in Oracle that acts like
In my oracle database I have table called PERSON with columns code, surname, forename.
Say you have table of some items with these two columns: ItemName Price ....where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.