View multiple lines of phone in the form of columns

Oracle 9i

I have the tables

visitors
ID name
__ ________________
1 John boy
Beautiful lady 2

Phone
Phone to cust
__ ___ ____________
1 1 555-555-5555
2 1 666-666-6666
3 2 222-222-2222
4 2 999-999-9999


I want to see
Customer telephone1 telephone2
__________ ___________ ____________
John Boy 555-555-5555 666-666-6666
Beautiful lady 222-222-2222 999-999-9999

I searched all morning, I can't find a simple way to do this (assuming there is one).

Published by: user6751911 on October 17, 2011 09:21

Published by: user6751911 on October 17, 2011 09:22

Hello

Welcome to the forum!

This is called a Pivot . Exactly how do depends on your version of Oracle and your needs (for example, the order of output on each line is important?)
See "how to convert lines to the columns" in the FAQ forum:
SQL and PL/SQL FAQ

Whenever you have a problem, please post CREATE TABLE and INSERT statements for some examples of data. Since this is your first post, I'll do it for you:

CREATE TABLE     customers
( id      NUMBER     PRIMARY KEY
, name       VARCHAR2 (10)
);

INSERT INTO customers (id, name) VALUES (1, 'John Boy');
INSERT INTO customers (id, name) VALUES (2, 'Lady Bele');

CREATE TABLE     phone
( id      NUMBER     PRIMARY KEY
, cust       NUMBER
, phone       VARCHAR2 (20)
);

INSERT INTO phone (id, cust, phone) VALUES (1, 1, '555-555-5555');
INSERT INTO phone (id, cust, phone) VALUES (2, 1, '666-666-6666');
INSERT INTO phone (id, cust, phone) VALUES (3, 2, '222-222-2222');
INSERT INTO phone (id, cust, phone) VALUES (4, 2, '999-999-9999');

This helps clarify what is exactly the problem, and it allows people to test their ideas.

Here's a way to rotate these data using Oracle 9:

WITH   got_r_num  AS
(
     SELECT     c.id
     ,     c.name
     ,     p.phone
     ,     ROW_NUMBER () OVER ( PARTITION BY  c.id
                               ORDER BY          p.phone
                             )        AS r_num
     FROM    customers  c
     JOIN     phone        p  ON  c.id  = p.cust
)
SELECT       name
,       MIN (CASE WHEN r_num = 1 THEN phone END)     AS phone1
,       MIN (CASE WHEN r_num = 2 THEN phone END)     AS phone2
FROM       got_r_num
GROUP BY  id, name
;

This also works in versions greater than 9, but from Oracle 11.1, you can use SELECT... Function PIVOT.

Output:

NAME       PHONE1               PHONE2
---------- -------------------- --------------------
John Boy   555-555-5555         666-666-6666
Lady Bele  222-222-2222         999-999-9999

This allows to display up to 2 phone numbers per client. If you have 3, then add

,       MIN (CASE WHEN r_num = 3 THEN phone END)     AS phone3

SELECT main clause. If you could have 4 numbers by cusotmner or 5, or any fixed number, continue to add columns as phone3 above to SELECT main clause.
If you don't know how amny phone numbers a customer might have, but that you want to view all the, then swivel can be difficult. See the thread below for some ideas on this subject:
Re: County report and the sum of the number of rows by multiple columns

Published by: Frank Kulash, October 17, 2011 12:40
Added example data and example

Tags: Database

