?
Solved

How to Get Table type Index in SQL?

Posted on 2014-01-02
2
Medium Priority
?
657 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 14

Accepted Solution

by:
Alexander Eßer [Alex140181] earned 1500 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

850 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