Format the first and the last record of query result

Hello
I have the following query

< tt > select 1 seq, "This is the first record" data from dual union of all the
Select 2, 'Data ' | tNom tab Union all
Select 3, "It was last last record" double
order by 1 < /tt >

When I have the coil this summary to a listfile with col seq noprint option I get:

This is the first record
Data MLA_ACCESS_LIST
Data MLA_APPLICATIONS
Data MLA_VPD_PCK
Data MLA_VPD_TABLES
It was the last last record

But I want to:

It's first record MLA_ACCESS_LIST
Data MLA_APPLICATIONS
Data MLA_VPD_PCK
MLA_VPD_TABLES it was save finally last record

I tried with 1 statement with the use of lead and lag, because first and last record stand the other result record. But I get ORA-30484: lack of specification of the window for this function

Is this possible with 1 statement or am I've sentenced to modify the results by myself?

Thank you Auke

Select row_number() case above (tNom control)
When 1 then 'it's the first record
end | tNom |
-case row_number() over (order by desc tNom)
When 1 then 'it was the last record. "
end
tab
order by tNom

HTH

Tags: Database

Similar Questions

  • Add a string to the last record

    Hello
    I was just trying to format an o/p to a table, and looking at the result, I thought it would be nice to add a piece of a chain to the last record. For example
    with dat as (
    select 'First Record' as COL from DUAL
    union all
    select 'Second Record'  from DUAL
    union all
    select 'Third Record'  from DUAL
    union all
    select 'Nth Record'  from DUAL )
    select * from dat
    
    o/p                                             Desired o/p
    COL                                            COL            
    -------------                                 -------------
    first RECORD                             first RECORD
    second RECORD                            second RECORD  
    THIRD RECORD                            THIRD RECORD 
    NTH RECORD                             This is the last record NTH RECORD   
    with dat as
    (
    select 'First Record' as COL from DUAL
    union all
    select 'Second Record'  from DUAL
    union all
    select 'Third Record'  from DUAL
    union all
    select 'Nth Record'  from DUAL
    ),
    ord as
    (
      select count(*) rn
        from dat
    )
    select decode(rownum, rn, 'This is Last Record ' || col, col)
      from ord, dat;
    
  • Select the last record of each month

    Hello

    to select the last docnumber and qty of every month

    Structure

    Name Null?    Type

    ------------------------------- -------- ----

    PRODUCTCODE NUMBER

    NUMBER NUMBER

    DATE OF PLANFORMONTH

    NUMBER OF CLEXPECTEDQTY

    NUMBER OF CLCONFIRMQTY

    NUMBER OF CLFGBUFFERQTY

    NUMBER OF CLTOTPRINTBUFFER

    in this select query if I take the sum he required all records where, as I want the last record of each month

    SELECT productcode docnumber MAX (Number), planformonth, SUM (clexpectedqty) clexpectedqty (planformonth) MAX.

    SUM (clconfirmqty) clconfirmqty, SUM (clfgbufferqty) clfgbufferqty, cltotprintbuffer OF FGSALESPLAN of the SUM (cltotprintbuffer)

    GROUP BY productcode, (planformonth)

    Sandy

    Hello

    Thanks its working now the code is written as below:

    SELECT * FROM

    (SELECT

    e.*,

    ROW_NUMBER() OVER (partition by PRODUCTCODE by DOCNUMBER DESC order) r

    Of

    E FGSALESPLAN)

    WHERE r = 1 AND

    entryvalid = 'Y '.

    order by Number

    Sandy

  • get the last record

    What is the best way to get the last record in a table?
    ... in addition to select * from tbl by id Desc... & then set = 1 maxrow in cfoutput.

    I want a quick way.
    I tried "Max (id), columns, but not worked.
    If I ' Max (id) as V ' & then turn around and make another request for ' where id = #V # "to get the rest of the record, there's more action.

    Quote:
    Posted by: paross1
    One way...

    SELECT all your columns
    From your_table
    WHERE your_engagement_appid = (SELECT MAX (your_id)
    From your_table)

    Phil

    Thank you guys. It worked great.
    I also tried the front joined query where the... I would have thought that.
    Thank you!

  • Cursor Oracle return only the last record

    I am a newbie in oracle stored proc. I tried to select data using the slider, but it only return last record. The recording must be greater than 1.

    CREATE or REPLACE procedure MySchema.Test (myrefcur on sys_refcursor)
    Is

    Begin
    declare

    Cursor C1 IS

    Select mySerialNum from TableA;
    MyRecord C1% rowtype;

    Begin
    Open C1;
    Loop
    Fetch C1 into myrecord;
    When the output C1% NotFound;

    Open for Myrefcur
    Select SerialNumB from TableB where SerialNumB = myrecord.mySerialNum;

    End loop;
    Close C1;
    End;
    end;

    However, it only returns the last record in the list.

    Original case *.
    The original code is as below:

    1st, I'll need to select a list of ImageSerialNum of ImageSerial

    * 1 query:
    Select A.ImageSerialNum from ImageSerial A, ProductionOrder B, Bom C
    Where A.ProductionOrderID = B.ProductionOrderID And B.Assembly_Num = C.Model_Num and
    B.Revision = C.Revision And B.EngRevision = C.EngRevision and
    C.Bom_ID = passInVariable* and C.FactoryID = "7"

    2nd, I'll need to check the process of EACH series with the code below:

    * Low code a return process for 1 series only.

    Select t.processid, t.processname, t.assembly_num, t.revision, t.engrevision of
    (Select p.ProcessID, p.ProcessName, in. Assembly_Num, in. review, in. EngRevision, im.imageserialnum
    Process p, Routesequence rs, Imageserial im, ProductionOrder in.
    Where im. ImageserialNum = SerialNum* and p.ProcessID = rs. ProcessID
    And rs. RouteID = in. RouteID and rs. SequenceID = im. NextRouteSequence
    And in. ProductionOrderID = im. ProductionOrderID AND IM. STATUS OF '0'
    UNION
    SELECT A.REWORKROUTEID AS PROCESSID PROCESSNAME AS B.ROUTENAME, C.ASSEMBLY_NUM, C.REVISION, C.ENGREVISION, a.imageserialnum
    OF IMAGESERIAL A, B OF ROAD, PRODUCTIONORDER C
    WHERE A.REWORKROUTEID = B.ROUTEID AND A.IMAGESERIALNUM = SerialNum*.
    AND A.PRODUCTIONORDERID = C.PRODUCTIONORDERID and a.status = '0') t

    After that, I would like to combine the two in 1 stored proc code.

    in this case, you just want to join the two applications to use in the FROM clause
    As I don't have your tables, I created two tables, each representing the results of your queries. Substitute the names of table with your queries

    SQL> drop table master
      2  /
    
    Table dropped.
    
    SQL> drop table details
      2  /
    
    Table dropped.
    
    SQL>
    SQL> create table master
      2  (ImageSerialNum varchar2(25));
    
    Table created.
    
    SQL>
    SQL>
    SQL> insert into master values ('Serial1');
    
    1 row created.
    
    SQL> insert into master values ('Serial2');
    
    1 row created.
    
    SQL> insert into master values ('Serial3');
    
    1 row created.
    
    SQL> insert into master values ('Serial4');
    
    1 row created.
    
    SQL> insert into master values ('Serial5');
    
    1 row created.
    
    SQL>
    SQL> create table details
      2  (ImageSerialNum  varchar2(25)
      3  ,ProcessID  number
      4  ,ProcessName varchar2(25)
      5  );
    
    Table created.
    
    SQL>
    SQL> insert into details values ('Serial1',  1, 'Process1');
    
    1 row created.
    
    SQL> insert into details values ('Serial3',  3, 'Process3');
    
    1 row created.
    
    SQL> insert into details values ('Serial5',  5, 'Process5');
    
    1 row created.
    
    SQL>
    SQL> select m.imageserialnum
      2       , d.processid
      3       , d.processname
      4    from master m
      5    left outer
      6    join details d
      7      on (m.imageSerialnum = d.imageserialnum)
      8   order by m.imageserialnum
      9  /
    
    IMAGESERIALNUM             PROCESSID PROCESSNAME
    ------------------------- ---------- -------------------------
    Serial1                            1 Process1
    Serial2
    Serial3                            3 Process3
    Serial4
    Serial5                            5 Process5
    

    your query will be something like

    select m.imageserialnum
         , d.processid
         , d.processname
      from () m
      left outer
      join (
    
  • remove the last record from the plsql table

    TYPE r_LOOPElement IS RECORD (TermID   NUMBER 
                                          );
    
    TYPE t_LOOPType IS TABLE OF r_LOOPElement INDEX BY BINARY_INTEGER;
    i_CustomerLoop      t_LOOPType ;
    
    i_CustomerLoop(1).TermID=1;
    i_CustomerLoop(2).TermID=2;
    i_CustomerLoop(3).TermID=3;
    Under certain conditions, I need to remove the last record from i_CustomerLoop

    whichi s the best way to do it. because I sometimes get duplicates for TermID in this plsql table.

    Hello

    See [removing items from Collection (DELETE method) | http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/collections.htm#CJAFGFIG]

    Kind regards

  • Identify the last record of node

    Hello everyone,

    another day, another problem.

    We want to display a list of commands not as multiple lines but as single line, each value divided by a comma:

    <? for-each: BM_AUFTRAEGE_ROW? > <? KRA_AUFTRAG_NUMMER? >, <? end foreach? >

    My concern is how to remove the last comma in this line? Can I calculate if it is the last recording of an if statement?

    Regrads,
    Stefan Dase

    To do this

    = ,

  • Limit the number of CMIS query results

    Hello
    Can we limit the number of CMIS query results
    my query is
    SELECT * from ora: t:IDC:GlobalProfile WHERE the ora: p:xRegionDefinition AS \'ALERTRD\'
    I want only newer 2 alerts to display.

    Thank you

    You use the CMIS query in a workflow of presenter content in WebCenter Portal? These documents provide a maxResults parameter to set.

  • Lack the last record in second and so forth

    When I record a stream to the FMS, press stop and then play my recorded stream, I seem to always miss the last second or two. What is a buffer problem? How can I solve this?

    Yes, that could be due to a problem of buffer. You want to ensure that the buffer is empty before you stop the publication. If you examine the code for the VideoRecord component, you will see an example of how to see the buffer. I find this also helps empty the stream (server side) before starting playback.

  • Properties of the file - Date of the last recorded

    Hello.

    I'm having trouble understanding the properties of the file, as "Last record Date" (DLS) and "Date modified" (MD).

    I asked that the last of them, MD, has been changed whenever the content has changed. But Distribution lists must be updated also.

    However, I have a file which has the DLS on 2007 and MD 2014 and the 'last impression"also is 2014.

    How is that possible?

    What has changed the date the content of the file was really the last?

    I would be grateful if someone could help me understand this.

    Thank you,

    Nuno Roque

    Modification date is when the file got changed on that hard drive.  Even if you have never opened the file, just drag-and - drop it to drive flash (for an example) would last updated date change, because the file on this disk changed really.

    Properties such as "Date of last recorded" and "date printed" are stored in the file itself, such as metadata and are updated no not by disk or operating system, but by the design (such as Word) program.

  • Dialog file save forgets the last record of consultation: (Windows XP)

    Whenever opens the dialog "Save" now always default to the my documents instead of the selected folder the last time that a dialog box "Save the file" or "File Open" has been used. This problem affects most Microsoft applications (Notepad, Paint, Word, Excel, etc.) on my Windows XP SP3 System.
    It is interesting its opposite, the 'Open' dialog box only no by default the My Documents folder, unless the "Save file" dialog box will open in front of her. So, it seems that the "Save File" dialog is changing the 'active' in My Documents folder whenever it opens. Someone at - he of the clues as to why this can happen and how to get back to a normal behavior?
    It's time to time very waste to modify records whenever I have save or open a file and caused inadvertently save me files in the My Documents folder when I forget.

    I discovered later that the problem was caused by the objective document Management System, and it is part of their intended design 'big brother' to allows you to use their document management system to save the files. I was very pleased with him removing my system, which restored a normal behavior of the Save dialog window.

  • How to find the last record of the extracted records

    Dear members,

    I have an OFA Page in which I view record master detail. For each master record can one or more detail records.

    In the page I got the button NEXT. If the user clicks the next button, I'm populating the next record of the master and its corresponding detail records.

    To achieve this, I wrote the code below in AM:_


    Public Sub findNextRec()
    *{*
    String headerID = null;
    Rank rank is getMaster_VO1 () .next ();.
    if(Row!=null)
    *{*

    headerID = row.getAttribute ("HeaderId") m:System.NET.SocketAddress.ToString ();
    getDetail_VO1 (.setMaxFetchSize(-1));
    getDetail_VO1 () .setWhereClause (null);
    getDetail_VO1 () .addWhereClause ("header_id in (: 1)" ");
    getDetail_VO1 () .setWhereClauseParams (null);
    getDetail_VO1 (.setWhereClauseParam(0,headerID));
    getDetail_VO1 () .executeQuery ();

    *}*
    *}*

    My CO code in processFormRequest method is as follows:_


    If (PageContext.GetParameter ("Next")! = null)
    *{*
    am.invokeMethod ("findNextRec");
    *}*

    Here my requirement is that if it's a last drive, I want to show the user a message saying it's last recording. To achieve this please let me know what the code should be written.

    Thanks in advance.

    Best regards
    Arun D. Reddy

    Arun,

    If my interpretation is correct, then you can achieve the same thing by making some minor changes to your existing code.

    public void findNextRec()
    {
    String headerID=null;
    Row row = getMaster_VO1().next();
    if(row!=null) //your code will return null when if there is no record
    {
    headerID=row.getAttribute("HeaderId").toString();
    getDetail_VO1().setMaxFetchSize(-1);
    getDetail_VO1().setWhereClause(null);
    getDetail_VO1().addWhereClause("header_id in (:1)");
    getDetail_VO1().setWhereClauseParams(null);
    getDetail_VO1().setWhereClauseParam(0,headerID);
    getDetail_VO1().executeQuery();
    }
    else{
    //write down the message that there exist no more rows (custom message)
    
         }
    }
    

    Kind regards
    GYAN

  • jump the last record loading using external table

    Hi gentlemen,

    I have a requirement to load data from text file of oracle database by using the external table. I need to remove the header records and complementary.

    I can use the skip option to remove the header, IE front-line.

    Is it possible to remove the additional record (IE last line) using the external table.


    Thanks in advance.

    Ferry

    Hello ferry.
    Do not hesitate on occasion as useful and Correct answers for those of us Newbie trying to get credibility :)

    Thank you
    Luke

  • To summarize the last record

    Hello... Experts

    My report gives 50records.
    In my report (10) Top N filter is used.

    ReQ: after 10th, line 11 (contains, the number of the other recording is = 40) must come

    Rather than recreating what has already been done, look at this link:

    http://obiee101.blogspot.com/2009/08/OBIEE-TopN-versus-rest.html

    I think that's what you're asking. If so, mark my 'correct' and narrow post on this thread.

  • Display total records with the last record

    Hi all

    I have the following tables:

    create the table TRY_date_detail

    (

    item_date date,

    number of item_order

    );

    create the table TRY_date_master

    (

    date of master_date,

    number of date_amount

    );

    Insert all

    IN TRY_date_detail values (to_date('01-01-2011','DD-MM-YYYY'), 1)

    IN TRY_date_detail values (to_date('01-01-2011','DD-MM-YYYY'), 2).

    IN TRY_date_detail values (to_date('01-01-2011','DD-MM-YYYY'), 3)

    IN TRY_date_detail values (to_date('01-01-2011','DD-MM-YYYY'), 4)

    IN TRY_date_detail values (to_date('01-01-2011','DD-MM-YYYY'), 5)

    IN TRY_date_master values (to_date('01-01-2011','DD-MM-YYYY'), 6432)

    IN TRY_date_master values (to_date('01-01-2011','DD-MM-YYYY'), 1111)

    IN TRY_date_detail values (to_date('11-08-2012','DD-MM-YYYY'), 11)

    IN TRY_date_detail values (to_date('11-08-2012','DD-MM-YYYY'), 12)

    IN TRY_date_detail values (to_date('11-08-2012','DD-MM-YYYY'), 13)

    IN TRY_date_detail values (to_date('11-08-2012','DD-MM-YYYY'), 14)

    IN TRY_date_master values (to_date('11-08-2012','DD-MM-YYYY'), 8913)

    IN TRY_date_detail values (to_date('09-03-2014','DD-MM-YYYY'), 21)

    IN TRY_date_detail values (to_date('09-03-2014','DD-MM-YYYY'), 22)

    IN TRY_date_detail values (to_date('09-03-2014','DD-MM-YYYY'), 23)

    IN TRY_date_master values (to_date('09-03-2014','DD-MM-YYYY'), 1234)

    IN TRY_date_detail values (to_date('11-03-2014','DD-MM-YYYY'), 33)

    Select * twice;

    -My query is:

    SELECT ITEM_DATE, ITEM_ORDER, DATE_AMOUNT NULL

    OF TRY_date_detail

    WHERE ITEM_DATE IN (SELECT DISTINCT master_date OF TRY_date_master)

    UNION

    SELECT MASTER_DATE, NULL, SUM (DATE_AMOUNT)

    OF TRY_DATE_MASTER

    MASTER_DATE GROUP;

    -My query result:

    ITEM_DATE ITEM_ORDER DATE_AMOUNT

    January 1, 11 12:00:00 AM 1 (null)

    January 1, 11 12:00:00 AM 2 (null)

    January 1, 11 12:00:00 AM 3 (null)

    January 1, 11 12:00:00 AM 4 (null)

    January 1, 11 12:00:00 AM 5 (null)

    January 1, 11 12:00:00 AM (null) 7543

    11 Aug 12 12:00:00 AM 11 (null)

    11 Aug 12 12:00:00 AM 12 (null)

    August 11, 12 noon 13 (null)

    11 Aug 12 12:00 14 (null)

    11 Aug 12 12:00:00 AM (null) 8913

    9 March 14 12:00:00 AM 21 (null)

    9 March 14 12:00:00 AM 22 (null)

    9 March 14 12:00:00 AM 23 (null)

    9 March 14 12:00:00 AM (null) 1234

    -What I need, is to display the Date_amount with the last line of each date as follows:

    ITEM_DATE ITEM_ORDER DATE_AMOUNT

    January 1, 11 12:00:00 AM 1 (null)

    January 1, 11 12:00:00 AM 2 (null)

    January 1, 11 12:00:00 AM 3 (null)

    January 1, 11 12:00:00 AM 4 (null)

    January 1, 11 12:00:00 AM 5 7543

    11 Aug 12 12:00:00 AM 11 (null)

    11 Aug 12 12:00:00 AM 12 (null)

    August 11, 12 noon 13 (null)

    August 11, 12 12 00 14 8913 h

    9 March 14 12:00:00 AM 21 (null)

    9 March 14 12:00:00 AM 22 (null)

    9 March 14 12:00:00 AM 23 1234

    Thank you

    Ferro

    You have to JOIN to the table two

    SQL> select item_date
      2       , item_order
      3       , decode(rno, cnt, date_amount) date_amount
      4    from (
      5          select item_date
      6               , item_order
      7               , date_amount
      8               , row_number() over(partition by item_date order by item_order) rno
      9               , count(*) over(partition by item_date) cnt
     10            from try_date_detail
     11            join (
     12                   select master_date, sum(date_amount) date_amount
     13                     from try_date_master
     14                    group
     15                       by master_date
     16                 )
     17              on item_date = master_date
     18         );
    
    ITEM_DATE           ITEM_ORDER DATE_AMOUNT
    ------------------- ---------- -----------
    01/01/2011 00:00:00          1
    01/01/2011 00:00:00          2
    01/01/2011 00:00:00          3
    01/01/2011 00:00:00          4
    01/01/2011 00:00:00          5        7543
    11/08/2012 00:00:00         11
    11/08/2012 00:00:00         12
    11/08/2012 00:00:00         13
    11/08/2012 00:00:00         14        8913
    09/03/2014 00:00:00         21
    09/03/2014 00:00:00         22
    09/03/2014 00:00:00         23        1234
    
    12 rows selected.
    
    SQL>
    

Maybe you are looking for

  • ooficejet HP 6600 not scan, copy or fax

    I get an error "unable to scan, copy or fax" on my hp officejet 6600.  I have already tried powerdown and back up and it did not work.  I also checked for updates and all this so far.  Any ideas on what could be the problem and how to fix it?

  • IPhone 6 and repair

    I have a screen that is NOT my original iphone screen and I have a motherboard problem. My screen has more contact. It is possible to get it replaced or repaired with a 3rd party screen?

  • Where can I find temporary Internet files?

    I can't find something and search my computer can not find anything!

  • How to edit a file

    How to edit a file

  • How can I activate Lightroom with my serial number?

    The most recent update of Lightroom has caused the dreaded error "the application could not start properly...". "I tried the AIDS available on the web and the forums, but nothing has worked.  I decided that I would reinstall the software, using the C