Similar Questions

  • View multiple lines inside a loop

    Hi all

    I have a question.

    My table xx_test_table has 10 columns, 3 of which are status, error_message and request_id.

    Now, after some validations on querying the table with the request_id it gives 3 rows.

    I have to post this in a loop. The code I used is the following.

    BEGIN

    SELECT COUNT (*)

    IN lv_error_count

    OF xx_test_table

    WHERE request_id = 5920135;

    IF(lv_error_count > 0) THEN

    fnd_file. Put_line (fnd_file. OUT, 'xx_test_table error information Table');

    FOR lv_disp_data in 1... lv_error_count LOOP

    SELECT column_name,

    ERROR_MESSAGE,

    request_id,

    table-name

    BY lv_column_name,

    lv_error_message,

    lv_request_id,

    lv_table_name

    OF po_interface_errors

    WHERE request_id = lv_req_id;

    fnd_file. Put_line (fnd_file. OUT,' request ID: ' | lv_request_id);

    fnd_file. Put_line (fnd_file. OUT,' column name: ' | lv_column_name);

    fnd_file. Put_line (fnd_file. OUT, "Error Message: ' |" lv_error_message);

    fnd_file. Put_line (fnd_file. OUT,' the name of the Table: ' | lv_table_name);

    END LOOP;

    END IF;

    . This loop is inside a separate procedure and all the variables have been declared. Problem is when the API is run at the front end it illustrates TOO_MANY_ROWS exceptions to this procedure.

    Is there another way to display multiple lines of data in a table when we Select in the statement?

    This should make the necessary

    BEGIN
           SELECT COUNT(*)
             INTO lv_error_count
             FROM xx_test_table
            WHERE request_id = 5920135;
    
           IF(lv_error_count > 0) THEN
    
              fnd_file.PUT_LINE(fnd_file.OUTPUT,'Error Information from xx_test_table Table');
    
              FOR rec IN ( SELECT column_name,
                                  error_message,
                                  request_id,
                                  table_name
                             FROM po_interface_errors
                            WHERE request_id = lv_req_id
                         )
              LOOP
                   fnd_file.PUT_LINE(fnd_file.OUTPUT,'Request ID:    '||rec.column_name);
                   fnd_file.PUT_LINE(fnd_file.OUTPUT,'Column Name:   '||rec.error_message);
                   fnd_file.PUT_LINE(fnd_file.OUTPUT,'Error Message: '||rec.request_id);
                   fnd_file.PUT_LINE(fnd_file.OUTPUT,'Table Name:    '||rec.table_name);
              END LOOP;
           END IF;
    END;
    /
    

    Concerning

    Arun

  • Shapes and lines solid impression in the form of points?

    I have a 300 DPI CMYK document that prints nicely on my laser printer, with the exception of the forms.  The problem is that the shapes appear as a collection of points rather than a solid object.  Here is a scanned example:

    illustrator.jpg

    As you can see, the text prints as a solid once I change the contours of the Type\Create, but the simple rectangle does not have this option.  Even when I export the document to PDF and print from Acrobat, the problem still bears.  The problem does not occur for solid black forms.  (Even when I print on a color laser printer it persists)  The problem is not just linked to my printer - I presented the document to Vistaprint and they returned to a print job that had the same effect 'half-hearted' compromise colored dots the solid rectangle, I wanted.

    Could someone tell me which option I'm dominant? Thank you...

    You get what you ask - a composite print CMYK. This is normal and expected behavior. If you want to print a solid color, you will need to use spot colors, but those additional costs and I doubt that you can get to an online printing service not cheap & dirty, anyway. The only reason why he works in the black is because it is printed as black text, which is treated differently from the other colors. Yet once, there is nothing wrong here, you miss just a understanding of the entire process. Find out about all the theoretical stuff on four-color printing, ink, frames of midtones separation and everything what and how to properly manage colors in artificial intelligence to improve the quality of your production...

    Mylenium

  • Display the data in the form of column headers

    I am trying to achieve in Apex 4.2

    My table is like (example)

    Identification number

    date of date_a

    value_1 number

    Value_2 number

    Value_2 number

    I have my sql like

    SELECT id, date_a, value_1, value_2, value_3

    from my_table

    If the report displays in the form

    ID date_a value_1 value_2 value_3

    1 01/01/2012 10 20 30

    15/03/2012 2 12 14 24

    Can anyone show me an example of how to create such a report

    01/01/2012-15/03/2012

    1                           2

    10                        12

    20                        14

    30                         24

    I took a look at pivot, but doesn't seem to be the thing

    See you soon

    Gus

    Gus,

    First of all you must understand SQL itself cannot change the names of the columns for a query, as Frank has said.

    Columns in a SQL query are the 'projection' and the number of columns, the names of them and the data types must be determined before all data are extracted.

    See the following article: 101 PL/SQL: cursors and Projection of SQL

    Apex is simply based on the queries that you write, and even there not magically be able to change the names of columns in report based on your data.

    This is not to say what you want is impossible... it's possible... but not easily...

    See: how a function having a dynamic number of columns in the pipeline?

    Essentially the data itself have be questioned or known, before the data is retrieved, so that requires only the generated columns dynamically based on known data (for example, the criteria entered by a user) or you can do a query of two passes... questioning the data only once to get the values and then dynamically generating a second query to extract data with dynamically generated column headers.

    In the Apex of reports you will usually have the problem report attributes are defined as part of the update and are determined when the query is assigned to the report (that you can manually override the headers)... but the apex will not allow lines dynamically the changes based on the data, for standard reports, it allows.  I have not tried to do in the Apex, but you can maybe try and generate the report results using a two-pass method, to put in an HTML region, but it depends on what user interaction is required with the report, that you far built-in report functions.

  • view multiple lines in the advanced table

    Hi all

    I have a requirement. I created advancedtable. When the page loads, to display 4 rows at a time. Can anyone please help how to achieve this req

    Kind regards
    Murali

    Hello

    Write the code below in AM that will create 5 blank lines in the advanced table.

    xxVOImpl voImpl = getxxLineVO1();
    voImpl.setWhereClause ("1 = 2");
    voImpl.executeQuery ();
    for (int i = 1; i)<=5>
    {
    Line = voImpl.createRow ();
    voImpl.insertRow (row);
    row.setNewRowState (Row.STATUS_INITIALIZED);
    row.setAttribute ("column1", i);
    row.setAttribute ("column2", "XYZ");
    }

    Kind regards
    Mary

  • Execution of multiple lines of command at the command prompt (windows)

    Hello

    I'm vascular using the command prompt in the windows to try to send a command to the microcontroller that is connected through TCP connection.

    I am able to use the normal cmd.exe to send the command but I am unable to send the command all successfully using labview.

    The Vi. I use the exec.vi system found in the labview connectivity section.

    Basically, I want to send is 'telnet A1' motion in the cmd.exe to establish a connection to the microcontroller, followed by "For A1 100 GO," which will be performed by the microcontroller to do what is necessary. But currently, the problem is that I can only establish a connection using the exec.vi system but can't send the second part of the message 'for A1 100 GB".

    My command line, I tried typing is cme.exe /K telnet A1 & for A1 100 GB. It seems that labview is only able to run the first part of the command. Y at - there no alternatives?

    Thank you for all your help.

    I suspect that there are problems of synchronization with this code. Forst, you should clean it to the top because it is very difficult to follow. Cables are hidden under objects, this is a lot bigger than a view type and the code is usually very disorganized. I also suggest that you look at using a state machine, but also a structure of the event to intercept the user interface events such as the Start button.

  • Is it really true that I can't view file creation date and time in the form of column bin?

    I need to sort my material by the date and time of creation of the file.

    It seems that this basic metadata more are missing in Premiere Pro

    I hope someone can point to my error here - otherwise, it's a MAJOR FAILURE by Adobe. Surely, after file name, it is the most "basic" bit of METADATA required from a file.

    Otherwise there is no solution workaround, other than the batch renaming clips at the finder level. (I tried the tags and comments at the research level, but can't seem to access it either)

    Hi Jim,.

    Unfortunately, even when these data are present for the clips, the ability to sort by these data is broken.

    It caused a lot of performance issues, then Yes, that it has been disabled.

    and they still haven't fixed yet.

    This is fixed in the next version. However, you must add the columns in the display of the metadata.

    Thank you

    Kevin

  • How to display Page also in the form of columns of report items?

    It seems that as soon as I do a column report a page element, and then disappears in the columns on the report. I want that page elements considered as well report columns. Is this possible in discoverer?

    Create a calculated item based on the item record. This effectively shows the column twice, once as part of page and then as a column.

  • Submitting a form by creating multiple lines in the DB table

    Hi all

    I created a new Apex application and have created a table with columns - USER_ID, ADDRESS, TELEPHONE, CREATEDON etc.

    I want to read the USER_ID of the user and complete this field on the form and fill in the CREATEDON field with the date system. These two fields are hidden on the form.

    Now, when the user fills his address and phone on the form and click on send, 3 identical rows are inserted into the DB table. The values of user and date system are set correctly.

    To set the UserID field, I inserted a $APP_USER. in the default value of the form section. I am not able to understand why the Apex is to insert several lines even when you click the submit button once.

    Help, please.

    The problem is solved now. I noticed that add default values for the form fields added process duplicate. That's why the form has been processed three times. Remove the additional process solved the problem.

  • Display multiple lines of data collection defined by the user in an e-mail message

    I created a collection defined by the user that displays several lines of data. I created a custom rule and have linked this collection set by the user to this rule and configure an e-mail action. Variable Seveity, I have defined it in the rule to contain the column values. But it will only contain the first line of data. How can I display multiple lines of data in the alarm itself as well as the e-mail? Any help is appreciated.

    The example query in the collection defined by the user is less;

    Select the type, status, queuename, count (*) from PSAPMSGPUBHDR

    Union

    Select the type, status, queuename, count (*) from PSAPMSGPUBCON

    Union

    Select the type, status, queuename, count (*) from PSAPMSGSUBCON

    Result:

    Number of status type Queuename

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

    HDR profil_utilisateur error 1

    PUB                  PERSON_BASIC                    New                                 4

    PUB WORKFORCE_SYNC error 1

    -3 rows

    I have defined the variables of gravity and the alarm message is something like this; (It is fetching only the first row of data) how do I loop through to get all the rows of data and display it in the message of alarm/email (alert) action must be written of the groovy script code to achieve this goal? If Yes can you please provide me examples?

    Alarm message:

    "Request message queue is:

    Type: @UDC_type

    QueueName: @UDC_queuename

    Status: @UDC_status

    County: @UDC_count

    Thanks in advance

    JAI

    Hi Jay,.

    fine I could help you. Please mark the thread as "Answered" when the issue has been resolved and do not hesitate to open a new thread for questions.

    Concerning

    Jochen

  • Coverting a line in the values in columns

    Hi friends Expert SQL,

    I have a line that contains 6 columns where I want the data to appear in the form of columns, as shown here:

    From:

    Select item1, item2, item3, amt1, amt2, amt3 in item_table, when sno = 1; <-returns 1 row as below

    ITEM1 ITEM2 ITEM3 AMT1 AMT2 AMT3
    ---------- ------------ ------------- ----------- ------------ ----------
    AAA BBB CCC 10,00 20,00 15,00


    Explanation of data: item1 (AAA) price is amt1 (10.00), item2 (BBB) price is amt2 (20 h 00) and item3 (CCC) price is amt3 (15.00). Ok.

    Now I want that data to be converted to columns, as shown here:

    TO:

    AMT ELEMENTS
    --------- ---------
    AAA 10.00
    BBB 20.00
    CCC 30.00


    Please help me guys, I want a SQL to display these data.

    I found a single query that converts a row of columns, but this is not my requirement: [for your reference only]

    SQL > select substr (the_string
    , decode (level, 1, 1, instr(the_string,',',1,level-1) + 1)
    , decode (instr(the_string,',',1,level), 0, length (the_string), instr(the_string,',',1,level) - decode (level, 1, 0, instr(the_string,',',1,level-1))-1)
    ) the_value
    from (select (select item1 |)) «, » || Item2. «, » || Item3 item_table where sno = 1) ELEMENTS
    the double)
    connect by level < = length (the_string) - length (replace(the_string,',')) + 1


    Thank you and best regards,
    Kiran
    WITH pivot_data
         AS (SELECT 'AAA' ITEM1,
                    'BBB' ITEM2,
                    'CCC' ITEM3,
                    '10.0' AMT1,
                    '20.0' AMT2,
                    '15.00' AMT3
               FROM DUAL)
    SELECT t1.items, t.amount
      FROM (SELECT NULL items, amount, ROWNUM rn
              FROM pivot_data UNPIVOT INCLUDE NULLS (amount
                              FOR items
                              IN (AMT1, AMT2, AMT3) )) t,
           (SELECT items, NULL amount, ROWNUM rn
              FROM pivot_data UNPIVOT INCLUDE NULLS (items
                              FOR amount
                              IN (ITEM1, ITEM2, ITEM3))) t1
     WHERE t.rn = t1.rn
    
    ITEMS     AMOUNT
    AAA     10.0
    BBB     20.0
    CCC     15.00
    
  • How to position the title of the form on the second page of the form sank

    Good day all.

    Well, I think I'm getting a little understanding of how to create forms.

    What I have is a form that "could" extend over several pages. That's what I have.

    The form has 4 sections that are able to expand as text is entered or additional lines are added.

    On the 'master' page, I placed the form "title". When I added the 'title' to 'master' page, he put the title in the right place on the first page. When I added lines as well as the form would extend 2 pages, the 'title' was in the right place, but the added line was placed above the 'title '.

    I added forms as well as the 'title' to the master page with the same result. I think there must be a way to add the title to the second pages (or more) without going through the addition of text replace the title.

    Thank you all

    Chomp

    The master page has a content area (the purple dotted line). This is the area where content will be placed on normal pages. If you place the

    Title outside of the content area, then you won't have an overflow condition.

    Paul

  • rows in the bi publisher columns

    How convert the lines into columns in bi publisher, I have ministries of the column, I want to display each Department in the form of columns, for example:

    Table1:

    now, it displays as:

    Resource Department role

    ____   ________     __________

    Role1 resource1 ministere1

    Role2 resource2 department2

    3 resource3 ministere3

    I want to display it like this:

    Role Resource ministere1 ministere3 department2

    ____   ________     __________     ___________    ___________

    Role1 resource1 *.

    Role2 resource2 *.

    role3   resource3                                                           *


    and how to do it, if I don't know the number of departments


    IM finding the solution, install oracle bi publisher desktop and that is all.

  • Calculate the % with the pivot table columns

    I created an application with these columns:
    Metric       Study          Fast          Slow       On-Target     Total
    ---------------------------------------------------------------------------------
    Metric1     Study1           1             0              0             1
    Metric1     Study2           1             0              0             1
    Metric1     Study3           0             0              1             1
    Metric1     Study4           0             0              1             1
    Metric1     Study5           0             1              0             1
    Metric1     Study6           0             1              0             1
    Metric1     Study7           0             0              1             1
    Metric1     Study8           0             0              1             1
    Metric1     Study9           1             0              0             1
    Metric1     Study10          1             0              0             1
    I want to create a pivot table looks like this.
    Metric          Fast     Slow      On-Target     Total      % Fast     % Slow   % On Target
    ------------------------------------------------------------------------------------------------------
    Metric1         4           2        4            10           40        20       40
    The fast, slow, on the target and Total columns are calculated fields. Picky, I'm having is to get the % columns to work. I also tried create columns % in the form of columns of the table, but at each level of study, the % is 100% or 0%.

    I tried with duplicate columns, all different options to display the value as. None of them worked.

    Could someone help me? The version of the OBI is 10.1.3.4

    Thank you

    Shi-ning

    Published by: SPUD on November 21, 2011 23:09

    Sounds like it. You will need the account of studies as a measure in the criteria. You could do something in the repository, but the fastest way is:

    Criteria:
    Add the study in (it will not go into the PivotTable)
    create new measure based on any existing measure that has the background you need with the formula:
    cases where [existing] is not null then 1 else 0 end

    This will give you 1 for each line that your measure in effect is valid. Add this new measure in the PivotTable and treat it as a normal amount.

  • The BLOB (image) column in the report (interactive)

    Hello

    I have a field called "image" in my "details" table, which is of type BLOB. I also have a field 'MIME Type' and 'filename '.

    In addition, I have a "name" and "description" column I need to display with the image in the form of columns in a report (interactive preference).

    I also modified the display BLOB format as per

    http://www.Oracle.com/WebFolder/technetwork/tutorials/OBE/DB/Apex/R31/apex31nf/apex31blob.htm

    what Miss me is the correct query. If possible, I want to control the size of the rendered image in the report as saying 40 * 50.

    I also mentioned the thread

    APEX 3.1 BLOB Image display

    But I do not know how to place the

    DBMS_LOB. GetLength ("BLOB_CONTENT") as "BLOB_CONTENT".

    in my query.

    The foregoing allows also the report type column 'number Should it?

    Any help would be appreciated.

    Kind regards
    Rigaut

    so I am very confused if the error is in the report or the table/data type definition itself.

    Or {noformat}) {noformat}

    The problem is in the settings of the P4_PICTURE element in the form on page 4. The Type of storage has been upgraded with WWV_FLOW_FILES of the Table, so the uploaded images were going to the repository of integrated files, not the BLOB on your CATEGORY table column. So the fundamental problem is that there are no images in your table to be included in the report.

    I changed the element P4_PICTURE Type of storage to a BLOB column specified in the attribute of the Source element, has added the additional column information and the IMAGESource and changed column PHOTO report 3 Format page mask download image, and the picture I have uploaded via the updated form the appears.

Maybe you are looking for

  • Webmail

    I use firefox 3.6.13 on win 7 OS installed on VAIO.Once I'm done done vaio updated, my firefox does not display properly in some example Web site: massage of facebook (does not display the massage), Flickr (not well ordered) and my webmail in gmail h

  • HP laptop G72: no sound on the tv when streaming movies, videos, etc.

    Audio works on my HP laptop, but when I stream from the internet there is no sound coming through my TV with HDMI connection.

  • list of directories of arm

    Hello I work in an evaluation committee lm3s8962 trying to datalog some data and I came up with a problem when I want to recover these data. "The list directory" does not work, I enclose the file vi witch that I tried to get the directory from the li

  • Lost everything in the Inbox in Outlook Express

    Everything in my Inbox disappeared!  I think I may have accidentally said 'yes' to the archive of my old Articles, thinking I compress files, and I don't know where to find the archives.  I have an old Dell with Windows XP and MS Office 2003.

  • I still need help with a thumbnail view in video files Real Player XP sp 3

    I still need help with thumbnail view in video files Real Player XP sp 3-Help! Help! Help!