change the view in oracle

Hello all;

I have an interesting problem

I have the following code
create table table_A 
(
      ID varchar2(200),
      qty number(6)
);

insert into table_a
  (id, qty)
values
  ('A', 10);

insert into table_a
  (id, qty)
values
  ('B', 6);

create table table_B 
(
      ID varchar2(200),
      colour varchar2(200)
);
insert into table_b
  (id, colour)
values
  ('A', 'Red');
insert into table_b
  (id, colour)
values
  ('B', 'Black');

create table table_info
(
       ID varchar2(200),
       addr varchar2(1000)
);

insert into table_info
  (id, addr)
values
  ('A', '2034 James Street');

insert into table_info
  (id, addr)
values
  ('B', '2044 Main Street');
and I use a selection similar to this
select g.id, g.qty, h.colour from table_A g, table_B h
where g.id = h.id
gives me the following display below
ID     QTY    COLOUR
A       10      Red
B         6      Black
now, I would like to change the display so that I can get this rather
ID       Addr
A        '2034 James Street'
ID       QTY       Colour
A          10         Red
ID      Addr
B       '2044 Main Street'
ID      QTY        Colour
B         6           Black
Any help is appreciated. Thank you.

Hello

Here's one way:

WITH     union_data  AS
(
     SELECT    g1.id
     ,       TO_CHAR (g1.qty)     AS column_2
     ,       h1.colour
     ,       g1.id               AS sort_id
     ,       2               AS sort_line
     FROM        table_A      g1
     ,       table_B      h1
     WHERE       g1.id            = h1.id
                   --
         UNION ALL
               --
     SELECT       'ID'               AS id
     ,       'QTY'               AS column_2
     ,       'Colour'          AS colour
     ,       g2.id               AS sort_id
     ,       1               AS sort_line
     FROM        table_A      g2
     ,       table_B      h2
     WHERE       g2.id            = h2.id
                   --
         UNION ALL
               --
        SELECT    t1.id
     ,       t1.addr          AS column_2
     ,       NULL               AS colour
     ,       t1.id               AS sort_id
     ,       0               AS sort_line
     FROM       table_info   t1
                   --
         UNION ALL
               --
        SELECT    'ID'               AS id
     ,       'Addr'          AS column_2
     ,       NULL               AS colour
     ,       t2.id               AS sort_id
     ,       -1               AS sort_line
     FROM       table_info   t2
)
SELECT       id, column_2, colour
FROM       union_data
ORDER BY  sort_id
,            sort_line
;

Here's how it works:

You already know how to get the output lines containing the values of the quantity and color.
You can generate a header line for each of these lines, which owns the labels 'ID', 'Quantity' and 'COLOR', and do a UNION to combine the results.

SELECT    g.id
,       TO_CHAR (g.qty)     AS qty
,       h.colour
FROM        table_A      g
,       table_B      h
WHERE       g.id            = h.id
                   --
    UNION ALL
               --
SELECT       'ID'
,       'QTY'
,       'Colour'
FROM        table_A      g
,       table_B      h
WHERE       g.id            = h.id
;

Output:

ID         QTY        COLOUR
---------- ---------- ----------
A          10         Red
B          6          Black
ID         QTY        Colour
ID         QTY        Colour

The problem with the above output is the header lines should be intertwined with data lines, firstly a header, and the data accompanying it. To do this, we can add additional columns to each branch of the UNION that are just for sorting:

SELECT    g1.id
,       TO_CHAR (g1.qty)     AS qty
,       h1.colour
,       g1.id               AS sort_id
,       1               AS sort_line
FROM        table_A      g1
,       table_B      h1
WHERE       g1.id            = h1.id
                   --
    UNION ALL
               --
SELECT       'ID'               AS id
,       'QTY'               AS qty
,       'Colour'          AS colour
,       g2.id               AS sort_id
,       2               AS sort_line
FROM        table_A      g2
,       table_B      h2
WHERE       g2.id            = h2.id
                   --
ORDER BY  sort_id
,            sort_line
;

Output:

ID         QTY        COLOUR     SORT_ID     SORT_LINE
---------- ---------- ---------- ---------- ----------
A          10         Red        A                   1
ID         QTY        Colour     A                   2
B          6          Black      B                   1
ID         QTY        Colour     B                   2

