Solved

How to Get Table type Index in SQL?

Posted on 2014-01-02
2
553 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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows how to recover a database from a user managed backup
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

770 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