How to select the first row for each pair of values ?

Hi guys, am hoping someone can help me here.
If I have 4 tables - Building, Dept, Emp, Text
B D E T
A 1 Z blah1
A 1 X blah2
A 1 W blah3
A 2 V blah4
A 2 G blah5
A 2 H blah6
B 1 K blah7
B 1 L blah8
B 2 E blah9
B 2 F blah0
I need a query that will bring back the first bit of text for each pair of building and dept records.
So the results I would get would be
A 1 blah1
A 2 blah4
B 1 blah7
B 2 blah9
blah2 wouldnt be returned, because we have already had a record from the Building A, dept 1 pairing.
Likewise we wouldnt get blah5 because we have already had a record from the Building A, dept 2 pairing.
Can this be done in 1 query??
Thanks all.
Message was edited by:
Scott Hillier

here you go
SQL> drop table t;
Table dropped.
SQL> create table t(B char(1), D integer, E char(1), T varchar2(5));
Table created.
SQL> insert into t values('A', 1, 'Z', 'blah1');
1 row created.
SQL> insert into t values('A', 1, 'X', 'blah2');
1 row created.
SQL> insert into t values('A', 1, 'W', 'blah3');
1 row created.
SQL> insert into t values('A', 2, 'V', 'blah4');
1 row created.
SQL> insert into t values('A', 2, 'G', 'blah5');
1 row created.
SQL> insert into t values('A', 2, 'H', 'blah6');
1 row created.
SQL> insert into t values('B', 1, 'K', 'blah7');
1 row created.
SQL> insert into t values('B', 1, 'L', 'blah8');
1 row created.
SQL> insert into t values('B', 2, 'E', 'blah9');
1 row created.
SQL> insert into t values('B', 2, 'F', 'blah0');
1 row created.
SQL> select b,d,t
  2    from (
  3  select row_number() over(partition by b, d order by b,d) rno,b,d,t
  4    from t)
  5   where rno = 1;
B          D T
A          1 blah1
A          2 blah4
B          1 blah7
B          2 blah9karthick
http://karthickarp.blogspot.com/