Who has solved a problem but created another. We do not want to see the columns sort_id and sort_line; We just want to use in the ORDER BY clause. However, in a UNION you CN can't ORDER BY anything which is not in the SELECT clause. Depending on your front end, you may be able to hide columns (in SQL * Plus, for example, you can say "COLUMN sort_id NOPRINT"), but here's how you can work around the problem in SQL pure, by the UNION in a separate subquery of the ORDER OF:

WITH     union_data  AS
(
     SELECT    g1.id
     ,       TO_CHAR (g1.qty)     AS qty
     ,       h1.colour
     ,       g1.id               AS sort_id
     ,       2               AS sort_line
     FROM        table_A      g1
     ,       table_B      h1
     WHERE       g1.id            = h1.id
                   --
         UNION ALL
               --
     SELECT       'ID'               AS id
     ,       'QTY'               AS qty
     ,       'Colour'          AS colour
     ,       g2.id               AS sort_id
     ,       1               AS sort_line
     FROM        table_A      g2
     ,       table_B      h2
     WHERE       g2.id            = h2.id
)
SELECT       id, qty, colour
FROM       union_data
ORDER BY  sort_id
,            sort_line
;

Output:

ID         QTY        COLOUR
---------- ---------- ----------
ID         QTY        Colour
A          10         Red
ID         QTY        Colour
B          6          Black

It's perfect for the table_a table_b data. To get the data of table_info thus, simply add 2 branches in addition to the UNION, as indicated at the beginning of this message.

It's a bit pointless to do 2 separate petitions, one to get the data and the other to get the header, when these 2 queries use the same tables and the same WHERE clause. An alternative is to cross join table to another table (or, more likely, a game of operation in the form of table of results), which has the values n = 1 and n = 2 and use CASE expressions to display data or its header. I'll leave that as an exercise for the reader.

Published by: Frank Kulash, January 18, 2011 13:02
Explanation added.

Tags: Database

