Solved

How to Get Table type Index in SQL?

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

Title # Comments Views Activity
oracle query help 36 84
Oracle - How to analyze data using DATE COLUMN? 7 74
Oracle and DateTime math 6 26
Wrong number of values in the INTO list of a FETCH statement 16 47
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
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 information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

863 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

28 Experts available now in Live!

Get 1:1 Help Now