Select only last date

Hi all!
How do I select only last date for each contragentid?
So for contragentid = 111270 it should be only '14.05.2010'.
select dd.contragentid,
decode(dd.ratingvalue,'PK1',1,'PK2',2,'PK3',2,'PSR',2,'UN4',2,'VVL',2,'BK',4,3) as ratingvalue from
(select 36 as contragentid, 'UN1' as ratingvalue, '25.02.2010' as ratingstartdate from dual
union all
select 111270 as contragentid, 'PK1' as ratingvalue, '26.11.2009' as ratingstartdate from dual
union all
select 111270 as contragentid, 'PK3' as ratingvalue, '14.05.2010' as ratingstartdate from dual
union all
select 111270 as contragentid, 'BK' as ratingvalue, '14.06.2011' as ratingstartdate from dual ) dd
where dd.ratingstartdate <= to_date('31.05.2010', 'DD.MM.YYYY')Also I need to select all rows from second test case for those contragentid which absent in first case, it should be one statement for both cases.
select * from
(select 5 as contragentid, 2 as ratingvalue from dual
union all
select 111270 as contragentid, 1 as ratingvalue from dual ) hhThanks ahead!

I've got solution for the first part of my beginning post:
select dd.contragentid,
decode(dd.ratingvalue,'PK1',1,'PK2',2,'PK3',2,'PSR',2,'UN4',2,'VVL',2,'BK',4,3) as ratingvalue,
last_value(dd.ratingstartdate) over
   (partition by dd.contragentid ORDER BY dd.contragentid, dd.ratingstartdate desc 
      ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) AS last_ratingstartdate
FROM
(select 36 as contragentid, 'UN1' as ratingvalue, to_date('25.02.2010','DD.MM.YYYY') as ratingstartdate from dual
union all
select 111270 as contragentid, 'PK1' as ratingvalue, to_date('26.11.2009','DD.MM.YYYY') as ratingstartdate from dual
union all
select 111270 as contragentid, 'PK3' as ratingvalue, to_date('14.05.2010','DD.MM.YYYY') as ratingstartdate from dual
union all
select 111270 as contragentid, 'BK' as ratingvalue, to_date('14.06.2011','DD.MM.YYYY') as ratingstartdate from dual ) dd,
(select contragentid, max(ratingstartdate) as ratingstartdate from
(select 36 as contragentid, 'UN1' as ratingvalue, to_date('25.02.2010','DD.MM.YYYY') as ratingstartdate from dual
union all
select 111270 as contragentid, 'PK1' as ratingvalue, to_date('26.11.2009','DD.MM.YYYY') as ratingstartdate from dual
union all
select 111270 as contragentid, 'PK3' as ratingvalue, to_date('14.05.2010','DD.MM.YYYY') as ratingstartdate from dual
union all
select 111270 as contragentid, 'BK' as ratingvalue, to_date('14.06.2011','DD.MM.YYYY') as ratingstartdate from dual )
where ratingstartdate <= to_date('31.05.2010', 'DD.MM.YYYY')
group by contragentid ) uu
where
    uu.contragentid = dd.contragentid
and uu.ratingstartdate = dd.ratingstartdateNow I need to add contragentid from the second test case (see beginning post) which are absent in my first test case.