Similar Questions

  • Change the view with email list on the left, not from list above and the content of the email below.

    I like my emails showing up with a list of emails to the left of the screen and the content of the e-mail to the right of the screen, which is how I got it in the old outlook program, I have used. Can someone tell me how to change the view, it looks like this?

    View (Alt + V) menu > Presentation > vertical display

  • Continue to change the views of folders under Vista

    Windows Vista has a tendency of capricciously changing the settings "Folder views" (tiles to details, etc.) and even delete the column headings used to "group by". Is there a solution? Is fixed in Vista 7?

    NEVER use a registry cleaner no matter what the case - Vista does a great job on its own and, most registry cleaners do nothing useful (even if the analysis indicates that it is 5999 errors that must be repaired and can be repaired if ypu buy program) or can do much harm (to the point where the only option is a clean install of the operating system).  There is not a single registry cleaner I can recommend (and there are probably hundreds of them out there).  IMHO, for Vista registry cleaners are a scam (and a dangerous one at that).

    You can change the views of files according to your needs (you have only 5 choices if you change the default templates - well you can always choose only 5, but the choice may be more in your order).  This is true regardless of the type of files contained in the files (once you change models, although the model chosen will depend on the type of file).

    Here's how to change the default template for a folder: http://www.vistax64.com/tutorials/70819-windows-explorer-folder-view-settings.html.  Default behavior is to select the model based on the first type of file placed in the folder (you must choose something).  Vista sets the folder type template according to what are the types of files in the window and the settings display window Explorer. This will show how to reset the display settings for the Windows File Explorer, disable Automatic folder Type Discovery (which is I think what you want)and increase the folder display the cache to make Vista do not forget the display settings, the folder type template, the size or the position of a specific window for when it was still closed to the location of specific path.

    It does not work with the Sub record under, Open with, open in a new tab (Internet Explorer), etc... dialog windows of type through the good File menu bar item. These don't seem to be able to have their size or their position to recall. For the latter, you can use the free program AutoSizer to resize them.

    Here is another article on how to modify the columns in Windows Explorer and sort in Vista: http://www.vistax64.com/tutorials/108665-column-customize.html.  This will show you how Add, Remove, move, change the widthand change the sort order of the columns in Windows Explorer in the way that you want.

    Here is another article on how to change the display of the default folders in Vista (but she argues, it is not a perfect solution and can revert to the previous behavior is not as good as the two prior links provided: http://news.cnet.com/8301-13880_3-10019957-68.html.)

    I hope this helps in your situation.

    Good luck!

    Lorien - a - MCSE/MCSA/network + / A +.

  • How to use the Explorer under Vista? Like in XP, I was able to change the 'view' of all the files that have been hidden.

    I want to change the view and see all the files.  Reason is to move files from one hard disk to another instead of doing the method of file transfer.

    Go to start / Control Panel / folder Options / view and scroll down and check the box to show the hidden files and folders.  In addition, uncheck to hide system files. In addition, uncheck to hide extensions of known file types (the last because it can be useful and worth while you're brings other changes).  Your problem should be solved.

    I hope this helps.

    Good luck!

    Lorien - MCSA/MCSE/network + / has + - if this post solves your problem, please click the 'Mark as answer' or 'Useful' button at the top of this message. Marking a post as answer, or relatively useful, you help others find the answer more quickly.

  • How can I change the view of drag in folders?

    * Original title: when dragging file icon

    I use windows 8. When I drag a Doc file in windows Explorer, I see a box with a big o in there. This obscures the folder in which I am trying to drag the file. How can I change the view of slide simply holds of a simple place (empty)?

    Hi Jim,.

    Thank you for your response.

    You will see the large icon of the file when you drag it is by design. It cannot be changed.

    Feel free to post your query if you have other issues with Windows in the future.

  • What is this error represents "another user has changed the line containing oracle.jbo.Key [21 primary key]."

    Mr President.

    What is this error represents "another user has changed the line containing oracle.jbo.Key [21 primary key]."

    Concerning

    You get this exception quite often when you have a business in PL SQL layer, but you can safely ignore (suppress) it by substituting the lock() method in all implementation of your entity classes.

    /*** customizing locking management: 
    * Because attribute values can change 'outside' ADF standard life cycle, 
    * when optimistic locking executes, the exception "Another User Changed the Row" is thrown. 
    * In this case, we execute locking again, ignoring the exception 
    */ 
    public void lock() 
    { 
     try 
     { 
      super.lock(); 
     } catch (oracle.jbo.RowInconsistentException e) 
     { 
      if (e.getErrorCode().equals("25014")) 
      { 
      super.lock(); 
      } 
      else throw e; 
     } 
    }
    
  • to change the password of oracle 11 g R2 RAC

    Hello
    I need to change the password or oracle. in a thread, it is already listed there be no effect to the environment of FCAC
    I agree to that, but I fear for ssh we need to reconfigure it or any what steps for ssh to manage the new oracle user password? Please guide me for the same thing.
    Thanks in advance

    Hello

    I agree to that, but I fear for ssh we need to reconfigure it or any what steps for ssh to manage the new oracle user password? Please guide me for the same thing.

    You can change your password of user oracle (sagna), no impact on ssh, SSH does not use the password of the user oracle (sagna).
    SHH information are based on hash keys and the password for SSH (own), not password of the Oracle user's operating system.

    If you have a ssh problem. Visit the link below.

    http://levipereira.WordPress.com/2010/12/07/configure-SSH-for-user-equivalence/

    Kind regards
    Levi Pereira
    Please close your message when you get the solution to your problem.

    Mark responses replied 'useful' response or 'correct' answer which will help others with the same problem.

    Thank you for doing your part to make this community as valuable as possible for everyone!

  • OA Framework page customization - how to change the view Instance

    OA Framework page customization - how to change the view Instance

    Hello
    I have to add extra field to a page.
    View instance, I found, but there is no attribute that I need.

    Is it possible to change the Instance from the view of the application level
    because you use only not JDeveloper?

    Thank you
    Malin

    Hi smart,

    If your VO does not include the column you are looking for, then the only way to achieve is through substitution of VO for which you use jdeveloper.
    You can't accomplish by customizing.

    Thank you
    Sree

  • Why do I not change the view when I open a folder?

    I am running Windows 7 on a laptop Gateway/Acer. My main question has different views of files and folders every time I open a new folder. It may appear as a list of small icons, etc. I remember that I could change the settings in the control panel in XP and Vista, and all records have the same point of view. What should I do on Windows 7?

    I'm also a terrible with startup items and know time if they are needed or not. I KNOW I have too much processes running and they use to the top of my RAM. This problem is my computer very slow. Even the elements that I spent in and saw that they have a "manual" startup, still seem start-up by themselves. I KNOW by looking at the processes and services and to put an end to or of them changing from automatic to manual. I don't know what to change (the descriptions make it all seems crucial), more the same manual start!

    Finally, I am confused with there online backup. The icloud, cloud, pc-cloud, etc. I've been a backup on my external hard drive, but it is full. I think I probably have things stored on at least 5 different clouds online, but would also even if I had an accident and had to reformat my hard drive?

    I thank very you much for your time and attention to my many questions. I've saved the top for a while!
    Laura

    One-way ticket, open a window in the Explorer and set the display as you want. Then in the menu bar click on Options of Tools\Folder, then click on apply to records. This should create all the folders as you want.  Can also go to control Panel\Folder Options\View and do the same thing.

  • How can I change the characters in Oracle 11 GR 2 Express AL32UTF8 to UTF - 8 (OS: Windows2008R2) is currently the NLS_CHARACTERSET setting = AL32UTF8 and NLS_NCHAR_CHARACTERSET = AL16UTF16?

    I installed Oracle Express 11 GR 2 software that created the database of the parameter "NLS_CHARACTERSET" AL32UTF8 and NLS_NCHAR_CHARACTERSET AL16UTF16 value XE.

    This database must be used with a character encoding application which usues UTF8 and requires database Oracle support UTF8.

    I need to change the setting of NLS_CHARACTERSET and NLS_NCHAR_CHARACTERSET parameters to comply with the requirement of the application?

    If yes how to change these settings to support UTF8?

    Thank you very much, Sergiusz.

    That's pretty conclusive. I confirm this also with the seller.

    Dziekuje bardzo.

  • Hi, just upgraded to the CD player. How can I change the view pagewidth to view full page?

    Hi, just upgraded to the CD player. How can I change the width of page in design mode full page?

    Hi Paul,.

    Launch the player, click on View-> Zoom and select the preferred mode. You can also select the mode full screen by pressing Ctrl + L on the keyboard.

    ~ Deepak

  • Change the view hosts ESXi and Vcenter Ip addresses

    Hello

    Because of our new zoning, we need to change the IP addresses of all our guests view ESXi as well as our vCenter server View.  Is it still possible without altering the DB ADAM that uses the view?

    Thank you

    Mooge

    If your ESX hosts are added to vCenter by host name and your vCenter are added to the view by hostname that you should be able to make this change without affecting the view.

    If your vCenter is added by IP, then you will have problems.

    If your ESX hosts are added by the intellectual property so that you can use maintenance mode to migrate all the virtual machines on each host, remove from the inventory, then add it to the cluster using the new IP or host name. View should have no problem with what we don't reference the hosts by their host names in any sort of statically.

    -Mike

  • Change the view office networks

    I'm changing my view office network, i.e. taking them out of the Nexux 1KV and put back them on the standard switch.  It seems that I can't change the image of «replica...» ».  Do I need to recompose the workstations?

    It's graceful in my opinion, maybe a powershell script to change via the network on the clones, until you're ready to recompose.

  • Change the views of business Finder

    Hello

    I wonder if we can change views business discoverer to add additional fields to the view. In particular, I need gl_date table ap_invoices, but it is not available in the view invoices apfg. Can I change this view to include this column? What are the future complications, if we do?

    Thank you.

    Hello
    You can refresh the view and then refresh the folder in the admin, but if you upgrade one day or regenerate views then you probabely will seek for this missing element.
    Another way to get the same result is to create a function that will return the gl_date to the AP, and then save it in the EUL
    and create an element calculated in the folder using this feature.
    User, they will now have the gl_date of AP and you change the display side (-):

    Tamir

  • Quick and easy way to change the SID of ORACLE EBS

    Hello

    I was wondering if it is somehow fast and quick change SID of Oracle EBS databases and Application layer?

    9i database
    EBS 11.5.x
    OS = Unix flavor (Redhat Linux / AIX)

    Thank you

    981553 wrote:
    Hello

    I was wondering if there anyway quick and fast change SID of Oracle EBS on two layer of database & Application?

    9i database
    EBS 11.5.x
    OS = Unix flavor (Redhat Linux / AIX)

    Thank you

    The way simplest would be using quick Clone - run preclone on the database/application, stop the application/database, run post clone on demand database and change the SID.

    Documentation fund quick Clone version 11i and 12 [799735.1 ID]
    Cloning Oracle Applications Release 11i with rapid Clone [ID 230672.1]

    Thank you
    Hussein

Maybe you are looking for