Solved

How to Get Table type Index in SQL?

Posted on 2014-01-02
2
536 Views
Last Modified: 2014-02-25
Hi ,

I am using below logic to verify whether the given value is present or not in the array. In that I also wanted to fetch the index of the value. Is this possible with the below approach? Please let me know if any other approach to fetch.

set serveroutput on
declare
    tabtype_exist_del_grp_org   FND_TABLE_OF_NUMBER := FND_TABLE_OF_NUMBER ();
    v_row_num       number;
    v_del_grp_exist varchar2(30);
    v_del_exist varchar2(30);
begin
    tabtype_exist_del_grp_org.extend;
    tabtype_exist_del_grp_org (1) := 184;
    tabtype_exist_del_grp_org.extend;
    tabtype_exist_del_grp_org (2) := 185;
    tabtype_exist_del_grp_org.extend;
    tabtype_exist_del_grp_org (3) := 243;
    
    BEGIN
        SELECT  ROWNUM, COLUMN_VALUE, 'Y'
        INTO    v_row_num, v_del_grp_exist, v_del_exist
        FROM    TABLE(tabtype_exist_del_grp_org)
        WHERE   COLUMN_VALUE = 243;
                                
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
        v_del_exist := 'N'; 
                                                         
    WHEN OTHERS
    THEN
        v_del_exist := 'N';
    END;
    
    dbms_output.put_line ('v_del_grp_exist : '||v_del_grp_exist);
    dbms_output.put_line ('v_row_num : '||v_row_num);
    dbms_output.put_line ('v_del_exist : '||v_del_exist);

end;

Open in new window

0
Comment
2 Comments
 
LVL 13

Accepted Solution

by:
Alexander Eßer [Alex140181] earned 500 total points
ID: 39750994
You can & should do this without using SQL within your PL/SQL (faster, no context switches):

...
  v_del_grp_exist := 243;
  v_indx := tabtype_exist_del_grp_org.first;
  while v_indx is not null loop
    if tabtype_exist_del_grp_org(v_indx) = v_del_grp_exist then
      dbms_output.put_line('value found!');
      exit;
    end if;
    v_indx := tabtype_exist_del_grp_org.next(v_indx);
  end loop;
...

Open in new window

0
 

Author Closing Comment

by:Suriyaraj_Sudalaiappan
ID: 39885054
Good
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Via a live example, show how to take different types of Oracle backups using RMAN.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now