Click here to Skip to main content
15,904,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have written oracle 11g procedure which will select records based on where conditions.
Problem is my table columns all are varchar2 types with has no index and I can't expect in future also.
My procedure need to return huge result set based on nearly 5 conditions on where clause from the same table.Please help in speed up my procedure result set.

table structure.
SQL
(id(number(PK)),
item_code(varchar),
item_desc(varchar),
1_code(varchar),
1_desc(varchar),
2_code(varchar),
2_desc(varchar),
3_code(varchar),
3_desc(varchar),
4_code(varchar),
4_desc(varchar),
5_code(varchar),
5_desc(varchar));

My query need to return
SQL
id,item_code,item_desc
in 5 cases like..
SQL
where 1_code=1_code_in;
where 1_code=1_code_in and 2_code=2_code_in;
where 1_code=1_code_in and 2_code=2_code_in and 3_code=3_code_in;

till 5_code
Posted
Updated 13-Dec-13 9:05am
v2
Comments
[no name] 7-Dec-13 12:23pm    
Ok I have first to mention I do not know Oracle...but I work a lot with SQL
a.) A lot of select statements have a where clause (which is really good, not to blow up the result set)
b.) What is the problem to define an index? If this is the problem then it ends in "I need a perfect solution but I can't make the basics suitable for this"
s#@!k 7-Dec-13 12:32pm    
I don't know do i create index on varchar2(100) type column which has 6 lacks records.Do i create it in procedure?
[no name] 7-Dec-13 12:37pm    
As I mentioned I do not know the deatils of Oracle. But generally creating an index is nothing more like "CREATE [UNIQUE] [ASC[ENDING] | DESC[ENDING]] INDEX index

ON table (col [, col …]);

E.g for an non unique ascending index for field f1 in table t1:

CREATE INDEX MyIndexName ON t1 (f1)
Jörgen Andersson 7-Dec-13 17:30pm    
Take the DBA out the back and shoot him.
Now fix the column types and add appropriate indexes.
thatraja 9-Dec-13 7:34am    
Agree

1 solution

It looks to me that just one added composite index would do the job:
SQL
CREATE INDEX MyTable_Composite_IX
ON MyTable (
    1_code
   ,2_code
   ,3_code
   ,4_code
   ,5_code
);
 
Share this answer
 
Comments
s#@!k 16-Dec-13 2:39am    
Thank you so much

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900