Similar Messages

  • Getting the first row for each group

    Hi Everyone,
    I have a query which returns a number of rows, all of which are valid. What I need to do is to get the first row for each group and work with those records.
    For example ...
    client flight startairport destairport stops
    A fl123 LGW BKK 2
    A fl124 LHR BKK 5
    B fl432 LGW XYZ 7
    B fl432 MAN ABC 8
    .... etc.
    I would need to return one row for Client A and one row for Client B (etc.) but find that I can't use the MIN function because it would return the MIN value for each column (i.e. mix up the rows). I also can use the rownum=1 because this would only return one row rather than one row per group (i.e. per client).
    I have been investigating and most postings seem to say that it needs a second query to look up the first row for each grouping. This is a solution which would not really be practical because my query is already quite complex and incorporating duplicate subqueries would just make the whole thing much to cumbersome.
    So what I really new is a "MIN by group" or a "TOP by group" or a "ROWNUM=1 by group" function.
    Can anyone help me with this? I'm sure that there must be a command to handle this.
    Regards and any thanks,
    Alan Searle
    Cologne, Germany

    Something like this:
    select *
    from (
       select table1.*
       row_number() over (partition by col1, col2 order by col3, col4) rn
       from table1
    where rn = 1In the "partition by" clause you place what you normally would "group by".
    In the "order by" clause you define which will have row_number = 1.
    Edit:
    PS. The [url http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/functions004.htm#i81407]docs have more examples on using analytical functions ;-)
    Edited by: Kim Berg Hansen on Sep 16, 2011 10:46 AM

  • How to select a max row for each group in SQL ( with distinct code )

    Dear friends, 
    My table is as show in below…  for each ‘grpid’ I want get row with Max tiv value and code should be distinct. Ie in result, code & grpid will come only once.
    grpid
    code
    Tiv
    2
    GB
    9
    2
    IN
    7
    1
    GB
    11
    1
    US
    10
    Result:    ( we are selecting   IN even though for grpid 2
     ‘GB’ has max value )
    grpid
    code
    Tiv
    2
    IN
    7
    1
    GB
    11
    -Sajid

    Thanks for reply..
    please see my  DML+  DL
    CREATE TABLE [dbo].[tab](
    [grpid] [int] NOT NULL,
    [code] [varchar](2) NOT NULL,
    [Tiv] [int] NOT NULL
    ) ON [PRIMARY]
    delete from tab
    insert into tab values (2 , 'GB' ,12)
    insert into tab values (2 , 'IN' ,10)
    insert into tab values (1 , 'GB' ,11)
    insert into tab values (1 , 'US' ,10)
    insert into tab values (3 , 'GB' ,10)
    insert into tab values (3 , 'US' ,9)
    insert into tab values (3 , 'UA' ,10)
    insert into tab values (3 , 'IN' ,8)
    Result:
    grpid      code     
    tiv
    1             
    US          10
    2             
    GB          12
    3             
    UA          10
    Thanks in Advance..
    -Sajid
    CREATE TABLE [dbo].[tab](
    [grpid] [int] NOT NULL,
    [code] [varchar](2) NOT NULL,
    [Tiv] [int] NOT NULL
    ) ON [PRIMARY]
    delete from tab
    insert into tab values (2 , 'GB' ,12)
    insert into tab values (2 , 'IN' ,10)
    insert into tab values (1 , 'GB' ,11)
    insert into tab values (1 , 'US' ,10)
    insert into tab values (3 , 'GB' ,10)
    insert into tab values (3 , 'US' ,9)
    insert into tab values (3 , 'UA' ,10)
    insert into tab values (3 , 'IN' ,8)
    ;with mycte as
    (select grpid,code,tiv , row_number() over(Partition by code Order by Tiv DESC) rn1, row_number() over(Partition by grpid Order by Tiv DESC) rn2
    from tab)
    ,mycte1 as (Select *
    , row_number() over(Partition by grpid, rn1 Order by rn2 ASC) rn3
    from mycte
    WHERE rn1=1
    Select grpid,code,tiv from mycte1
    Where rn3=1
    drop table tab

  • How to select a max row for each group in SQL

    Dear Frindz,
    I want select countries with maximum value of 'Value' for a 'grpid'.  Also already selected 'Country' should not be considered for other 'grpid' while checking the maximum. ( ie Country or grpid should not be repeated in the result )
    CREATE TABLE [dbo].[test1](
    [Country] [varchar](4) NULL,
    [grpid] [int] NOT NULL,
    [Value] [float] NULL,
    [Row_number] [bigint] NULL
    ) ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'US', 49707, 604456458, 1)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'US', 909, 604456458, 2)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'US', 231, 604456457, 3)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'GB', 5086, 497654945, 4)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'GB', 50147, 405759433, 5)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'GB', 909, 405759433, 6)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'GB', 231, 405759433, 7)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'CA', 49707, 353500201, 8)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'CA', 5086, 353500201, 9)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'CA', 909, 353500201, 10)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'CA', 231, 353500201, 11)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'JP', 49707, 198291290, 12)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'JP', 5086, 198291290, 13)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'JP', 909, 198291290, 14)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'JP', 231, 198291290, 15)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'MX', 49707, 181884714, 16)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'MX', 909, 181884714, 17)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'MX', 231, 181884714, 18)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'BR', 49707, 105147054, 19)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'BR', 5086, 105147054, 20)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'BR', 909, 105147054, 21)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'AR', 49707, 94774929, 22)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'AR', 5086, 94774929, 23)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'AR', 909, 94774929, 24)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'AR', 231, 94774929, 25)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'ZA', 49707, 84560514, 26)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'ZA', 909, 84560514, 27)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'ZA', 231, 84560514, 28)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'CN', 49707, 68966682, 29)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'CN', 909, 68966682, 30)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'CN', 231, 68966682, 31)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'CB', 49707, 65020665, 32)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'CB', 5086, 65020665, 33)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'CB', 909, 65020665, 34)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'CB', 231, 65020665, 35)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'GT', 49707, 42016510, 36)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'GT', 5086, 42016510, 37)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'GT', 909, 42016510, 38)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'CR', 49707, 37116544, 39)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'CR', 5086, 37116544, 40)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'CR', 909, 37116544, 41)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'CR', 231, 37116544, 42)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'SV', 49707, 31103322, 43)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'SV', 5086, 31103322, 44)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'SV', 909, 31103322, 45)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'NI', 49707, 17415843, 46)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'NI', 5086, 17415843, 47)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'NI', 909, 17415843, 48)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'HN', 49707, 12516273, 49)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'HN', 5086, 12516273, 50)
    GO
    INSERT [dbo].[test1] ([Country], [grpid], [Value], [Row_number]) VALUES (N'HN', 909, 12516273, 51)
    GO
    Result:
    Country
    grpid
    Value
    Row_number
    US
    49707
    604456458
    1
    GB
    5086
    497654945
    4
    CA
    909
    353500201
    10
    JP
    231
    198291290
    15
    -Sajid

    Hi Pituach, thanks for your reply.
    in result  Country or grpid should not be repeated... in your result 'GB' and 'US' is  repeating.
      1) select countries with maximum value of 'Value' for a 'grpid'
      2) 'grpid' & country should not be repeated.
      3)  we need to take next maximum 
    value if 'grpid'  not  there a for 
    highest value.
    Result:
    Country
    grpid
    Value
    Row_number
    US
    49707
    604456458
    1
    GB
    5086
    497654945
    4
    CA
    909
    353500201
    10
    JP
    231
    198291290
    15
    -Sajid
    -Sajid

  • First row for each entry

    hi
    i have sorted the internal table by field f1 and i need to insert the first row for each f1 entry.
    I tried AT NEW f1. But that doesnt seem to work.
    Kindlly help.
    Thanks.

    *--ENSURE THAT age IS FIRST FIELD IN INTERNAL TABLE it_gir while declaring it.....
    SORT it_gir BY age ASCENDING.
    LOOP AT it_gir INTO wa_gir.
    AT NEW age.
    <b>*--if there are fields which are getting populated with **** instead of original values....then use below statement...</b>
    read table it_gir index sy-tabix.
    MOVE-CORRESPONDING wa_gir TO wa_final1.
    APPEND wa_final1 TO it_final1.
    clear wa_final1.
    ENDAT.
    ENDLOOP.
    now it should definitely work.....
    if not check in debugging mode if data exists or not....!!!
    Regards
    Vasu

  • Change field value in a table, based on another field value in the same row (for each added row)

    Please Help, I want to change field value in a table, based on another field value in the same row (for each added row)
    I am using this code :
    <HTML>
    <HEAD>
    <SCRIPT>
    function addRow(tableID) {
    var table = document.getElementById(tableID);
    var rowCount = table.rows.length;
    var row = table.insertRow(rowCount);
    var colCount = table.rows[0].cells.length;
    for(var i=0; i<colCount; i++ ) {
    var newcell = row.insertCell(i);
    newcell.innerHTML = table.rows[1].cells[i].innerHTML;
    switch(newcell.childNodes[0].type) {
    case "text":
    newcell.childNodes[0].value = "";
    break;
    case "checkbox":
    newcell.childNodes[0].checked = false;
    break;
    case "select-one":
    newcell.childNodes[0].selectedIndex = 0;
    break;}}}
    function deleteRow(tableID) {
    try {var table = document.getElementById(tableID);
    var rowCount = table.rows.length;
    for(var i=0; i<rowCount; i++) {
    var row = table.rows[i];
    var chkbox = row.cells[0].childNodes[0];
    if(null != chkbox && true == chkbox.checked) {
    if(rowCount <= 2) {
    alert("Cannot delete all the rows.");
    break;}
    table.deleteRow(i);
    rowCount--;
    i--;}}}catch(e) {alert(e);}}
    </SCRIPT>
    </HEAD>
    <BODY>
    <INPUT type="button" value="Add Row" onClick="addRow('dataTable')" />
    <INPUT type="button" value="Delete Row" onClick="deleteRow('dataTable')" />
    <TABLE id="dataTable" width="350px" border="1">
    <TR>
    <TD width="32"></TD>
    <TD width="119" align="center"><strong>Activity</strong></TD>
    <TD width="177" align="center"><strong>Cost</strong></TD>
    </TR>
    <TR>
    <TD><INPUT type="checkbox" name="chk"/></TD>
    <TD>
    <select name="s1" id="s1">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    </select>
    </TD>
    <TD><input type="text" name="txt1" id="txt1"></TD>
    </TR>
    </TABLE>
    </BODY>
    </HTML>

    Hi,
    Let me make sure u r working with table control.
    First u have to create a event(VALIDATE) to do the validation.
    Inside the event,
    1. First get the current index where user has pointed the curson
    2. Once u get the index read the internal table with index value.
    3. Now u can compare the col1 and col2 values and populate the error message.
    1. DATA : lo_elt TYPE REF TO if_wd_context_element,
                   l_index type i.
    lo_elt = wdevent->get_context_element( name = 'CONTEXT_ELEMENT' ).
         CALL METHOD LO_ELT->GET_INDEX( RECEIVING  MY_INDEX = l_index.
    above code should be written inside the event.
    Thanks,

  • How to include the first row of detail in every xquery transformed xml?

    I am dealing with a XML file,where i need to publish to different BS.
    First node will be a common node node which contains vital info,second node goes to one BS and third goes to another BS.
    *<header></header>*
    *<details></details> (they are unbounded, but the first detail tag which comes in the input file is a mandatory tag in such a way that it needs to be included in every transformed message)*
    *<trailer></trailer>*
    We need to apply x query transformation on it in such a way:
    *</header></header>*
    *<1st detail></1st detail>*
    *<detail></detail> (2nd row of detail in input file)* -------------------------> Goes to BS1
    *<trailer></trailer>..*
    *<header></header>*
    *<1st detail></1st detail>*
    *<detail></detail> (3rd row of detail in input file)* ----------------------------->Goes to BS2
    *<trailer></trailer>*..
    And so on.
    Now, the problem is how to include the first row( *1st detail* ) of detail in every xquery transformed xml?

    are you looping of this input with a for each?
    /yourdata/details[1] should return always the first detail element.
    or before the for each do an assing of this first detail element to "generic_details_var"
    and use this var in every looping iteration (in an assign or as input for xquery)

  • Selecting The First Row Of h:dataTable after getting new DataModel f

    Hi Friends
    If any one knows how to select first row of a dataTable on change of a DataModel it is representing please give the reply

    I haven't understood the answer of UlrichCech
    I am not using IRDA for my development purpose.
    and abt your reply ..
    I have already tried tht way but the problem is that
    whenever I selects different row page gets postback and selects
    the first row again and there is no way to trap posback event in JSF
    like ASP.NET
    I think my answer is some where related to DataModelListener..

  • Creating view to get first row for each table !!

    I am having tables(more than 10) which are related using foreign key and primary key relationship.
    Example:
    Table1:
    T1Prim T1Col1 T1Col2
    Table2
    T2For T2Prim T2Col1 T2Col2 T2Col3
    (here T2For will have value same as T1Prim and in my design it has same column name i.e. T1Prim)
    Table3
    T3For T3Prim T3Col1 T3Col2 T3Col3
    (here T3For will have value same as T2Prim)
    and so on.
    The data in the tables is like For table1 there will be one record, for table2 there will be one record and for table 3 there are more than one records.
    Can i view either the first record for each of them or all records from each of them by writing the following view.
    I have written a view like this:
    Create or replace view test (T1Prim,T1Col1, T1Col2,T2Prim,T2Col1 T2Col2, T2Col3, T3Prim,T3Col1, T3Col2, T3Col3)
    As
    Select
    Table1.T1Prim,
    Table1.T1Col1,
    Table1.T1Col2,
    Table2.T2Prim,
    Table2.T2Col1,
    Table2.T2Col2,
    Table2.T2Col3,
    Table3.T3Prim,
    Table3.T3Col1,
    Table3.T3Col2,
    Table3.T3Col3
    From
    Table1,
    Table2,
    Table3
    where
    Table1.Prim = Table2.For
    and Table2.Prim = Table3.For
    When i ran the select statement on the view I am not getting any data. Whereas there is data when select is ran on individual table.
    Can someone please tell me where i am goofing.
    Thanks in the anticipation that i will get some hint to solve this.
    Eagerly waiting for reply.
    Thanks !!

    I mean use a collection :
    Collection Methods
    A collection method is a built-in function or procedure that operates on collections and is called using dot notation. The methods EXISTS, COUNT, LIMIT, FIRST, LAST, PRIOR, NEXT, EXTEND, TRIM, and DELETE help generalize code, make collections easier to use, and make your applications easier to maintain.
    EXISTS, COUNT, LIMIT, FIRST, LAST, PRIOR, and NEXT are functions, which appear as part of an expression. EXTEND, TRIM, and DELETE are procedures, which appear as a statement. EXISTS, PRIOR, NEXT, TRIM, EXTEND, and DELETE take integer parameters. EXISTS, PRIOR, NEXT, and DELETE can also take VARCHAR2 parameters for associative arrays with string keys. EXTEND and TRIM cannot be used with index-by tables.
    For more information, see "Using Collection Methods".
    Syntax
    Text description of the illustration collection_method_call.gif
    Keyword and Parameter Description
    collection_name
    This identifies an index-by table, nested table, or varray previously declared within the current scope.
    COUNT
    COUNT returns the number of elements that a collection currently contains, which is useful because the current size of a collection is not always known. You can use COUNT wherever an integer expression is allowed.
    For varrays, COUNT always equals LAST. For nested tables, normally, COUNT equals LAST. But, if you delete elements from the middle of a nested table, COUNT is smaller than LAST.
    DELETE
    This procedure has three forms. DELETE removes all elements from a collection. DELETE(n) removes the nth element from an index-by table or nested table. If n is null, DELETE(n) does nothing. DELETE(m,n) removes all elements in the range m..n from an index-by table or nested table. If m is larger than n or if m or n is null, DELETE(m,n) does nothing.
    EXISTS
    EXISTS(n) returns TRUE if the nth element in a collection exists. Otherwise, EXISTS(n) returns FALSE. Mainly, you use EXISTS with DELETE to maintain sparse nested tables. You can also use EXISTS to avoid raising an exception when you reference a nonexistent element. When passed an out-of-range subscript, EXISTS returns FALSE instead of raising SUBSCRIPT_OUTSIDE_LIMIT.
    EXTEND
    This procedure has three forms. EXTEND appends one null element to a collection. EXTEND(n) appends n null elements to a collection. EXTEND(n,i) appends n copies of the ith element to a collection. EXTEND operates on the internal size of a collection. So, if EXTEND encounters deleted elements, it includes them in its tally. You cannot use EXTEND with index-by tables.
    FIRST, LAST
    FIRST and LAST return the first and last (smallest and largest) subscript values in a collection. The subscript values are usually integers, but can also be strings for associative arrays. If the collection is empty, FIRST and LAST return NULL. If the collection contains only one element, FIRST and LAST return the same subscript value.
    For varrays, FIRST always returns 1 and LAST always equals COUNT. For nested tables, normally, LAST equals COUNT. But, if you delete elements from the middle of a nested table, LAST is larger than COUNT.
    index
    This is an expression that must yield (or convert implicitly to) an integer in most cases, or a string for an associative array declared with string keys.
    LIMIT
    For nested tables, which have no maximum size, LIMIT returns NULL. For varrays, LIMIT returns the maximum number of elements that a varray can contain (which you must specify in its type definition).
    NEXT, PRIOR
    PRIOR(n) returns the subscript that precedes index n in a collection. NEXT(n) returns the subscript that succeeds index n. If n has no predecessor, PRIOR(n) returns NULL. Likewise, if n has no successor, NEXT(n) returns NULL.
    TRIM
    This procedure has two forms. TRIM removes one element from the end of a collection. TRIM(n) removes n elements from the end of a collection. If n is greater than COUNT, TRIM(n) raises SUBSCRIPT_BEYOND_COUNT. You cannot use TRIM with index-by tables.
    TRIM operates on the internal size of a collection. So, if TRIM encounters deleted elements, it includes them in its tally.
    Usage Notes
    You cannot use collection methods in a SQL statement. If you try, you get a compilation error.
    Only EXISTS can be applied to atomically null collections. If you apply another method to such collections, PL/SQL raises COLLECTION_IS_NULL.
    You can use PRIOR or NEXT to traverse collections indexed by any series of subscripts. For example, you can use PRIOR or NEXT to traverse a nested table from which some elements have been deleted.
    EXTEND operates on the internal size of a collection, which includes deleted elements. You cannot use EXTEND to initialize an atomically null collection. Also, if you impose the NOT NULL constraint on a TABLE or VARRAY type, you cannot apply the first two forms of EXTEND to collections of that type.
    If an element to be deleted does not exist, DELETE simply skips it; no exception is raised. Varrays are dense, so you cannot delete their individual elements.
    PL/SQL keeps placeholders for deleted elements. So, you can replace a deleted element simply by assigning it a new value. However, PL/SQL does not keep placeholders for trimmed elements.
    The amount of memory allocated to a nested table can increase or decrease dynamically. As you delete elements, memory is freed page by page. If you delete the entire table, all the memory is freed.
    In general, do not depend on the interaction between TRIM and DELETE. It is better to treat nested tables like fixed-size arrays and use only DELETE, or to treat them like stacks and use only TRIM and EXTEND.
    Within a subprogram, a collection parameter assumes the properties of the argument bound to it. So, you can apply methods FIRST, LAST, COUNT, and so on to such parameters. For varray parameters, the value of LIMIT is always derived from the parameter type definition, regardless of the parameter mode.
    Examples
    In the following example, you use NEXT to traverse a nested table from which some elements have been deleted:
    i := courses.FIRST; -- get subscript of first element
    WHILE i IS NOT NULL LOOP
    -- do something with courses(i)
    i := courses.NEXT(i); -- get subscript of next element
    END LOOP;
    In the following example, PL/SQL executes the assignment statement only if element i exists:
    IF courses.EXISTS(i) THEN
    courses(i) := new_course;
    END IF;
    The next example shows that you can use FIRST and LAST to specify the lower and upper bounds of a loop range provided each element in that range exists:
    FOR i IN courses.FIRST..courses.LAST LOOP ...
    In the following example, you delete elements 2 through 5 from a nested table:
    courses.DELETE(2, 5);
    In the final example, you use LIMIT to determine if you can add 20 more elements to varray projects:
    IF (projects.COUNT + 20) < projects.LIMIT THEN
    -- add 20 more elements
    Related Topics
    Collections, Functions, Procedures
    http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96624/13_elems7.htm#33054
    Joel P�rez

  • How to ignore the first row  in sender file

    I would like to ignore the first row in each file in the sender channel - how can i do it?

    Hi
    Check this,
    As he said give Document Offset = 1
    http://help.sap.com/saphelp_nw04/helpdata/en/2c/181077dd7d6b4ea6a8029b20bf7e55/content.htm
    Also check this forum
    Re: Supress Column Heading - File Content Conversion in Sender Adapter
    Thanks,
    Prakash

  • How to select the first record?

    Hi,
    Could anyone tell me how to select the first record of every
    group?
    ex, I want to find out every customer their first purcaseDate.
    CustomerID PurcaseDate Region
    A00000001 2001/01/01 AA
    A00000001 2001/02/02 AA
    A00000002 2001/03/01 AC
    A00000002 2001/05/07 AC
    A00000003 2001/03/05 DD
    result:
    A00000001 2001/01/01 AA
    A00000002 2001/03/01 AC
    A00000003 2001/03/05 DD
    Thanks

    Vincent,
    You could do it as Carl suggested, with a couple of
    corrections.  You would need to include the CustomNo column in
    the order by clause of your cursor.  You would also need to add
    a where clause to your update statement, otherwise everywhere
    Region in the table would be updated with the same value of the
    last CustomNo in the cursor, regardless of the CustomNo in the
    table.  See corrected code below:
    DECLARE
      CURSOR     cust
      IS
      SELECT     DISTINCT CustomNo, Region, Purchase_Date
      FROM       my_table
      ORDER BY   CustomNo, Purchase_Date, Region;
      c_customer VARCHAR2 (9) := '...';
      c_region   VARCHAR2 (2) := '..';
      cntr       NUMBER := 0;
    BEGIN
      FOR x IN cust
      LOOP
        IF x.CustomNo != c_customer
        THEN
          c_customer := x.CustomNo;
          c_region := x.Region;
        ELSE
          UPDATE my_table
          SET    Region = c_region
          WHERE  CustomNo = c_customer;
          cntr := cntr + 1;
          IF cntr = 25
          THEN
            COMMIT;
            cntr := 0;
          END IF;
        END IF;
      END LOOP;
      COMMIT;
    EXCEPTION
      WHEN OTHERS THEN 
        NULL;
    END;
    Another option is that you could just use one update statement,
    like this:
    UPDATE my_table a
    SET    Region =
           (SELECT DISTINCT Region
            FROM   my_table b
            WHERE  (CustomNo, Purchase_Date) IN
                   (SELECT   CustomNo, MIN (Purchase_Date)
                    FROM     my_table
                    GROUP BY CustomNo)
            AND    a.CustomNo = b.CustomNo)
    Barbara

  • How to use the different class for each screen as well as function.

    Hi Experts,
    How to use the different class for each screen as well as function.
    With BestRegards,
    M.Thippa Reddy.

    Hi ThippaReddy,
    see this sample code
    Public Class ClsMenInBlack
    #Region "Declarations"
        'Class objects
        'UI and Di objects
        Dim objForm As SAPbouiCOM.Form
        'Variables
        Dim strQuery As String
    #End Region
    #Region "Methods"
        Private Function GeRate() As Double
                Return Double
        End Function
    #End Region
    Public Sub SBO_Appln_MenuEvent(ByRef pVal As SAPbouiCOM.MenuEvent, ByRef BubbleEvent As Boolean)
            If pVal.BeforeAction = True Then
                If pVal.MenuUID = "ENV_Menu_MIB" Then
                End If
            Else ' Before Action False
                End If
        End Sub
    #End Region
    End Class
    End Class
    Rgds
    Micheal
    Vasu Anna Regional Feeling a???? Just Kidding
    Edited by: micheal willis on Jul 27, 2009 5:49 PM
    Edited by: micheal willis on Jul 27, 2009 5:50 PM

  • Windows Explorer - How to select the first item once we open the explorer?

    Hi,
    In Windows Explorer - How to select the first item once we open the explorer using keyboard shortcut. I typically use downward arrow, it goes to the 2nd item in the list, then I again have to use upward arrow to go up.
    Is there a shortcut to select the first item in the list using keyboard? This is not specific to Windows 7, it has been the behavior even in previous Windows OS versions.
    Thanks,
    Mallik

    Opening a Microsoft Ticket is probably your best option. Unfortunately the change will not happen immediately and it will require multiple users to send in a ticket. I hope this ends up being resolved though.
    Good luck Mallik
    Also, don't forget to mark the post as answered so that it does not show up as unanswered to help others who search the forums.
    Agreed, MS wont change it easily. :)
    Arnav Sharma | http://arnavsharma.net/ Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading
    the thread.

  • How to use the first row function value for the rest of records

    Hi all,
    I am having a select statement like this. We are calling function enabled for each row. So it is taking
    time. As per our bussiness logic, we can use what the function 'enabled' will give for the first row to
    other rows also. so that we can avoid calling the function 'enabled' next row onwars.
    Before
    SELECT
    decode(enabled(col1, col2, col3),'TRUE','xxx', col4),
    decode(enabled(col1, col2, col3),'TRUE','xxx', col5),
    decode(enabled(col1, col2, col3),'TRUE','xxx', col6),
    decode(enabled(col1, col2, col3),'TRUE','xxx', col7),
    decode(enabled(col1, col2, col3),'TRUE','xxx', col8),
    from
    table1 t1, table2 t2 where t1.col1 = t2.col1
    After
    SELECT
    decode(enabled(col1, col2, col3),'TRUE','xxx', col4),
    decode('true/false','TRUE','xxx', col5), --Here 'true/false' is the first row value after calling the function 'enabled'
    decode('true/false','TRUE','xxx', col6),
    decode('true/false','TRUE','xxx', col7),
    decode('true/false','TRUE','xxx', col8),
    from
    table1 t1, table2 t2 where t1.col1 = t2.col1
    Any thoughts on this, how to implement this logic
    Thanks,
    Pal

    It's not clear where col1, col2, col3... etc. come from, so I've assumed they're in table1.
    with table1_X as (select enabled(col1, col2, col3) as enbl
                            ,col1, col2, col3, col4, col5, col6, col7, col8
                      from   table1)
    SELECT decode(t1.enbl,'TRUE','xxx', col4)
          ,decode(t1.enbl,'TRUE','xxx', col5)
          ,decode(t1.enbl,'TRUE','xxx', col6),
          ,decode(t1.enbl,'TRUE','xxx', col7),
          ,decode(t1.enbl,'TRUE','xxx', col8),
    from   table1_x t1 join table2 t2 on (t1.col1 = t2.col1)p.s. you'd be better leaving out the enabled function altogether and incorporating the logic of the function directly in the SQL, and then you would be avoiding any context switching which will clearly impact performance on any large amount of data.
    Edited by: BluShadow on 14-May-2013 08:26

  • How to set the first row as selected in single selection of table

    when the page renders how do we make the first row as selected for single selection in a table.
    Thansk a lot for your help

    set the selection Attribute's value to 'Y' for the first row. Thats enough.
    eg;
    Row row=vo.first();
    row.setAttribute("SelectionAttribute", "Y");
    --Prasanna                                                                                                                                                                                                                                                                                                                                           

