Need to Concatenate Data In a Single Record

Guys
Here I describe the example on the employee data
Before
10 ABC
10 SCOTT
10 KING
20 ROBERT
20 ALLEN
AFTER
10 ABC, SCOTT, KING
20 ROBERT, ALLEN
I had a requirement to concatenate employee name in single record by department wise, I have done by creating
function(Using loop) and call it in sql query, but query is getting much time,
Is there any other way to improve the query without using loop?
Kindly help me, Thanks in Advance.

SQL> ed
Wrote file afiedt.buf
  1  select deptno,
  2  LTRIM(max(sys_connect_by_path(ename,',')),',') employess
  3  from (select deptno,ename,
  4        row_number() over(partition by emp.deptno
  5        order by empno) r
  6        from emp)
  7  start with r=1
  8  connect by prior r+1=r
  9         and prior deptno=deptno
10* group by deptno
SQL> /
    DEPTNO
EMPLOYESS
        30
ALLEN,WARD,MARTIN,BLAKE,TURNER,JAMES
        20
SMITH,JONES,SCOTT,ADAMS,FORD
        10
CLARK,KING,MILLERFor more example
http://www.oracle-base.com/articles/misc/StringAggregationTechniques.php

Similar Messages

  • Concatenate multiple records into one single record

    Hello everyone,
    Can anyone guide me how to merge multiple records into one single record
    like......... I am getting the data in the file like
    aaaaa/bbbbbbb/ccccccccccc/dddddddddddd/eee
    ffffff/gggg/hhhhhhhhhhhhhh
    /123/4567/55555/99999999/kaoabfa/eee
    fffff/kkkkkkkk/llllllllllllllllllllllll
    when i use gui_upload I am getting the data into the internal table in the above format.
    My main intension is to split the record at / to multiple lines and dowload it into another file.
    What i am planning to do is... if the line does not start with / then i want to concatenate the multiple lines into single line and then split it into multiple records. Can anyone guide me how to achieve this.

    Yes, it should work.
    In my example
    Loop at itab.
    concatenate i_text itab into i_text.
    endloop.
    You change that loop for the loop of your internal table with the file records
    So if you have this three records
    'aaaa/bbb/ccc'
    '/dddd/efg'
    'hijk/lmn'
    i_text will look like this at the end
    'aaaa/bbb/ccc/dddd/efghijk/lmn'
    then in this part of the code
    split i_text at '/' into table itab2.
    itab2 will have the records looking like this
    aaaa
    bbb
    ccc
    dddd
    efghijk
    lmn'

  • Need single record for single period. Modify the select query.

    Requirement
    THere are 6 programs for each company for each billing period. If anyof the program for one billing period and period_balance>0 then display outstanding balance YES. if period_balance <=0 for all the programs for one period then outstanding balance=NO
    Below is the query i have used but i have to modify the query to get single record for each period whether outstandignbalance yes or no. Please help to resolve this issue. OR modify the query.
    select distinct B_Billing_key, B_COMPANY_ID company ,
    to_char(to_date('01/'||trim(substr(B_REPORT_PERIOD,5,2))||'/'||
    trim(substr(B_REPORT_PERIOD,1,4)),'DD/MM/YYYY'),'Month YYYY') Billing,
    Max(to_char(P_RECEIVED_DATE,'MM/DD/YY')) lastPaymentdate,
    SURCH_AMOUNT,ADJUST_AMOUNT,PI_AMOUNT,AMOUNT,
    (nvl(SURCH_AMOUNT,0)+nvl(ADJUST_AMOUNT,0)+nvl(PI_AMOUNT,0))-(nvl(sum(AMOUNT),0))"Period_Balance",
    decode(sign((nvl(SURCH_AMOUNT,0)+nvl(ADJUST_AMOUNT,0)+nvl(PI_AMOUNT,0))-(nvl(sum(AMOUNT),0))),1, 'Yes'
    ,'No'
    ) outstandingbalance
    p.PROGRAM_NAME_ID programname
    FROM tuff_balance_view,MV_PROG_SURCH S,MV_PAYMENT_HOLDING H,MV_PROGRAM_DICT P where
    b_company_id = 'U-7052-C'
    and B_Billing_key=s.BILLING_KEY
    and S.PROGRAM_KEY = P.PROGRAM_KEY
    and P.PROGRAM_KEY= H.PROGRAM_KEY
    GROUP BY B_Billing_key,B_COMPANY_ID,B_REPORT_PERIOD,SURCH_AMOUNT,ADJUST_AMOUNT,PI_AMOUNT,PROG_SURCH_KEY,
    S.PROGRAM_KEY,p.PROGRAM_NAME_ID,AMOUNT
    order by B_Billing_key desc
    B_Billing_key is the primary key. I am looking for the output only one record for each biling perid. there are 6 programs for each billing period. if any of the program has period balance >0 then outstanding balance should be yes. For sample i am giving 2 programs.
    Actual output from the above
    biling_key company billing period period_balance outstandingbalance programname
    123 xyz January 2011 $4 Yes ABC
    123 xyz January 2011 $-5 NO DEF
    456 xyz February 2011 $-3 NO ABC
    456 xyz February 2011 $- 2 NO DEF
    Need the output as below from the above query. Can you please help to simplify query. If anyof theprogram having outstanding balance for that particular period show the outstandigbalance as yes. Else NO.
    Expected output as below
    company billing period outstandingbalance programname
    xyz January 2011 Yes ABC
    xyz February 2011 No DEF
    Thanks,
    vi

    Hi G,
    With the same query i am gettting outs as NO for all months which is not true. can you pelase look at the following data.
    SELECT DISTINCT B_BILLING_KEY,
    to_char(to_date('01/'||trim(substr(B_REPORT_PERIOD,5,2))||'/'||
    trim(substr(B_REPORT_PERIOD,1,4)),'DD/MM/YYYY'),'Month YYYY') Billing,
    B_company_id company,
    sum((nvl(T.B_ORG_SURCH_AMOUNT,0)+nvl(T.B_ORG_PI_AMOUNT,0))-(nvl(T.P_AMOUNT,0))) "PeriodBalance",
    Max(to_char(P_RECEIVED_DATE,'MM/DD/YY')) LastPaymentDate,
    decode(sign(
    (nvl(T.B_ORG_SURCH_AMOUNT,0)+nvl(T.B_ORG_PI_AMOUNT,0))-(nvl(T.P_AMOUNT,0))), 1,'Yes','No') Outs
    FROM mv_program_dict P, tuff_balance_view T WHERE
    b_company_id = 'U-7052-C' group by B_REPORT_PERIOD,B_company_id,B_BILLING_KEY,B_ORG_SURCH_AMOUNT,
    B_ORG_PI_AMOUNT,P_AMOUNT
    order by B_BILLING_KEY desc
    Actual
    Billing key Billing company periodbalance lastpayment date outs
    110631534073     November 2010     U-7052-C     270          Yes
    110631534073     November 2010     U-7052-C     690          Yes
    110631534073     November 2010     U-7052-C     66          Yes
    110461533197     October 2010     U-7052-C     4740          Yes
    110461533197     October 2010     U-7052-C     27000          Yes
    110461533197     October 2010     U-7052-C     0          No
    110251532527     September 2010     U-7052-C     0     09/13/10     No
    110251532527     September 2010     U-7052-C     0          No
    110251532527     September 2010     U-7052-C     -18     09/13/10     No
    110251532484     August 2010     U-7052-C     0     09/13/10     No
    110251532484     August 2010     U-7052-C     2001     09/13/10     Yes
    110251532484     August 2010     U-7052-C     0          No
    Expectedoutput(need only following columns)
    Billing key Billing company lastpayment date outs
    110631534073     November 2010     U-7052-C               Yes
    110461533197     October 2010     U-7052-C               Yes
    110251532527     September 2010     U-7052-C          09/13/10     No
    110251532484     August 2010     U-7052-C          09/13/10     YES
    By using below query i am getting all output as NO. HOw to modify it.
    SELECT company,
    billing,LastPaymentDate,
    CASE
    WHEN SUM (DECODE (outs, 'YES', 1, 0)) > 0 THEN 'YES'
    ELSE 'NO'
    END Outstanding
    FROM (
    SELECT DISTINCT B_BILLING_KEY,
    to_char(to_date('01/'||trim(substr(B_REPORT_PERIOD,5,2))||'/'||
    trim(substr(B_REPORT_PERIOD,1,4)),'DD/MM/YYYY'),'Month YYYY') Billing,
    B_company_id company,
    sum((nvl(T.B_ORG_SURCH_AMOUNT,0)+nvl(T.B_ORG_PI_AMOUNT,0))-(nvl(T.P_AMOUNT,0))) "PeriodBalance",
    Max(to_char(P_RECEIVED_DATE,'MM/DD/YY')) LastPaymentDate,
    decode(sign(
    (nvl(T.B_ORG_SURCH_AMOUNT,0)+nvl(T.B_ORG_PI_AMOUNT,0))-(nvl(T.P_AMOUNT,0))), 1,'Yes','No') Outs
    FROM mv_program_dict P, tuff_balance_view T WHERE
    b_company_id = 'U-7052-C' group by B_REPORT_PERIOD,B_company_id,B_BILLING_KEY,B_ORG_SURCH_AMOUNT,
    B_ORG_PI_AMOUNT,P_AMOUNT
    order by B_BILLING_KEY desc)
    GROUP BY company, billing,LastPaymentDate;
    Note:in the actual out put max(lastpayment date) is returing null values. if there is any date in one billing return that date only remove null example is september. in september it should return only 09/13/10 this date not null date. but if there is no other within one biling then consider that as null example november..
    Thanks,
    v

  • Selecting single record from multiple record based on date

    Hi experts,
    I have a table which contains the multiple records for single ID No. Now i have to select single record which contains the latest date.
    here is the structure
    Name   Null Type        
    ID_P        NUMBER      
    NAME_P      VARCHAR2(12)
    DATE_P      TIMESTAMP(6)
    Records
    1 loosi     22-AUG-13 01.27.48.000000000 PM
    1 nammi  26-AUG-13 01.28.10.000000000 PM
    2 kk        22-AUG-13 01.28.26.000000000 PM
    2 thej      26-AUG-13 01.28.42.000000000 PM
    now i have to select below 2 rows how can write select qurie for this?
    1 loosi     26-AUG-13 01.27.48.000000000 PM
    2 thej      26-AUG-13 01.28.42.000000000 PM

    Hi,
    You can use the analytic ROW_NUMBER function.
    I don't have a copy of your table, so I'll use scott.emp to illustrate.  In scott.emp, there may be multiple rows for a single job.  To display just 1 row per job, the row with the most recent hiredate:
    WITH got_r_num AS
         SELECT  empno, job, deptno, hiredate -- Or whatever columns you want
         ,       ROW_NUMBER () OVER ( PARTITION BY  job
                                      ORDER BY      hiredate DESC
                                    )  AS r_num
        FROM    scott.emp
    --  WHERE ...   -- If you need any filtering put it here
    SELECT   *      -- Or list all columns except r_num
    FROM     got_r_num
    WHERE    r_num   = 1
    What results do you want in case of ties?  Depending on your requirements, you may want to add tie-breaking expressions to the analytic ORDER BY clause, and/or use RANK instead of ROW_NUMBER.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Point out where the query above is producing the wrong results, and explain, using specific examples, how you get the right results from the given data in those places.
    If you modify the query at all, post your modified version.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • Data Merge - Sets of Single Records?

    I am trying to use data merge to fill in fields, only problem is I need 2 sets of 2 records on one page. I could possibly reformat this to work on one page, but I would still need 2 sets for each record. Also, I know I could probably just change the data to have 2 of each record, but assume the data is unable to be changed. If there is a way to make a text box a slave of another where it could mimic the original record, maybe I could do it that way, I just don't know if that is possible. See image below.
    I am using InDesign CS3. Any ideas?

    I don't think there's any way to do this directly, but it could be done in two steps using a script to get your two-up layout.
    First, set up a page to hold only one record and do the two instances of the names as a single record per page.
    Next, go to http://forums.adobe.com/message/1308215 and copy the rotatepage.js script into a plain text editor like notepad, and save  withthe .js extension in the Scripts panel subdolder of the scripts folder in your user profile or user library. In Windows XP the path is \Documents and Settings\<user name>\Application Data\Adobe\InDesign\Version 5.0\Scripts\Scripts Panel and it will be similar in other operating systems.
    To run the script, double-click it in the scripts panel. I Think it should run as is, but if it fails, make a new subfolder in the scripts panel folder called "Version 3.0 Scripts" (without the quotes) and move it into that, then try again. Waht this script does is make a PDF of the open file, then create a new file with rotated pages and places the PDF rotated into the new file. The primary use was for doing things like calendars, but it will work to give you spreads that you can print (by checking the spreads box in the print dialog) as two-up.

  • How to store as single record data coming from different ods to cube

    Hi All,
            we have the scenario like .
    Same contract values are uploaded from 3 ods to cube.In the cube this information is stored as 3 different records.
    Is there any option having same contract no and same fiscal period values should be stored as single record in cube.
    Thanks in advance.
    Regards,
    Shradda.

    Hi Shradda,
    On Performance Side .....consider below points
    1. Indexes on Cube ( That delete indexes before load and create them after Load ).
    2. Aggregate Design ( Decision on Base Aggregates, roll up Hierarchy , BW Statistics etc ).
    3. Partition of InfoCube ( Basically decision on No. of Partition )
    4. Data Package Size ( Always try to have larger Data Package so that preaggreation will reduce the no. of Data Records ).
    Best is Service.sap.com on BI page u will find material for performance . THat will help you .
    To assign points on the left of screen u will get radio buttons for assigning points for each person who has responded .
    Regards,
    Vijay

  • Need to transfer data records from one version of sap to another version of

    hello,
            i have a requirement where i need to transfer the tables  with the records in it from sap r/3 4.7 version to sap ecc 6.0 version,now the present issue is how to tranfer the data records from old version to new version......kindly help me in this requirement

    Hi,
        Write a program in SAP 4.7 to download all records to a flat file. Then write a program in ECC6 to upload all records from the flat file...........
    Thanks,
    Aditya.

  • Tracking Changes for Single record in Data Dictionary

    Hi Experts,
    I encountered with this question in an interview. I was asked how to maintain/track changes for a particular single record in a Data Dictionary table. I knew that for an entire table we can do it using table maintenance events. But I was confused when the interviewer asked for one particular record in table. Kindly input your thoughts on this.
    Thanks.

    Hi Radhika,
    In case of record in a table we can use "log data changes" option (Table DBTABLOG) in Technical Settings > Log data changes. It enable writing of change documents in Tables CDHDR/CDPOS.
    Hope this helps.
    Regards,
    Naveen

  • Want to show data from current month & prev month in single record on forms?

    Hello experts,
    i have this requirement:
    Table structure:
    MOnth       Division         totalAmount
    01-apr-2013      1               10000
    01-May-2013    1               20000
    01-apr-2013      2               30000
    01-May-2013    2               50000
    i want to display in forms like
    Form:
    Month  : 01-May-2013
    Month               Division               total               prev_Month          division               total                         dIFFERENCE
    01-May-2013               1              10000                01-Apr-2013               1               20000                        10000
    01-May-2013               2              30000                01-Apr-2013               2               50000                        20000
    I am using two procedure for fetching records for current month and previous month.
    but it will cause problem, if for some division previous month data not present.
    please suggest me some query with which i can fetch current and pre month data in single record.
    Please help me out.
    Thanks
    yash

    I'M NOT SURE BUT TRY IT ............
    select x.mn mnth, x.division, x.totalAmount total, y.mn prev_month,  y.division, y.totalAmount total, (y.totalAmount - nvl(y.totalAmount,0)) difference
    from
      (select month mn, division, totalAmount
      from table_name
      where month = (select max(month)
      from table_name
      ) x,
      (select month mn, division, totalAmount
      from table_name
      where month = (select add_months(max(month),-1)
      from table_name
      ) y
    where x.division = y.division(+)
    MOSTAFIZ MITUL
    DHAKA BANGLADESH

  • Delete a single record of specific Master Data

    Hello Experts,
    We have this InfoObject '0FUND' which is time-dependent. For a specific Master Data, exp: 40002, we have a list of records, that vary in 'Valid from' and 'Valid To'. Example:
    FMArea__Fund____ValidTo____ValidFrom____Attribute...
    CM______40002__31.12.2001__01.01.1000_____MOD
    CM______40002__31.12.2002__01.01.2002_____MOD
    CM______40002__31.12.2003__01.01.2003_____MOD
    This master data as no transactional data in any InfoProvider. When we try to delete a single record, the system delete all the records for 0FUND=40002.
    Is there possible to make a selective deletion, in order to choose a single record?
    At same time, we delete from the InfoCube all transactional data assign to a specific Master Data in a particular year. Exp (0FUND=40022; 0FISCYEAR=2004). When we try to delete this specific record:
    FMArea__Fund____ValidTo____ValidFrom____Attribute...
    CM_____40022___31.12.2004__01.01.2004_____MOD
    The BW System doesn't allow deleting this specific record. Why this occur, its necessary delete all the transactional data assigned to 40022 Master Data??
    Best Regards,
    IB

    Hi IB,
    Yes. It is necessary to delete the transacton data where the master data is referred before deleting the master data. This because the master data value in the Cube/ODS looks up at the SID table for the master data.
    Bye
    Dinesh

  • [AS] Trying to change Single Record number under data merge?

    Any help would be great?

    This is where I am trying to go with this:
    tell application "Adobe InDesign CS3"
    tell data merge 1 of document 1
    tell data merge preferences
    set record selection to all records
    set records per page to single record
    set record number to 3--or any number or i value I want to repeat with
    end tell
    end tell
    tell document 1
    tell data merge properties to merge records--and merge that one number
    end tell
    end tell
    Setting the record number actually changes the field for single record but when I try to merge said number it does all the records. I am sure its an ordering thing but it is still causing some head scratches. You've all been really helpful with an area that doesnt seem to be detailed anywhere.
    Any help would be great. Thanks.

  • Need Help importing data using PHP to convert it into a single HTML line

    Hi, My names Chance
    I'm a 2nd year web design student and have been assigned a project by my teacher for a charity website
    i found a tutorial of exactly what i need to do but im stuck on creating a script to import  and convert php data
    to a single html line
    heres the link to the the script, if you scroll down to the bottom
    where it says
    RSS or XML Data Source
    "The scrolling text can be imported from any source: RSS, XML or any other format.
    For example, if you want to import data using PHP to convert it into a single HTML line to be displayed by the ticker, create a php script to import and convert the data, and include it directly in the DIV tag as follow"
    this is what i need help doing
    http://www.mioplanet.com/rsc/newsticker_javascript.htm
    i already have the php code that i want to import
    i just need to know how to import and convert my php script so im able
    to make the the javascript from the link i provided to work
    thank you so much for your time
    if you have any question or answer please email me
    [email protected]
    thanks again hope to here from you soon

    Hi
    The instructions are there on the page you provided a link to!
    What is it you do not understand?
    PZ
    www.pziecina.com

  • How to insert sales text (MM02) into a single record of a Ztable.

    Hi,
    I'm extracting data from different data base tables and populating a Ztable which has Matnr as primary key and sales text as a field.
    I have already used READ_TEXT to display the text and it is displayed in multiple records which in turn leads to duplication of Material numbers.
    Now I want to avoid duplication of records (Matnr) as this being a primary record, and display the sales text of a particular material number into one single record.
    Can anyone tell me how to insert sales text (MM02) transaction into one single record.
    Thanks,
    Govind

    sorry i am not enough clear about your requirement...
    as i can understand i am explaining to you.
    suppose your itab contains repaeating matnr.
    matnr
    1
    1
    2
    2
    2
    3
    3
    like this.
    data : text(200),
             matnr like mara-matnr.
    loop at itab.
    call READ_TEXT fnmodule.
    loop at tline.
    concatenate text tline-tdline into text.
    endloop.
    matnr = itab-matnr.
    at end of matnr.
    itab1-matnr = matnr.
    itab1-text = text.
    append itab1.
    clear text.
    endat.
    endloop.
    NB change the code as per your requirement
    regards
    shiba dutta

  • Integrating number of records into a single record

    Hi
    I have a table where we store trainees with certifications, it stores trainees address, id, pass/fail flag, course codes, competetion date and certificate expiration date. WHat I need is to display a single record for each trainee in my query. In this case, what we have currently in the table is we might have 11 certificates for a trainee or 1 or maybe 5 etc. All I need is to display all his information, address, trainee id, courrse code..course code11 in a signle record. Is it possible and how? Please help

    Try this one - it points to the same page and looks like it works:
    Re: How to show the SELECT result in a certain form?

  • I need options for data replication within production db and dimensional db

    Hi,
    I'm looking for options on how to solve this issue. We've 2 databases, one is our production, operative database, used by around 400 users at a time, and another one, which is our dimensional model of the same info, used to obtain reports. We also have a lot of ETL's (extract, transform and load) processes running every night to update the dim model.
    Mi problem is that we have some online reports, and nowadays, we're getting data from the operational database, causing a performance issue in online operations. We want to migrate this reports to the dimensional model, and we're trying to find the best options for doing this.
    Options that we're considering are ETL's process running continuously every XX minutes, materialized views, ETL's on demand, and others.
    Our objective is to minimize performance issues on transactional database.
    We're using Oracle 8i (yes, the oldie one) and Reporting Services as report engine (reports just run a pkg to get data).
    Any option is welcome.
    Thx in advance.
    Regards,
    Adrian.

    The best option for you if the performance is the
    most important is ORACLE STREAMS. Also is the most
    complex but the final results are very goodsAgreed. As User12345 points out, though, that requires Oracle 9.2 or higher.
    Another option is the materialized views with Fast
    Refresh , that need the materialized view logs in
    the master site.
    The first load is expensive but if you refresh each
    15 minutes the cost is not high.I'd be careful about making that sort of statement. The overhead of both maintaining materialized view logs (which have to be written to synchronously with the OLTP transactions and which impose an overhead roughly equivalent to a trigger on the underlying table) and doing fast refreshes every 15 minutes can be extensive depending on the source system. One of the reasons that Streams came about was to limit this overhead.
    For refresh i execute a cron shell that run the
    DBMS_MVIEW.REFRESH package. my experience with group
    refresh not was goodWhat was your negative experience with refresh groups? I've used them regularly without serious problems. Manual refreshes of individual materialized views against an OLTP system would scare the pants off me because you'd inevitably end up with transactionally inconsistent views of the data (i.e. child records would be present with no parent record, updates that affect multiple tables would be partially replicated until the next refresh, etc). Trying to move that sort of inconsistent data into a different data model, and trying to run reports off that data, would seem highly challenging at a minimum. Throwing everything into a single refresh group so that all the materialized views are transactionally consistent, or choosing a handful of refresh groups for those tables that are related to each other, seems like a far easier way to build a system.
    Justin

Maybe you are looking for

  • How do I download and access music directly from an external hard drive

    How do I download and access music directly from an external hard drive through iTunes

  • Tables for Release strategies

    Hi ... I was referring to MM table doc , in that it is mentioned table EBELN & EBELP are for Purchase Order header / Line and BANFN & BNFPO are for PR header/ Line. But for release strategy ...people told me to refer CEKKO for PO and CEBAN for PR. do

  • Full Database Export/Import

    I was attempting to export a full database from one server (DB files on the N: drive) and import it into a freshly created new database with the same instance name on a new server (DB files on the D: drive). I was told to: 1) Export the full database

  • Dbms_scheduler gives error when setting up notifiactions

    Hello, I'm using XE 11.g and SQL Developer 4.0 on a Windows 7 platform.  I have a package associated with a job.  I set it up using the Job wizard in SQL Developer 4.0.  The job is executed weekly, as defined the schedule.  All of this works well. I

  • 10.8 Safari (6?) won't stay open?

    Upon opening everytime I see a crash report. Process:         Safari [3151] Path:            /Applications/Safari.app/Contents/MacOS/Safari Identifier:      com.apple.Safari Version:         6.0 (8536.25) Build Info:      WebBrowser-7536025000000000~