Similar Messages

  • How to select only last 4 characters in a column of type varchar2

    The data in column P_JACKS.LABEL is in the form of:
    294-001,
    B01-099,
    194A-098,....
    I'd like to select only the 3 characters following the '-' dash, and find the maximum of that set.
    This must be simple, I know, but so am I. Can someone please help me with this?
    Thanks!!

    I'm sure there is some slick regexp way to do it but this should work
    WITH t AS
      (SELECT '294-001' value FROM dual
      UNION ALL
      SELECT 'B01-099' FROM dual
      UNION ALL
      SELECT '194A-098' FROM dual
    SELECT greatest( (SUBSTR( value,LENGTH(value)-2,1)), (SUBSTR( value,LENGTH(value)-1,1)), (SUBSTR( value,LENGTH(value))) )
    FROM tmaybe I misunderstood do want to the max for the whole group as in 99
    or did you mean 3 rows with values
    1
    9
    9
    which is what I did
    Edited by: pollywog on Sep 9, 2010 6:45 PM
    Edited by: pollywog on Sep 9, 2010 6:47 PM

  • How to get  --Last date of the Last value .

    Dear All,
    I have a report like
    Material – Country – Current Price
    1112-----  Singapore  -
      100
    1112-----  Japan  -
      120
    1112-----  Malesia   -
      99
    Here current price is Last Value of the particular Material on particular Date.
    This I can get based on Key figure Aggregation ( Last Value and reference Character 0CALDAY ), It is giving the last Value of the Particular Material.
    Now my user wants to see Last date of the value ( Date of the Value )
    Example :-
    Material – Country –  Date --Current Price
    1112-----  Singapore  -
    01/04/2008 -- 100
    1112-----  Japan  -
    04/05/2008 -- 120
    1112-----  Malesia   -
    05/05/2008 -- 99
    If  I drill down the date in my  report  it is showing all dates , my user wants to see only last date .
    Hope some one has solved this issue , please help me to solve this issue.
    Regards,
    SHAIK.

    I have created a keyfigure with date as a data type.
    In aggregation tab, I selected  aggregation Maximum.
    Upto DSO, data is Loaded perfect. Ok.
    I added the same key figure in cube , When I am trying to Activate the Transformation,
    It is giving Error message.
    Rule 17 is invalid and is being deleted. The reason for this is that a field or InfoObject that is used in rule 17 has been deleted in the source or target of the transformation ODSO ZPL_DSO1 -> CUBE ZPLATT_C (0GH6MHANQ2J79LXZBLGIJ9ZK9LWHK6RS)
    Plz Advice.
    Regards,
    SHAIK
    Edited by: shaik on May 7, 2008 5:46 PM

  • Report req -To get the last date

    Hi all,
    I have  one report requirement,I have to develope the report to display last movement date.
    I am able to get the all movement dates regarding the particular material.But I need to display only last date .Is any option in query designer to get last date only in report .Instead of displaying all dates like MAX of the date in our abap code.
    Thank's
    BK

    Hello Srini / Tarak
    Thank you I will try your options .But I dont have any direct keyfigure like : last movement date.
    I have to do all cal on my date characteristic only.In this regard please suggest...
    Thanks
    Bk

  • Select only the last 12 months

    Hi all
    I need to write a query that will select only records from the last 12 months, order them by customer ID, and show one column per month, and a Total column where I need to add monthly Values.
    The table has the following fields
    •     YearMonth varchar(6)
    •     CustomerID varchar(15)
    •     Value integer
    Records example
    - 200809, 1, 10
    - 200809,2,20
    - 200808,1,15
    - 200808,2,12
    - 200501, ….
    I need to write a query and place it in a view that will select only records from the last 12 months, order them by customer ID, and show one column per month, and a Total column where I need to add monthly Values.
    The results should display the:
    •     CustomerID,
    •     one column per month displaying the Value
    • and the total column (sum monthly values for a customer)
    My questions are:
    •     How do I select records only from the last 12 months
    •     How do I name dynamically the columns, because today October,15 the list will start in November 2007 through October 2008, but next month it will move from December 2007 through October 2008
    •     How do I create a view with dynamic columns
    •     How do I create a column totals
    Please advice

    Hi,
    user631364 wrote:
    ... My questions are:
    •     How do I select records only from the last 12 monthsThere a a couple of things you could mean by "the last 12 months".
    Hkandpal showed you one way.
    Another is
    WHERE   yearmonth >= TO_CHAR (ADD_MONTHS (SYSDATE, -11), 'YYYYMM')
      AND   yearmonth <= TO_CHAR (            SYSDATE,       'YYYYMM')Storing DATEs in a VARCHAR2 column (or in any type of column other than DATE) is a bad idea. At best, it will involve lots of conversions, like those above.
    •     How do I name dynamically the columns, because today October,15 the list will start in November 2007 through October 2008, but next month it will move from December 2007 through October 2008
    •     How do I create a view with dynamic columns
    How to Pivot a Table with a Dynamic Number of Columns
    For example, you want to make a cross-tab output of
    the scott.emp table.
    Each row will represent a department.
    There will be a separate column for each job.
    Each cell will contain the number of employees in
         a specific department having a specific job.
    The exact same solution must work with any number
    of departments and columns.
    (Within reason: there's no guarantee this will work if you
    want 2000 columns.)
    PROMPT     ==========  0. Basic Pivot  ==========
    SELECT     deptno
    ,     COUNT (CASE WHEN job = 'ANALYST' THEN 1 END)     AS analyst_cnt
    ,     COUNT (CASE WHEN job = 'CLERK'   THEN 1 END)     AS clerk_cnt
    ,     COUNT (CASE WHEN job = 'MANAGER' THEN 1 END)     AS manager_cnt
    FROM     scott.emp
    WHERE     job     IN ('ANALYST', 'CLERK', 'MANAGER')
    GROUP BY     deptno
    ORDER BY     deptno
    PROMPT     ==========  1. Dynamic Pivot  ==========
    --     *****  Start of dynamic_pivot.sql  *****
    -- Suppress SQL*Plus features that interfere with raw output
    SET     FEEDBACK     OFF
    SET     PAGESIZE     0
    SPOOL     p:\sql\cookbook\dynamic_pivot_subscript.sql
    SELECT     DISTINCT
         ',     COUNT (CASE WHEN job = '''
    ||     job
    ||     ''' '     AS txt1
    ,     'THEN 1 END)     AS '
    ||     job
    ||     '_CNT'     AS txt2
    FROM     scott.emp
    ORDER BY     txt1;
    SPOOL     OFF
    -- Restore SQL*Plus features suppressed earlier
    SET     FEEDBACK     ON
    SET     PAGESIZE     50
    SPOOL     p:\sql\cookbook\dynamic_pivot.lst
    SELECT     deptno
    @@dynamic_pivot_subscript
    FROM     scott.emp
    GROUP BY     deptno
    ORDER BY     deptno
    SPOOL     OFF
    --     *****  End of dynamic_pivot.sql  *****
    EXPLANATION:
    The basic pivot assumes you know the number of distinct jobs,
    and the name of each one.  If you do, then writing a pivot query
    is simply a matter of writing the correct number of ", COUNT ... AS ..."\
    lines, with the name entered in two places on each one.  That is easily
    done by a preliminary query, which uses SPOOL to write a sub-script
    (called dynamic_pivot_subscript.sql in this example).
    The main script invokes this sub-script at the proper point.
    In practice, .SQL scripts usually contain one or more complete
    statements, but there's nothing that says they have to.
    This one contains just a fragment from the middle of a SELECT statement.
    Before creating the sub-script, remember to turn off SQL*Plus features
    that are designed to help humans read the output (such as headings and
    feedback messages like "7 rows selected.", since we do not want these
    to appear in the sub-script.
    Remember to turn these features on again before running the main query.
    •     How do I create a column totalsIn SQL*Plus, use the BREAK command.
    In SQL, "GROUP BY ROLLUP" or "GROUP BY GROUPING SETS"

  • Query to find first and last call made by selected number for date range

    Hi,
    query to find first and last call made by selected number for date range
    according to filter:
    mobile_no : 989.....
    call_date_from : 25-april-2013
    call_date_to : 26-april-2013
    Please help

    Hi,
    It sounds like you want a Top-N Query , something like this:
    WITH    got_nums   AS
         SELECT     table_x.*     -- or list columns wanted
         ,     ROW_NUMBER () OVER (ORDER BY  call_date      ) AS a_num
         ,     ROW_NUMBER () OVER (ORDER BY  call_date  DESC) AS d_num
         FROM     table_x
         WHERE     mobile_no     = 989
         AND     call_date     >= DATE '2013-04-25'
         AND     call_date     <  DATE '2013-04-26' + 1
    SELECT  *     -- or list all columns except a_num and d_num
    FROM     got_nums
    WHERE     1     IN (a_num, d_num)
    ;This forum is devoted to the SQL*Plus and iSQL*Plus front ends. This question doesn't have anything to do with any front end, does it? In the future, you'll get better response if you post questions like this in the PL/SQL.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the SQL forum FAQ {message:id=9360002}

  • Determine the last date of visit before FY selected in the slicer

    Hi,
    I have data for date wise clients visits.  My objective is to determine the last date of visit to the client before the FY selected in the slicer.
    The objective, data layout and question is available in this file
    http://sdrv.ms/19RnW0A
    Please help with the appropriate PowerPivot calculated Filed formula.
    Thank you.
    Regards, Ashish Mathur Microsoft Excel MVP www.ashishmathur.com

    Hi, basically this calculation would solve your initial question, though, it does not match the requested results:
    LastVisit:=CALCULATE(MAX(Data[Date]), DATESBETWEEN(Calendar[Date], BLANK(), MIN(Calendar[Date])-1))
    its important to add that this calculation only works if you mark your Calendar-table as Date-table which was not the
    case in the sample workbook!
    assuming you select 2012-2013, then according to your Calendar-table you select dates from 31/12/2012 till 30/12/2013
    so the "last date of visit to the client before the FY selected in the slicer." would be the last visit before
    31/12/2012 which would be 12/12/2012 for Client A and not 25/02/2012 as expected result
    hth,
    gerhard
    Gerhard Brueckl
    blogging @ http://blog.gbrueckl.at
    working @ http://www.pmOne.com
    Gerhard's approach is a nice clean solution.
    The only thing I would add is that we could use LASTDATE and FIRSTDATE instead of the MIN/MAX functions:
    LastVisit:=
    CALCULATE(
    LASTDATE(Data[Date]),
    DATESBETWEEN(
    Calendar[Date],
    BLANK(),
    FIRSTDATE(Calendar[Date]) -1)
    In order to achieve the overall outcome described in the uploaded Excel workbook, changes to the how the [Financial Year] and [Financial Year Key] are calculated will also need to be made (so that the slicer filters the correct data ranges).
    This can be done by using the suggested calculated column changes above or something similar.
    Having reviewed the requirement again, the logic behind the [Last Visit Last Year] measure that I proposed is slightly different from what is required because it only looks at the last visit date
    within the previous financial year to the one currently selected in the slicer. On the other hand Gerhard's is looking for the last visit date
    any time before the first date in the selected financial year and this is more in-line with the actual requirement. With the provided dataset, both approaches provide the same outcome, but the difference
    in behaviour would become apparent if the last visit date was not found within the previous financial year to the one selected in slicer.

  • Selecting a group of Images? only last image getting adjustments?

    sorry if this is a stupid question, but when I select a range of images and apply image rotation or stamp metadata, only the last image in the selection gets the adjustment that I apply to the images.
    It seems that when I select the images, the whole group has a white boarder around it, but the last image has a thicker boarder around it, and that is the only image that will respond to a change. I must have hit some weird short cut key to turn on that option, how do I turn that off?
    Please I need help asap, it's driving me insane. Thank you

    There is a rectangle box on the bottom of the Aperture screen that is the primary only box. If you have that selected only the primary image will be adjusted.
    Jeff

  • Last date of the selected quarter

    hi all - I have been struggling to figure out how to get the last date of selected quarter. for example, if the user has selected 2014 Q1 from the date hierarchy, I want to show 2014-03-31.
    any idea how to accomplish this? thanks in advance

    Hi Sam,
    There are several ways to do this in MDX.  
    One way is to use LastChild a few times.  For example, if your hierarchy had Period, Week, and Day below Quarter, and you were sure the user had selected a Quarter (the MDX could check) try this assuming your date hierarchy is calle [Date].[Fiscal
    Calendar].    [Date].[Fiscal Calendar].lastchild.lastchild.lastchild
      The first lastchild will get the last Period in the Quarter, the second lastchild the last week in that Period and the third lastchild will get the last day of that week.
    Another way, which will work for any level they selected would be something like; assuming the Day level is called [TheDate].   Tail(Descendants([Date].[Fiscal Calendar],[Date].[Fiscal Calendar].[TheDate]),1).item(0)  The descendants
    gets all the days in the selected period, the tail gets a set including just the last day, and Item(0) gets that particular day.
    Of course, the MDX snippets above could be used in larger MDX expressions.
    Hope that helps.  It really is worthwhile to learn a little MDX.  Remember, anything is possible in MDX if the cube has the data.
    Richard

  • DTP Routine to load only last year data

    Hi Gurus,
    I have a requirement to load only last year ( 0CALMONTH  i.e MM/YYYY)  data based on current year in transformation, Please could you correct below code...
    DATA: l_idx like sy-tabix.
      DATA: DATE_H TYPE D.
      DATE_H = SY-DATUM(4) - 1.
      l_t_range-SIGN = 'I'.
      l_t_range-OPTION = 'EQ'.
      l_t_range-HIGH = DATE_H.
      if l_idx <> 0.
        modify l_t_range index l_idx.
      else.
        append l_t_range.
      endif.
      p_subrc = 0.
    Right now it is bringing upto last year data. Please could you guide me what changes needs to be done...
    Thanks
    Ganesh Reddy.

    DATA: DATE_H(6) TYPE c,
                 DATE_L(6) TYPE c'
                 L_YEAR(4) TYPE c.
    L_YEAR = SY-DATUM(4) - 1.
    CONCATENATE L_YEAR '01' INTO DATE_L.
    CONCATENATE L_YEAR '12' INTO DATE_H.
    l_t_range-SIGN     = 'I'.
    l_t_range-OPTION = 'BT'.
    l_t_range-LOW     = DATE_L.
    l_t_range-HIGH     = DATE_H.

  • Select only dates greater than static value

    I am retreiving dates from an sql table, currently I am pulling all the dates. How do I only pull dates greater than say 5/1/2008?
    Below is the current code.
    String strSQL = "Select convert(nvarchar, wk_dt, 101) as outDt From t_fiscal_weeks Where wk_dt <= '" +
    DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new java.util.Date()) + "' Order by wk_dt desc";
    Thanks for the help

    Always, always, always use a PreparedStatement: [http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html]

  • Getting data in a query on last date of all previous months

    Dear Experts,
    I need your help with a query.
    I am trying to create a query which when run should pick the number of Open Sales Order on the last date of all the previous months from the start of company.
    I could create the query for fetching the required data on last day of the previous month, say today is 25th June 2014, so my query only fetches data for May 31st 2014 but I need data for all previous month, May 31st 2014, April 30th 2014, March 31st 2014 & so on.
    Please advise how to achieve this is SQL query.
    Thanks & regards,
    Nitin

    Hi,
    Try this:
    Select *
    from(
    SELECT T0.[DocNum] as #,t0.cardcode as C, t0.docdate
    FROM ORDR T0
    WHERE T0.[DocStatus] = 'o' and T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-1,0)),10) OR T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-2,0)),10) or T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-3,0)),10) or T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-4,0)),10) or T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-5,0)),10) or T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-6,0)),10) or T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-7,0)),10)
    group by t0.cardcode,docdate,T0.[DocNum]) S
    pivot
    (count(#) for c in([cvt01],[cvt02],[cvt03],[cvt04],[cvt05],[cvt06],[cvt07],[cvt08],[cvt12])) P
    Note: Replace Cvt01,02...with your customer code.
    Thanks & Regards,
    Nagarajan

  • How to get first and last date of previous month

    To set default values in selection screen,I want first and last date of the previous month.
    Also I want the first and last dates of previous quarter.
    The quarters can be only january to march, apr to june, jul to sept, oct to dec.
    I want to run a program on beginning of each month by job scheduling having <b>selection screens</b> for the above monthly and quarterly dates.

    Hi Suhas,
    Use the below code.
    DATA: v_date LIKE sy-datum.
    DATA: v_month_begin_date TYPE sy-datum,
          v_month_end_date TYPE sy-datum,
          v_month(2) TYPE n,
          v_month1(2) TYPE n,
          v_quarter TYPE i,
          v_year(4) TYPE n,
          v_quarter_begda TYPE sy-datum,
          v_quarter_endda TYPE sy-datum.
    v_month =  sy-datum+4(2).
    IF v_month = '01'.
      v_month = '12'.
      v_year = sy-datum+0(4) - 1.
    ELSE.
      v_month = v_month - 1.
      v_year = sy-datum+0(4).
    ENDIF.
    CONCATENATE v_year v_month  '01' INTO v_date.
    CALL FUNCTION 'HR_JP_MONTH_BEGIN_END_DATE'
      EXPORTING
        iv_date             = v_date
      IMPORTING
        ev_month_begin_date = v_month_begin_date
        ev_month_end_date   = v_month_end_date.
    v_month1 = sy-datum+4(2).
    IF v_month1 = '01' OR
       v_month1 = '02' OR
       v_month1 = '03'.
      v_quarter = 1.
    ELSEIF v_month1 = '04' OR
           v_month1 = '05' OR
           v_month1 = '06'.
      v_quarter = 2.
    ELSEIF v_month1 = '07' OR
           v_month1 = '08' OR
           v_month1 = '09'.
      v_quarter = 3.
    ELSEIF v_month1 = '10' OR
           v_month1 = '11' OR
           v_month1 = '12'.
      v_quarter = 4.
    ENDIF.
    IF v_quarter = 1.
      v_quarter = 4.
      v_year = sy-datum+0(4) - 1.
    ELSE.
      v_quarter = v_quarter - 1.
      v_year = sy-datum+0(4).
    ENDIF.
    CALL FUNCTION 'HR_99S_GET_DATES_QUARTER'
      EXPORTING
        im_quarter = v_quarter
        im_year    = v_year
      IMPORTING
        ex_begda   = v_quarter_begda
        ex_endda   = v_quarter_endda.
    WRITE:/5 'previous month begin date : ', v_month_begin_date.
    WRITE:/5 'previous month end date   : ', v_month_end_date.
    WRITE:/5 'previous quarter begin date : ', v_quarter_begda.
    WRITE:/5 'previous quarter end date : ', v_quarter_endda.
    Message was edited by:
            Velangini Showry Maria Kumar Bandanadham

  • Error occured in the data selection while extract data from Source system

    Hello Friends
    i am facing Problem while extracting data to Biw System from SAP R/3 system
    The error mesage is 'Error occured in the data selection '
    i.e. Monitoring - Details tab - Extraction - With error

    Hi
    The delta wil take the Last init selection for loading data in to the BW...
    Did u check the IP at the Update tab is it the correct delta only.. or its a full..
    better to go to the RSA3 and check the extractor in the Delta mode .. if u give ur delta mode it automatically takes the selction options.. so please try in RSA3..
    regards
    CK
    PS: CHECK THE INIT SELECTIONS TOO  or do an init with outdatatransfer and perform the delta...
    Message was edited by:
            BW Star

  • Repeating nodes using FOR loop but when concating XML string then concating only last iteration of FOr loop ??

    I stuck with a problem that I am using FOR loop for generating repeating nodes. 
    Now when I concat the generated node in the main node then I got only last iteration of that FOR loop.
    can anybody suggest me a way to handle this error....
    FOR i IN 1..pl_phone_tab.Count
    LOOP
    SELECT xmlelement("Phone"     
                                        ,xmlelement("PHONETYPE",xmlattributes('01' AS "dmnADRP_PHONETYPE"),pl_phone_tab(i).p_phtype_tab)
                         ,xmlelement("PHONENUM",pl_phone_tab(i).p_phnum_tab)
                         ,xmlelement("PRIMARY_CONTACT",pl_phone_tab(i).p_prcon_tab)
    INTO p_phone_xml
    FROM dual; END LOOP;
    SELECT xmlelement("PhoneInfo"
                           ,xmlconcat(p_phone_xml))
    INTO p_phone_info_xml
    FROM dual;
    here I am getting only one node but there has to be two nodes for PHONE node

    Not that I'm encouraging you but here are two standalone examples explaining how to do what you want :
    1) Loop through the input collection and append each node to its target container :
    SQL> declare
      2 
      3    type t_emp_tab is table of scott.emp%rowtype;
      4 
      5    emp_tab       t_emp_tab;
      6    emp_info_xml  xmltype;
      7    emp_xml       xmltype;
      8 
      9  begin
    10 
    11    -- filling emp_tab with data
    12    select e.*
    13    bulk collect into emp_tab
    14    from scott.emp e
    15    where e.deptno = 10;
    16 
    17    emp_info_xml := xmltype('<EmpInfo/>');
    18 
    19    -- looping through emp collection and appending to EmpInfo element
    20    for i in 1 .. emp_tab.count loop
    21      select appendchildxml(
    22               emp_info_xml
    23             , '/*'
    24             , xmlelement("Emp"
    25               , xmlattributes(emp_tab(i).empno as "id")
    26               , xmlforest(
    27                   emp_tab(i).ename as "Name"
    28                 , emp_tab(i).job as "Job"
    29                 )
    30               )
    31             )
    32      into emp_info_xml
    33      from dual;
    34    end loop;
    35 
    36    dbms_output.put_line(emp_info_xml.getclobval(1,2));
    37 
    38  end;
    39  /
    <EmpInfo>
      <Emp id="7782">
        <Name>CLARK</Name>
        <Job>MANAGER</Job>
      </Emp>
      <Emp id="7839">
        <Name>KING</Name>
        <Job>PRESIDENT</Job>
      </Emp>
      <Emp id="7934">
        <Name>MILLER</Name>
        <Job>CLERK</Job>
      </Emp>
    </EmpInfo>
    PL/SQL procedure successfully completed
    2) Build a secondary collection of XML nodes and use XMLAgg to aggregate them in one go :
    SQL> declare
      2 
      3    type t_emp_tab is table of scott.emp%rowtype;
      4 
      5    emp_tab       t_emp_tab;
      6    emp_info_xml  xmltype;
      7    emp_xml_tab   xmlsequencetype := xmlsequencetype();
      8 
      9  begin
    10 
    11    -- filling emp_tab with data
    12    select e.*
    13    bulk collect into emp_tab
    14    from scott.emp e
    15    where e.deptno = 10;
    16 
    17    -- looping through emp collection and appending to the collection of Emp nodes
    18    for i in 1 .. emp_tab.count loop
    19 
    20      emp_xml_tab.extend;
    21 
    22      select xmlelement("Emp"
    23             , xmlattributes(emp_tab(i).empno as "id")
    24             , xmlforest(
    25                 emp_tab(i).ename as "Name"
    26               , emp_tab(i).job as "Job"
    27               )
    28             )
    29      into emp_xml_tab(i)
    30      from dual;
    31 
    32    end loop;
    33 
    34    select xmlelement("EmpInfo", xmlagg(t.column_value))
    35    into emp_info_xml
    36    from table(emp_xml_tab) t ;
    37 
    38    dbms_output.put_line(emp_info_xml.getclobval(1,2));
    39 
    40  end;
    41  /
    <EmpInfo>
      <Emp id="7782">
        <Name>CLARK</Name>
        <Job>MANAGER</Job>
      </Emp>
      <Emp id="7839">
        <Name>KING</Name>
        <Job>PRESIDENT</Job>
      </Emp>
      <Emp id="7934">
        <Name>MILLER</Name>
        <Job>CLERK</Job>
      </Emp>
    </EmpInfo>
    PL/SQL procedure successfully completed
    Both solutions give the same output.
    Test them both and see which one fits better into your scenario.

Maybe you are looking for

  • When people view my site, it appears ... then quickly disappears!!  ???

    I recently viewed my site from a friend's Windows PC and the screen began to populate with graphics and text. As soon as it was completely populated, all the graphics and text disappeared leaving only the background 'fill' ... I have used other Windo

  • Copying cells from Google Docs to Numbers doesn't work

    I've tried multiple times now to copy data from a Google Docs into a Numbers spreadsheet, to no avail. I'm trying to copy two columns of data, about 150 rows long, and instead of it pasting into two columns, it pastes into a single column in Numbers.

  • Table for  manage cube

    Dear Experts I need to find out what table stores the information for Selection Conditions in RSA1 >  right-mouse-click on cube>  Manage . Its now invisible even though invisibility is not turned on. Please advise. Thanks. regards Pascal

  • Acrobat Server Edition?

    Hope someone can point me in the right direction regarding network use of Adobe Acrobat. Does Adobe still offer a server version of the product? How about the use of Acrobat under Windows Terminal Server? Ideally, I would like my Remote Desktop users

  • Retaining data for Upload Sync BO

    Hi all , If I am using an Upload type of Sync BO , the local data on client is sent to server after synchronization . But if I want to retain the data on client after  synchronization , what setting should done or methods called in Java classes ?