Getting first row in a group by order by sql

Hi all,
I'm having problems with the query below. What I want is to get a count of hotelid and group it then take the top result. My problem is that the version of oracle that I'm using is giving me errors because of the nested group by, order by. Is there any way around this?
SELECT *
FROM (SELECT agentid, hotelid, COUNT(hotelid) AS COUNT
FROM akorders a, akworklist_summary b
WHERE a.agentid = 1408946 AND
a.akorderid = b.akorderid
GROUP BY agentid, hotelid
ORDER BY COUNT DESC)
WHERE ROWNUM < 2
TIA!
Brian

SELECT agentid, hotelid, COUNT(hotelid) AS COUNT
FROM akorders a, akworklist_summary b
WHERE a.agentid = 1408946 AND
a.akorderid = b.akorderid
GROUP BY agentid, hotelid
HAVING COUNT(*) = (SELECT MAX(icount)
                   FROM (SELECT agentid, hotelid, COUNT(hotelid) AS icount
                         FROM akorders a, akworklist_summary b
                         WHERE a.agentid = 1408946 AND
                               a.akorderid = b.akorderid
                               GROUP BY agentid, hotelid ))

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 get first row from View Object cache.

    hi,
    I am using Jdeveloper 11.1.1.6
    can we get first row from View Object cache??
    Thanks in Advance.
    Best
    Shashidhar

    Hi Frank,
    Thanks for reply!!
    My case is:
    I have a Query based ViewObject.
    One of the field is LOV and remaining fields are in ADF table. the LOV field is out side ADF table when i insert first record in ADF table and i choose LOV  filed the value is selected.
    when i create second row LOV value got refreshed because both are in same VO.
    I need to get the LOV value of first row and set same value to second Row.
    Shashidhar

  • How can I get Numbers to return the first row in a group of VLOOKUP query results instead of last one?

    I'm trying to query from one table (call it Table1) a batch of rows in another table (Table2) using VLOOKUP on a date specified in the first table (Table1). My problem is it's returning the last incident in Table2 of the requested date instead of the first incident. This really breaks the OFFSET scheme I'd like to use to collect the rest of the items for that date. Is there some way to compel VLOOKUP to return the first row of query results, not the last?
    NOTE: I see I've asked this before, but forgot to go back and look at responses given. It's been a while and I've limped along until now with the way things were. I'm actually trying to delete this questions, so if you see it, ignore it. I suppose if someone can tell me real quick how to delete a stupid question, that might be helpful.

    you cannot delete a post yourself.  You can flag the post an request a moderator remove.

  • How to select first row of each group in a group by statement

    Table            
    ProdCode    PackType    BatchCode    ExpDate
    BURSLO               1             BS20GO-2001    01/12/2004
    BURSLO               1             BS20GO-2011    01/01/2007
    BURSLO               2             BS20GO-2027    01/02/2003
    BURSLO               3             BS20GO-2060    01/02/2004
    BURSOI               9             BU10F12    01/02/2006
    BURSOI               9             BU10GO-1301    01/05/2005
    BURSOI              11             BU10GO-131    01/06/2008
    BURSOI               2             BU10GO-1311    01/06/2007
    BURSOI              13             BU10GO-1328    01/07/2006
    Output            
    ProdCode    PackType    BatchCode    ExpDate
    BURSLO               1             BS20GO-2011    01/01/2007
    BURSLO               2             BS20GO-2027    01/02/2003
    BURSLO               3             BS20GO-2060    01/02/2004
    BURSOI               9             BU10F12    01/02/2006
    BURSOI              11             BU10GO-131    01/06/2008
    BURSOI               2             BU10GO-1311    01/06/2007
    BURSOI              13             BU10GO-1328    01/07/2006
    i need first row after group by ProdCode,    PackType and decreading order of ExpDate
    Please Help me.
    Thanks.
         

    Try the below:
    ;With cte
    as
    (Select *,Row_Number()Over(partition by Prodcode,Packtype Order by expdate desc) Rn From Tablename)
    Select * From cte where rn=1

  • How to get first row in query output

    HI,
    query:
    select a.LOGIN,s2diq(a.created_t)
    from service_t a,account_t b
    where a.ACCOUNT_OBJ_ID0=b.POID_ID0
    and b.ACCOUNT_NO='80161001'
    and b.status =10100
    output of query:
    80161001     6/25/2011 2:00:43 AM
    80161001_1     10/16/2011 9:10:44 PM
    80161001_2     10/16/2011 9:36:02 PM
    80161001_3     10/16/2011 10:23:07 PM
    80161001_4     10/17/2011 9:41:34 PM
    80161001_5     10/17/2011 9:45:59 PM
    80161001_6     10/17/2011 10:26:27 PM
    how to get only first row only in quaery:
    Thanks
    Prakash
    Edited by: prakashdba on Apr 7, 2009 3:09 AM

    Then how about this
    select * from
         (select a.LOGIN,s2diq(a.created_t) secondcolumn
         from service_t a,account_t b
         where a.ACCOUNT_OBJ_ID0=b.POID_ID0
         and b.ACCOUNT_NO='80161001'
         and b.status =10100
         order by COLUMN_NAME) A
    where rownum=1;

  • How to get first row from view iterator programatically?

    Hi All,
    I am using Jdeveloper 11g Release 2.
    I want to fetch the first row of a view iterator in a bean. Can any one guide me through this use case.
    Any help will be highly appreciated.
    Thanks ... Best Regards
    Bilal

    Use the code snippet as below:
    *// 1. Access the binding container*
    DCBindingContainer bc = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
    *// 2. Find a named iterator binding*
    DCIteratorBinding iter = (DCIteratorBinding)bc.findIteratorBinding("<ITERATOR_NAME>");
    *//3. Get the RowSetIterator Object*
    RowSetIterator rsi = iter.getRowSetIterator();
    *//4. Get the First Row*
    Row firstRow = rsi.first();
    Thanks,
    Navaneeth

  • Can't fetch XMLType after getting first row

    Hi - when I call OCIDefineObject in a sub function, after getting the first row of XMLType value, the program can't fetch subsequent rows and stops. If I call OCIDefineObject in the same memory space of where the fetch call locates, it works out fine. Somehow the persistency of xmldocnode can not last.
    Any clues? I can email out both working/non-working programs upon request.
    my environment is Oracle 11g on Solaris box.
    Sample Code: (fetch only the first row and stop)
    char orderNumData[4001];
    xmldocnode* xmlData = (xmldocnode *) 0;
    xmldocnode** xmlDatap = &xmlData;
    defineStr(define_orderNum, (char*)&orderNumData, 4001);
    defineXML(define_customerdata, xmlDatap );
    rc = OCIStmtExecute ( svc, stmt, err,
              1,
              0, NULL, NULL,
              OCI_DEFAULT);
    cout << "OrdNum: " << orderNumData << endl;
    displayXML (xmlData);
    while ((rc = OCIStmtFetch2 (stmt, err, 1,
    OCI_FETCH_NEXT,
    (ub4) 1,
    OCI_DEFAULT )) == OCI_SUCCESS)
    cout << "OrdNum: " << orderNumData << endl;
    displayXML (xmlData);
    void defineXML ( OCIDefine defineHdn, xmldocnode *xmlDatap )
    ociStatus = OCITypeByName( env,
    err,
    svc,
    (const text *) "SYS",
    (ub4) strlen((char *)"SYS"),
    (const text *) "XMLTYPE",
    (ub4) strlen((char *)"XMLTYPE"),
    (CONST text *) 0,
    (ub4) 0,
    OCI_DURATION_SESSION,
    OCI_TYPEGET_HEADER,
    (OCIType **) &xmltdo);
    ociStatus = OCIDefineByPos ( stmt,
    &defineHdn,
    err,
    pos,
    (dvoid *) 0,
    (sb4) 0,
    SQLT_NTY,
    (dvoid *) 0,
    (ub2 *)0,
    (ub2 *)0,
    (ub4) OCI_DEFAULT );
    ociStatus = OCIDefineObject( defineHdn,
    err,
    (OCIType *) xmltdo,
    (dvoid **) xmlDatap,
    &xmlSize,
    (dvoid **) &indp,
    (ub4 *) 0);
    Working one:
    Instead if I call OCITypeByName, OCIDefineByPos,
    and OCIDefineByPos right before the OCIStmtExecute() in the main,
    then all results can be returned.
    OCITypeByName(...)
    OCIDefineByPos(...)
    OCIDefineObject(...)
    rc = OCIStmtExecute ( svc, stmt, err,
    1,
    0, NULL, NULL,
    OCI_DEFAULT);
    cout << "OrdNum: " << orderNumData << endl;
    displayXML (xmlData);
    while ((rc = OCIStmtFetch2 (stmt, err, 1,
    OCI_FETCH_NEXT,
    (ub4) 1,
    OCI_DEFAULT )) == OCI_SUCCESS)
    cout << "OrdNum: " << orderNumData << endl;
    displayXML (xmlData);
    Thanks,
    Terrence

    void defineXML ( OCIDefine defineHdn, xmldocnode *xmlDatap ) { ...
    ociStatus = OCIDefineObject(
    defineHdn, err, (OCIType *) xmltdo, (dvoid **) xmlDatap,
    &xmlSize, (dvoid **) &indp, (ub4 *) 0);
    Instead if I call OCITypeByName, OCIDefineByPos,
    and OCIDefineByPos right before the OCIStmtExecute()
    in the main, then all results can be returned.I ran into this issue myself (was going nuts until a smarter colleague open my eyes on the issue). The problem is that you passing addresses of local variables in defineXML for xmlSize and indp, when the addresses you pass must remain valid for the whole fetch. (xmlSize is not written to apparently, by indp is for sure, so you are writing/corrupting your program stack...)
    To resolve this, I use a stack allocated helper struct whose lifetime extends the fetch, and which is referenced in the bind_object method. --DD
    struct ObjectBindInfo {
        void* p_value;
        void* p_indicator;
        ub4 value_size;
        ub4 indicator_size;
    static void insert_one_object(ub4 id) { ...
        sql_point pt(id);
        ObjectBindInfo pt_info(pt, &pt.indicator_);
        stmt.bind_object(conn, 2, pt, pt_info);
    ... void Statement::bind_object(
        Connection& conn, ub4 position, ..., ObjectBindInfo& obj_info
        // WARNING: Addresses passed to OCIBindObject MUST still be
        // valid after OCIStmtExecute, so cannot be addresses to local
        // (stack) vars. Thus the use of ObjectBindInfo...
        checkerr(
            OCIBindObject(
                bind_hndl, errhp(), tdo,
                (void**)&obj_info.p_value,     &obj_info.value_size,
                (void**)&obj_info.p_indicator, &obj_info.indicator_size
            errhp()
    }Of course, you've noticed that I talk about binds above, but the fact that you need to provide non-local var addresses to OCI applies to defines as well. --DD
    Message was edited by: ddevienne

  • Cant able to get first row

    Hi!!
    I am using jdeveloper 11.1.1.5
    I had developed this code in my AMImpl
            fpdvo.reset();
            for (int i=1;i<=12;i++) {
                System.out.println (i);
                Row fpdvor = fpdvo.next();
                System.out.println(fpdvor.getAttribute("FpdShortDesc"));  
    //It must print the values from April to March  But it Starts from May leaving April So i am getting null Pointer  Exception when it reaches i=12
                Row fpvorn = fpvo.createRow();
                cl.add(Calendar.DATE, 1);
                cl.set(Calendar.DAY_OF_MONTH,
                       cl.getActualMinimum(Calendar.DAY_OF_MONTH));
                java.util.Date Startdate = cl.getTime();
                System.out.println(Startdate);
                fpvorn.setAttribute("FpFromDate", cl.getTime());
                System.out.println("StartDate" +
                                   fpvorn.getAttribute("FpFromDate"));
                fpvorn.setAttribute("FpYear", currentRow.getAttribute("NextYear"));
                cl.set(Calendar.DAY_OF_MONTH,
                       cl.getActualMaximum(Calendar.DAY_OF_MONTH));
                java.util.Date enddate = cl.getTime();
                System.out.println(enddate);
                fpvorn.setAttribute("FpBu", "MEL");
                fpvorn.setAttribute("FpEndDate", cl.getTime());
                fpvorn.setAttribute("FpPeriod", i);
                fpvorn.setAttribute("FpShortDesc",
                                    fpdvor.getAttribute("FpdShortDesc"));
                fpvorn.setAttribute("FpLongDesc",
                                    fpdvor.getAttribute("FpdLongDesc"));
                fpvorn.setAttribute("FpQtr", fpdvor.getAttribute("FpdQtr"));
                fpvorn.setAttribute("FpQtrStDesc",
                                    fpdvor.getAttribute("FpdQtrStDesc"));
                fpvorn.setAttribute("FpQtrLgDesc",
                                    fpdvor.getAttribute("FpdQtrLgDesc"));
                this.getDBTransaction().commit();
                for (Row gllvlr = gllvlrs.first(); gllvlr != null;
                     gllvlr = gllvlrs.next()) {
                    Row gapbr = gapbvo.createRow();
                    gapbr.setAttribute("GapbAcct",
                                       gllvlr.getAttribute("GlalAcct"));
                    gapbr.setAttribute("GapbBu", "MEL");
                    gapbr.setAttribute("GapbCreditAmt", "0");
                    gapbr.setAttribute("GapbDebitAmt", "0");
                    gapbr.setAttribute("GapbLvl1",
                                       gllvlr.getAttribute("GlalLvl1"));
                    gapbr.setAttribute("GapbLvl2",
                                       gllvlr.getAttribute("GlalLvl2"));
                    gapbr.setAttribute("GapbLvl3",
                                       gllvlr.getAttribute("GlalLvl3"));
                    gapbr.setAttribute("GapbLvl4",
                                       gllvlr.getAttribute("GlalLvl4"));
                    gapbr.setAttribute("GapbPlant",gllvlr.getAttribute("GlalPlant"));
                    gapbr.setAttribute("GapbPeriod", i);
                    gapbr.setAttribute("GapbYear",
                                       currentRow.getAttribute("NextYear"));
                    this.getDBTransaction().commit();
            }could anyone pls help me to solve this issue

    are you trying to iterate over fpdvo?
    if yes check http://download.oracle.com/otn_hosted_doc/jdeveloper/11gdemos/ADF_Insider_Essentials/IterateRows/IterateRows.html

  • 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 get first row of a dataobject

    I have a ListDataObjectList that I’m setting in the request object. In the UIX page there is one field that is the same in all rows and hence I want to display only once. I have the following code in my UIX page, but it displays duplicate values (one from each row). How can I suppress repeating values?
    <rowLayout hAlign="center">
    <contents childData="${sessionScope.accounts}">
    <html:b>
    <formattedText text="${uix.current.customerSSN}" styleClass="OraDataText"/>
    </html:b>
    </contents>
    </rowLayout>
    Any help would be very much appreciated.

    You can use array notation in EL to access the first item (since it is duplicated).
    <rowLayout hAlign="center">
    <contents>
    <html:b>
    <formattedText text="${sessionScope.accounts[0].customerSSN}" styleClass="OraDataText"/>
    </html:b>
    </contents>
    </rowLayout>
    Kind Regards.

  • Export in Excel- always first row blank

    hi,
    if i export in excel file always i am getting first row as blank with line. how can i eliminate this row.

    Hi Kayadhu,
    Generally, if we design a report and the top of report body remain extra blank space, it will result in the extra blank row after export the report to Excel. Please see the screenshot below:
    In your case, please try to reduce the blank space in the report body. If the issue still persists, please post more information about your report design structure to us.
    Regards,
    Bin Long
    Bin Long
    TechNet Community Support

  • How to get value from First Row in an REF CURSOR

    I have a REF CURSOR defind like:
    open out_RESULT_SET for
    select
    EVENT_UID,
    EVENT_DATE,
    EVENT_ITEM
    from
    EVENT
    order by
    EVENT_DATE ASC;
    I want to also set the value of a variable v_FIRST_EVENT_DATE to the value in the EVENT_DATE column of the first row.
    I know I could do a:
    select
    min(EVENT_DATE)
    into
    v_FIRST_EVENT_DATE
    from
    EVENT;
    But I would rather just use the REF CURSOR (I think).
    Thanks for the help.

    How would I get v_FIRST_EVENT_DATE set to the date of the first event in the REF CURSOR out_RESULT_SET?Normal fetch into associated local variables should suffice.
    Something along those lines:
    declare
       v_first_event_date   event.event_date%type;
       v_event_uid          event.event_uid%type;
       v_event_date         event.event_date%type;
       v_event_item         event.event_item%type;
    begin
       open out_result_set for
          select   min (event_date) over () first_event_date, event_uid,
                   event_date, event_item
              from event
          order by event_date asc;
       loop
          fetch out_result_set
           into v_first_event_date, v_event_uid, v_event_date, v_event_item;
          exit when out_result_set%notfound;
          do_something;
       end loop;
      close out_result_set;
    end;
    /

  • Trying to get ending effective date for groups of rows

    Hi Everyone,
    I've searched the forums, but I can't find a post that presents a problem quite like this.
    I have some data that looks like this:
            ID_NUM     EFFECTIVE ALLOC_PERCENT   ACCT
           101 01-JUL-11            21   A1
           101 01-JUL-11            72   A2
           101 01-JUL-11             7   A3
           101 01-JUL-12            20   B1
           101 01-JUL-12            80   B2
           101 01-JAN-13            20   A1
           101 01-JAN-13            20   A2
           101 01-JAN-13            50   A3
           101 01-JAN-13            10   B1
           101 01-JUN-13            50   A1
           101 01-JUN-13            50   A2(note - I manually inserted blank lines for clarity)
    Here's the logic: The rows represent a percentage allocation to the account number for the specified id number, for that effective date. A newer effective date supercedes previous ones, and if any row in the conceptual group is superceded, then they all are.
    I'm trying to find out the date when each group's effective period ended, and include that in the result set so that I can subsequently calculate the number of days a given row was effective; something like this;
      ID_NUM     EFFECTIVE END_DATE   ALLOC_PERCENT ACCT
           101 01-JUL-11 01-JUL-12             21 A1
           101 01-JUL-11 01-JUL-12             72 A2
           101 01-JUL-11 01-JUL-12              7 A3
           101 01-JUL-12 01-JAN-13             20 B1
           101 01-JUL-12 01-JAN-13             80 B2
           101 01-JAN-13 01-JUN-13             20 A1
           101 01-JAN-13 01-JUN-13             20 A2
           101 01-JAN-13 01-JUN-13             50 A3
           101 01-JAN-13 01-JUN-13             10 B1
           101 01-JUN-13 <null>                50 A1
           101 01-JUN-13 <null>                50 A2The END_DATE of the group is the EFFECTIVE_DATE of the following group (ordered by ID_NUM, EFFECTIVE_DATE).
    The last two rows' END_DATE is null because there is no group of rows with a later effective date - in my process, I'll NVL that to sysdate so that my days calculations will be valid.
    I tried some analytic queries with LEAD, but I couldn't figure out how to make it get the next group's effective date. I could get the next row's effective date, but not the next group's. I couldn't specify how many lead rows to look ahead, because there is not a consistent number of rows in each group.
    How do I populate the END_Date column?
    Here's the code to create the above.
    create table t
    (id_num number,
    effective_date date,
    alloc_percent number,
    acct_code varchar2(4)
    insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jul-2011',21.0,'A1');
    insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jul-2011',72.0,'A2');
    insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jul-2011',7.0,'A3');
    insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jul-2012',20.0,'B1');
    insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jul-2012',80.0,'B2');
    insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jan-2013',20.0,'A1');
    insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jan-2013',20.0,'A2');
    insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jan-2013',50.0,'A3');
    insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jan-2013',10.0,'B1');
    insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jun-2013',50.0,'A1');
    insert into t (id_num,Effective_date,alloc_percent,acct_code) values(101,'01-jun-2013',50.0,'A2');
    commit;
    select * from t;Oracle version information:
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    "CORE     11.2.0.3.0     Production"
    TNS for Solaris: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    Thank you very much

    select  id_num,
            effective_date,
            first_value(effective_date)
              over(
                   partition by id_num
                   order by effective_date
                   range between 1 following and unbounded following
                  ) end_date,
            alloc_percent,
            acct_code
      from  t
      order by id_num,
               effective_date
        ID_NUM EFFECTIVE END_DATE  ALLOC_PERCENT ACCT
           101 01-JUL-11 01-JUL-12            21 A1
           101 01-JUL-11 01-JUL-12            72 A2
           101 01-JUL-11 01-JUL-12             7 A3
           101 01-JUL-12 01-JAN-13            20 B1
           101 01-JUL-12 01-JAN-13            80 B2
           101 01-JAN-13 01-JUN-13            20 A1
           101 01-JAN-13 01-JUN-13            10 B1
           101 01-JAN-13 01-JUN-13            20 A2
           101 01-JAN-13 01-JUN-13            50 A3
           101 01-JUN-13                      50 A1
           101 01-JUN-13                      50 A2
    11 rows selected.
    SQL> SY.

  • Lock the first row in an ordered table

    Hi,
    I have a table (TD_EVENTOS). I want to lock the row with te minimun value of a column (a timestamp called hora_evento) and some requirements of other columns. Then i build a cursor like this:
    CURSOR c is select * from td_eventos where (...) order by hora_evento for update skip locked;
    And then I make a fetch into this cursor and I get the row (locked) that I want. But i need the speedest way, and making that cursor it orders all rown in the table (when I only want the first row without lock) and when that table has 6000 or 7000 rows it wastes around 130 ms. My solution is to add to the WHERE a AND rownum < 50, and it only orders 50 rows (in 10 ms), but it orders 50 aleatory rows, and that`s not what I want.
    Any solution faster?
    Thanks!

    Sorry that wasn't clear of me and could be misleading. I didn't mean Oracle would have to do a full table scan, another access path such as an appropriate index scan would do. I was trying to get across that to do any kind of order or min or max, all records have to be investigated. Since the fact that you don't know a row is locked until you try to lock it, you clearly can't filter on it (it's not a data attribute).
    Apologies for any confusion my earlier post might have caused.
    The suggestion about using a sorted hash cluster still stands though, they are designed for FIFO queues.
    Which reminds me - SKIP LOCKED is in fact undocumented but everybody knows that Oracle use it internally for doing AQ. Since it's undocumented, you don't know how it works, when it will work, when it won't and of course Oracle can turn around and say "we don't support this".

Maybe you are looking for

  • How can I tell if my iPod touch 5 is jailbroken?

    I Don't know if I jailbroke my device or if this can cause a jailbrake but I downloaded a jailbroken app, it was meant to be downloaded by jailbroken devices not non-jailbroken devices so I downloaded it on my iPod and I haven't jailbroken my iPod an

  • ITunes wont start Error report.

    A while back, I had to do a system restore. I reinstalled both quicktime and iTunes, but whenever I open iTunes, one of those "iTunes has encountered an error," messages appears. I have tried everything, including reinstalling several times. I have a

  • How do I turn a FLA into a URL Button ?

    Hiya I have a FLA file with 4 layers 2 of the layers are Text Boxes 2 of them are masks to make the different words "Shine" Is there a way to make the whole file a button so when people click on it, it goes to a different page ? Thx Paul

  • I have a MACMINI and use Skype daily,

    I have a Mac Mini and I use Skype daily, but after a few minutes it starts to echo badly and make noises, How do I control this? what do I have to buy to stop the noise?

  • Does the SGE2010 support 10gb Mini GBIC?

    Hello, I have one 48 port SGE2010 and one 24 port SGE2000P at separate sites that are connected with single-mode fiber. I was wondering if the SGE's will support 10gb Mini GBIC transceivers or only 1gb Mini GBIC transceivers? I would like to connect