How to get multiple records in one row and different column

Hi All,
I am using oracle database 11g
and i have a two tables table_1, table_2
table_1 having columns
emp_no
first_name
middle_name
last_name
email
and table_2 having columns
emp_no
phone_type
phone_number
and having entires
emp_no phone_type phone_number
1001 MOB 9451421452
1001 WEMG 235153654
1001 EMG 652341536
1002 MOB 9987526312
1003 WEMG 5332621456
1004 EMG 59612356
Now i want the output of values with phone type as MOB or WEMG in a single row with different columns
emp_no first_name middle_name last_name email mobile officeno
1001 mark null k [email protected] 9451421452 235153654
1002 john cena gary [email protected] 9987526312 null
1003 dany null craig [email protected] null 5332621456
1004 donald finn sian [email protected] null null
can i have any inputs to achive this???
Regards
$sid

Frank Kulash wrote:
sonething like this:Frank, you missed aggregate function (pivot requires one). However main thing is it will cause ORA-01748:
with table_1 as (
                 select 1001 emp_no,'mark' first_name,null middle_name,'k'last_name,'[email protected]' email from dual union all
                 select 1002,'john','cena','gary','[email protected]' from dual union all
                 select 1003,'dany',null,'craig','[email protected] null' from dual union all
                 select 1004,'donald','finn','sian','[email protected]' from dual
     table_2 as (
                 select 1001 emp_no,'MOB' phone_type,9451421452 phone_number from dual union all
                 select 1001,'WEMG',235153654 from dual union all
                 select 1001,'EMG',652341536 from dual union all
                 select 1002,'MOB',9987526312 from dual union all
                 select 1003,'WEMG',5332621456 from dual union all
                 select 1004,'EMG',59612356 from dual
SELECT     *
FROM     table_1      t1
JOIN     table_2      t2  ON  t1.emp_no = t2.emp_no
PIVOT     (    max(t2.phone_number)
     FOR  t2.phone_type  IN  ( 'MOB'   AS mob
                             , 'WEMG'  AS wemg
        FOR  t2.phone_type  IN  ( 'MOB'   AS mob
ERROR at line 19:
ORA-01748: only simple column names allowed hereYou need to:
with table_1 as (
                 select 1001 emp_no,'mark' first_name,null middle_name,'k' last_name,'[email protected]' email from dual union all
                 select 1002,'john','cena','gary','[email protected]' from dual union all
                 select 1003,'dany',null,'craig','[email protected] null' from dual union all
                 select 1004,'donald','finn','sian','[email protected]' from dual
     table_2 as (
                 select 1001 emp_no,'MOB' phone_type,9451421452 phone_number from dual union all
                 select 1001,'WEMG',235153654 from dual union all
                 select 1001,'EMG',652341536 from dual union all
                 select 1002,'MOB',9987526312 from dual union all
                 select 1003,'WEMG',5332621456 from dual union all
                 select 1004,'EMG',59612356 from dual
     table_3 as (
                 select  t1.emp_no,first_name,middle_name,last_name,email,
                         phone_type,phone_number
                   FROM     table_1      t1
                   LEFT JOIN     table_2      t2  ON  t1.emp_no = t2.emp_no
SELECT     *
FROM     table_3
PIVOT     (    max(phone_number)
     FOR  phone_type  IN  ( 'MOB'   AS mob
                             , 'WEMG'  AS wemg
    EMP_NO FIRST_ MIDD LAST_ EMAIL                     MOB       WEMG
      1004 donald finn sian  [email protected]
      1003 dany        craig [email protected] null            5332621456
      1001 mark        k     [email protected]      9451421452  235153654
      1002 john   cena gary  [email protected]    9987526312
SQL>SY.

Similar Messages

  • How to get multiple records using fn-bea:execute-sql()

    Hi,
    I created Proxy service(ALSB3.0) to get records from DB table. I have used Xquery function(fn-bea:execute-sql()). Using simple SQL query I got single record, but my table having multiple records. Please suggest how to get multiple records using fn-bea:execute-sql() and how to assign them in ALSB variable.
    Regards,
    Nagaraju
    Edited by: user10373980 on Sep 29, 2008 6:11 AM

    Hi,
    Am facing the same issue stated above that I couldnt get all the records in the table that am querying in the Proxyservice.
    For example:
    fn-bea:execute-sql('EsbDataSource', 'student', 'select Name from StudentList' ) is the query that am using to fetch the records from the table called StudentList which contains more than one records like
    Id Name
    01 XXX
    02 YYY
    03 ZZZ
    I tried to assign the result of the above query in a variable and while trying to log the variable, I can see the below
    <student>
    <Name>XXX</Name>
    </student>
    I want to have all the records from my table in xml format but it's not coming up. I get the value only from the first row of my table.
    Please suggest.
    regards,
    Venkat

  • How to create 2D array with 3 rows and unlimit column?

    how to create 2D array with 3 rows and unlimit column?

    Here are images of what I described in my previous post
    Message Edited by JoeLabView on 11-14-2007 07:56 AM
    Attachments:
    2D-array_code.PNG ‏7 KB
    2D-array_values.PNG ‏13 KB

  • How to concatenate multiple records into one

    Hi everybody:
    I want to know if exist some way to concat multiple records into one without using cursors. For example, I have a table named "Authors" like this:
    Lan|Author
    English|Ernest Hemingway
    Spanish|Octavio Paz
    Spanish|Mario Vargas Llosa
    English|Sinclair Lewis
    Spanish|Gabriel García Márquez
    And I want to get this:
    Author
    Octavio Paz, Mario Vargas Llosa, Gabriel García Márquez
    I have worked with SQL Server and I can do something like this:
    CREATE FUNCTION dbo.MyConcat (@lan varchar(10))
    RETURNS varchar(5000) AS
    BEGIN
    declare @retvalue varchar(5000)
    set @retvalue=''
    select @retvalue = @retvalue + Author +',' from Authors where lan = @lan
    return substring(@retvalue,1,len(@retvalue)-1)
    END
    ie, do not use cursors to concatenate records. However, with ORACLE, I have to do someting like this.
    FUNCTION MyConcat(P_Lan IN VARCHAR2) RETURN VARCHAR2 IS
    v_ret VARCHAR2(4000);
    v_element VARCHAR2(4000);
    v_cursor sys_refcursor;
    BEGIN
    OPEN v_cursor FOR SELECT Author FROM Authors where Lan = P_Lan
    LOOP
    FETCH v_cursor INTO v_elemento;
    EXIT WHEN v_cursor%NOTFOUND;
    IF v_ret IS NULL THEN
    v_ret := v_element;
    ELSE
    v_ret := v_ret || ', ' || v_element;
    END IF;
    END LOOP;
    RETURN v_ret;
    END;
    Exist some other way to do this?
    Best Regards
    Jack

    Tks both for answer... I forgot to mention that I am using Oracle 10g. I read about LISTAGG() but this function is available for Oracle 11g release 2.
    I wil read about the other techniques than Hoek mention
    Best Regards.
    Jack

  • How to get Multiple records from functions

    Hi Everyone
    Im new to this stuff. Im trying  through JCO. As far as the single recordsets like data of customer or article are concerned i get it through an array.
    But i wanted to retrieve
    1- Whole tables like (all articles)
    2- Selected articles. or Customer order details (articles in PO)
    That means multiple records in one go.
    Later on ill display it in JTables.
    Like for the past three days i was googling around. Thought like this ones not for my stomach. Came across this Forum. Thought its worth posting a request.
    Here is the code
    public String[] KSearch(String Knr) throws Exception{
                            String[] Result=new String[11];
                            IFunctionTemplate ftemplate= Con.repository.getFunctionTemplate("SucheKUNDE");
                            if (ftemplate == null)
                                    throw new Exception("Funktionstemplate nicht gefunden");
                            JCO.Function function = ftemplate.getFunction();
                            JCO.ParameterList input = function.getImportParameterList();
                            input.setValue(Knr,"FieldName");
                       JCO.Client client = JCO.getClient(Con.conPoolId);
                       client.execute(function);
                       JCO.ParameterList output = function.getExportParameterList();
                       Result[0]=output.getString("NAME");
                       Result[1]=output.getString("VORNAME");
                       Result[2]=output.getString("GDATE");
                       Result[3]=output.getString("TELEFON");
                       Result[4]=output.getString("MAIL");
                       Result[5]=output.getString("STRASSE");
                       Result[6]=output.getString("PLZ");
                       Result[7]=output.getString("ORT");
                       Result[8]=output.getString("KONTO");
                       Result[9]=output.getString("INSTITUT");
                       Result[10]=output.getString("BLZ");
                                                                                    JCO.releaseClient(client);
                       return Result;
    now instead of a single record what if im expecting a number of records, like what if i need customer over 25. Which means more than one. I have to get in tabular format so that i can display it in JTables.
    Hope it a bit illustrative.
    Regards
    Edited by: Aaron Maleck on Jan 5, 2008 7:35 AM

    public String[] KSearch(String Knr) throws Exception{
    String[] Result=new String11;
    IFunctionTemplate ftemplate= Con.repository.getFunctionTemplate("SucheKUNDE");
    if (ftemplate == null)
    throw new Exception("Funktionstemplate nicht gefunden");
    JCO.Function function = ftemplate.getFunction();
    JCO.ParameterList input = function.getImportParameterList();
    input.setValue(Knr,"FieldName");
    JCO.Client client = JCO.getClient(Con.conPoolId);
    client.execute(function);
    // Maybe here you should use a JCO.Table Class to get the //ExportParameters such as
    JCO.Table output = function.getTableParameterList().getTable( "tabelname" );
    // so you can use setRow() Function to get the information of the //relevant record. such as the 3. Costum
    output.setRow(3);// Record Number
    Result[0]=output.getString("NAME");
    Result[1]=output.getString("VORNAME");
    Result[2]=output.getString("GDATE");
    Result[3]=output.getString("TELEFON");
    Result[4]=output.getString("MAIL");
    Result[5]=output.getString("STRASSE");
    Result[6]=output.getString("PLZ");
    Result[7]=output.getString("ORT");
    Result[8]=output.getString("KONTO");
    Result[9]=output.getString("INSTITUT");
    Result10=output.getString("BLZ");
    JCO.releaseClient(client);
    return Result;
    &#65321;am not sure that works. But you can try it. and reply me to tell if it really works as i think.
    Hope helps.
    Amao

  • Line separator to get multiple records in one variable

    Hi Experts,
    I have a requirement where i need to get data in the below form , in exactly one variable.
    Invoice No.       Inv. Date      Voucher   Gross Amount    TDS Amount     Discount    Paid Amount  
    986013092,17   04/08/2010    00091217   32415.00            .00                 .00          32415.00
    Bharti Infot      27/07/2010     00091230   19600.00            .00                 .00          19600.00
    9860442689    04/08/2010       001247     47374.00            .00                  .00         47374.00
    2031565000,2031565000Total Amount     99389.00             .00                  .00         99389.00
    As of now, I have written the following,
    loop at lt_merge into ls_merge.
      lv_skfbt  = ls_MERGE-SKFBT.
      lv_budat  = Ls_MERGE-budat.
      lv_wskto  = Ls_MERGE-wskto.
      lv_wrbtr  = Ls_MERGE-wrbtr.
      lv_WT_QBSHB = ls_merge-WT_QBSHB.
    concatenate invoice_id
                ls_merge-BELNR
                lv_BUDAT
                ls_merge-XBLNR
                lv_skfbt
                lv_wt_qbshb
                lv_WSKTO
                lv_wrbtr
    into invoice_id separated by space.
    endloop.
    which gives me one row of the table where, invoice_id stores my entire one record as a string. My question is how do I proceed with separating the lines if I have multiple records?
    Thanks in advance..
    Regards,
    Trishna

    HI
    choose some character that will be not use in your data for example '|' vertical separator. You will get string:
    invoice_id  = line1 | line2 | line3 |.....
    loop at lt_merge into ls_merge.
    lv_skfbt = ls_MERGE-SKFBT.
    lv_budat = Ls_MERGE-budat.
    lv_wskto = Ls_MERGE-wskto.
    lv_wrbtr = Ls_MERGE-wrbtr.
    lv_WT_QBSHB = ls_merge-WT_QBSHB.
    concatenate invoice_id
    ls_merge-BELNR
    lv_BUDAT
    ls_merge-XBLNR
    lv_skfbt
    lv_wt_qbshb
    lv_WSKTO
    lv_wrbtr
    into invoice_id separated by space.
    new code
    concatenate  invoice_id '|' into invoice_id
    endloop.

  • How to store multiple records for one master reocrd using sequnce

    dear,
    my question is in one form i have master block f and detail block.
    my question is i created one sequence and assign to master table. but i dont know how to assign that sequence to multiple record in detail table for that particular master record. i got lots of answer previously but i m not getting exactly.pls tell me full procedure otherwise gv me one demo application
    NOTe: the sequnce is created after master record commiting to database.
    PLS pls help me
    Thanks
    damby

    i did not get answer pls help me.

  • Self join to get related records in one row

    I have a table that has individual records for each family member.
    tPerson.LastName, tPerson.FirstName, tPerson.RelationshipCode, tPerson.FamilyUnitCode, tPerson.JobCode
    Smith, John,HD, 1234, AD
    Smith, Jill, SP, 1234, TC
    Olson, Fred, HD, 2345, AV
    Olson, Wilma, SP, 2345, MD
    Adams, Nate, HD, 3456, DP
    Adams, Heidi, SP, 3456, DP
    Franks, John, HD, 4567, AV
    Williams, Pauline, HD, 5678, TC
    I need to get each family unit in one row, preferably without a group on, for a report because I need to compare the jobcodes of HD and SP to decide how to build an expression for a listing. I need to also get singles with no spouse info.
    FamilyCode, Lastname, HDFirstName, SPFirstName, HDJobCode, SPJobCode
    1234, Smith, John, Jill, AD, TC
    2345, Olson, Fred, Wilma, AV, MD
    3456, Adams, Nate, Heidi, DP, DP
    4567, Franks, John, NULL, AV, NULL
    5678, Williams, Pauline, NULL, TC, NULL
    Does the type on constraint affect the effect of an inner join? I have trouble getting the left side returning rows where there is no SP records for that familyCode.
    Any help? John

    >> I have a table that has individual records [sic] for each family member. <<
    Rows are not records. And you posted no DDL.
    Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying
    temporal data. We need to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you need to read and download the PDF for:
    https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
    The sample data looks like it has a tibble on it. This is the classic design error of putting meta data, like a “t-” on tables and data element names. The next classic error you made
    is a table name that is singular and vague; do you really have only one “Person” in a table? According to ISO-11179 rules, that is what you said.
    >> I need to get each family unit in one row, ..<<
    Not in RDBMS. Please look up the term “1NF” or “First Normal Form” which forbids structure data in columns.
    But it just gets worse. Being in a family is a relationship, so it has its own table. The individuals are entities, so they have a table. Having a job is another relationship, so it is
    in a third table. In your world, all these things are crammed into a single table! This might be how an OO programmer would attempt to do RDBMS that first time, but it is not good. Here is skeleton to get your started: 
    CREATE TABLE Personnel
    (emp_id CHAR(9) NOT NULL PRIMARY KEY,
    last_name VARCHAR(20) NOT NULL,
    first_name VARCHAR(20) NOT NULL);
    CREATE TABLE Family_Units
    (family_unit CHAR(4) NOT NULL,
    relationship_code CHAR(5) NOT NULL
    CHECK (relationship_code IN ('spouse', ????)),
    PRIMARY KEY (family_unit, relationship_code),
    emp_id_1 CHAR(9) NOT NULL
    REFERENCES Personnel
    ON DELETE CASCADE,
    emp_id_2 CHAR(9) NOT NULL
    REFERENCES Personnel
    ON DELETE CASCADE,
    CHECK (emp_id_1 <> emp_id_2)
    CREATE TABLE Employment
    (emp_id_1 CHAR(9) NOT NULL
    REFERENCES Personnel
    ON DELETE CASCADE PRIMARY KEY,
    job_code CHAR(2) NOT NULL); -- do you know about DOT codes?
    See how we use DRI actions? Etc. 
    >> I need to compare the job_codes of HD and SP to decide how to build an expression [sic] for a listing. I need to also get singles with no spouse info. <<
    Expression return scalar values in SQL. You meant query. Where is the SQL you attempted? Is “spouse” the only relationship? 
    You have not posted enough information for anyone to really help you. What little we can extract from this says that you have no idea how about RDBMS. Want to do some reading, follow
    Netiquette and try again? 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • How to get multiple takes on one track?

    Using the latest version of GarageBand, how can I get multiple takes of a vocal, for example, on one track and then select the best one?

    See this support article:
    Record multiple takes:  http://help.apple.com/garageband/index.html#gbnda1184253

  • Multiple record in one row..

    Hi experts,
    I want to merge multiple row from same table into one row... is it possible? if so then how??
    Regards,
    SKP

    Sure, it's possible
    create table scott.a
    as
    select 1 a, 2 b from dual     
    union all
    select 3 a, 4 b from dual     
    create table scott.b
    (a number, b number, c number, d number)
    insert into scott.b
    select a1.a,a1.b,a2.a,a2.b from scott.a a1, scott.a a2
    where a1.a = 1 and a2.a = 3
    P.S. Sorry, at first misunderstood the task
    Message was edited by:
    Dmytro Dekhtyaryuk

  • How to get multiple records from internal table through BDC

    PERFORM DYNPRO USING:
      'X'  'SAPMM61L'  '0500',
      ' '  'BDC_OKCODE'  '=NEWC',
      'X'  'SAPMM61L'  '0500',
      ' '  'BDC_CURSOR'  'PLPTU-PLWRK(01)',
      ' '  'BDC_OKCODE'  '=TAKE',
      ' '  'PLPTU-PLWRK(01)' '2531'. (2531 is a plant)
    This is the recording used to get plant via BDC of MS31.
    Using this code i can get only single plant...
    If i want to get multiple plants from an internal table,how i can change this code?
    Since it is a recording i cant put this code in LOOP..ENDLOOP.
    Suggest any method for doing this....
    Awaiting for ur reply...

    Hi,
    While recording also record the scroll down button.
    The you can place different plant in the BDC using loop and endloop
    Regards
    Arun

  • Data merging: how to get multiple records in single text frame?

    Hi
    I'm experimenting with data merging in InDesign CS3. The biggest stumbling block I've come across is trying to get my records to flow as continuous text in a single text frame (which would, ideally, autoflow onto new pages in the document). The records vary considerably in length, and so I can't just create a standard text frame to repeat on the page.
    Perhaps data merging isn't the best way of doing this and I should be learning to script instead. I feel like I'm just one step away, though.
    Any suggestions would be appreciated.

    OK, new scenario now:
    Is it possible to set a text box to auto-resize to fit the content that comes in during the data merge?
    I have placed one of my data fields in a text box with a stroke and fill, and placed this as an anchored object in the main text box with the other fields. The problem is that the length of text in this field varies considerably, and I'd like the text to fit snugly within its box. Ideally this text box would not appear at all if the field is blank for a particular record.
    I hope I've explained all of that clearly enough. Any ideas?

  • How to get multiple photos as one clip in imovie?

    i have 13 school photos that i want to include in an imovie slideshow project. i wanted them to scroll from left to right, but can't seem to get them all in one clip. is there a way to do this? i found a way to do it by adding all 13 pictures into one photo using photobucket, but when i import that massive photo into imovie, it is such poor quality that it isn't worth it. please help. i'm going crazy over here.

    In that case, I have never done this before, but here is how I would approach it.
    In Photoshop, or similar app, I would create a photo that is 1080pixels high or bigger and wide enough to hold all pictures.
    I would place all photos in here and export as a single photo.
    In iMovie, I would set the image to Ken Burns, with the starting rectangle on the first photo, and the ending rectangle on the last photo.

  • Multiple records in one row

    Hi all,
    I want to display all the party codes which have same party name,
    and I want to display all the party codes in one row separated by comma. is it possible?

    You can either use analytic functions + hierarchy or stragg (listagg if you are on 11.2) or undocumentd wm_concat. There are plenty examples on this forum. For example:
    select  deptno,
            ltrim(sys_connect_by_path(job,','),',') job_list
      from  (
             select  deptno,
                     job,
                     row_number() over(partition by deptno order by job) rn
               from  emp
      where connect_by_isleaf = 1
      start with rn = 1
      connect by deptno = prior deptno
             and rn = prior rn + 1
        DEPTNO JOB_LIST
            10 CLERK,MANAGER,PRESIDENT
            20 ANALYST,ANALYST,CLERK,CLERK,MANAGER
            30 CLERK,MANAGER,SALESMAN,SALESMAN,SALESMAN,SALESMAN
    select  deptno,
            rtrim(stragg(job || ','),',') job_list
      from  emp
      group by deptno
        DEPTNO JOB_LIST
            10 MANAGER,PRESIDENT,CLERK
            20 CLERK,ANALYST,CLERK,ANALYST,MANAGER
            30 SALESMAN,MANAGER,SALESMAN,SALESMAN,CLERK,SALESMAN
    select  deptno,
            wm_concat(job) job_list
      from  emp
      group by deptno
        DEPTNO JOB_LIST
            10 MANAGER,PRESIDENT,CLERK
            20 CLERK,ANALYST,CLERK,ANALYST,MANAGER
            30 SALESMAN,MANAGER,SALESMAN,SALESMAN,CLERK,SALESMANSY.

  • How to insert some records in one table and some records in another table

    Interview question
    how insert records in two tables by using trigger
    CREATE or REPLACE TRIGGER Emp_Ins_Upd_Del_Trig
    BEFORE delete or insert or update on EMP
    FOR EACH ROW
    BEGIN
    if UPDATING then
    UPDATE emp2
    SET
    empno = :new.empno,
    ename = :new.ename
    --, job = :new.job
    --, mgr = :new.mgr
    --, hiredate = :new.hiredate
    , sal = :new.sal
    --, comm = :new.comm
    --, deptno = :new.deptno;
    sdate = :new.sdate,
    edate = :new.edate
    end if;
    if INSERTING then
    INSERT INTO emp2
    VALUES
    ( :new.empno
    , :new.ename
    --, :new.job
    --, :new.mgr
    --, :new.hiredate
    , :new.sal
    --, :new.comm
    --, :new.deptno
    new.sdate,
    new.edate);
    end if;
    if DELETING then
    DELETE FROM emp2
    WHERE empno = emp2.empno;
    end if;
    END;
    it is working fine but he wants to insert some specific litimit on one table and some specified limit of records in one ..
    In this senerio can i insert records by use count of records...
    please help me..

    Can you be more specific on the "Limit"
    Conditional insert can be used in this case.

Maybe you are looking for