Maybe you are looking for

  • SQL server agent job running as Agent Service Account whose service account does not have r/w access but is still able to write?

    Hi. I am newer to SQL server security and am reviewing some of our SQL server's configuration to make sure the services are running under accounts with least privilege.  I have a SQL server 2012 instance whose Agent service is configured to run under

  • Microsoft Windows Network: The local device name is already in use.

    I posted in : http://answers.microsoft.com/en-us/windows/forum/windows_7-networking/disconnected-network-drive-error-as-follows-an/9a877c38-5e86-4c34-84c2-427a965577c6?page=2 Error: "An error occurred while reconnecting drive letter to \\network serv

  • My iTunes won't quit

    I opened my itunes to listen to one song after finishing the song to completion I went to the "Quit itunes" tab at the top and nothing happened. after waiting a few minutes tried again, still nothing happens so I went to the itunes icon in my dock ri

  • How to create a tcode for a program in FMEQ transaction

    Hi ABAP Experts, I need to assign a program from FMEQ transaction to a custom z-transaction code. Can anybody tell me how to do this. I already tried  go to system-status-> "copy program name from here and past it in SE93). This would not work becaus

  • Photoshop as a Paint app?

    I recently became aware that some (many?) use PS as their paint app..even ones who'd used Painter, ArtRage, etc. The paintings I've seen created in Photoshop are breathtaking, truly. My question: can anyone who's made this transition, or who always p