Concatentate and pivot data

Oracle 11g Release 2

I have three tables: file_data, notes and comments. One-to-many relationship exists between file_data and the other two tables.

The primary keys for all tables: file_id and record_id.

I need to rotate the notes.notes and comments.comment_txt and then concatenate them into a single string.

Here is the configuration:

create table file_data
( file_id   number
,record_id number
,rec_txt   varchar2(255)
)
/


insert into file_data values(1,1,'yadda')
/
insert into file_data values(1,2,'nadda')
/
insert into file_data values(1,3,'badda')
/
insert into file_data values(1,4,'sadda')
/
insert into file_data values(1,5,'padda')
/


create table notes
( file_id   number
,record_id number
,note   varchar2(255)
)
/


insert into notes values(1,1,'note1')
/
insert into notes values(1,2,'note2a')
/
insert into notes values(1,2,'note2b')
/
insert into notes values(1,2,'note2c')
/
insert into notes values(1,3,'note3')
/
insert into notes values(1,4,'note4')
/
insert into notes values(1,5,'note5')
/


create table comments
( file_id   number
,record_id number
,comment_txt   varchar2(255)
)
/


insert into comments values(1,1,'comment')
/
insert into comments values(1,2,'comment2a')
/
insert into comments values(1,2,'comment2b')
/
insert into comments values(1,3,'comment')
/
insert into comments values(1,4,'comment')
/
insert into comments values(1,5,'comment')
/


commit;


col rec_txt for a10
col note for a10
col comment_txt for a11


select f.file_id, f.record_id, f.rec_txt,n.note,c.comment_txt
from   file_data f, notes n, comments c
where  f.file_id = 1
and    f.file_id = n.file_id
and    f.record_id = n.record_id
and    f.file_id = c.file_id
and    f.record_id = c.record_id ;


   FILE_ID  RECORD_ID REC_TXT    NOTE       COMMENT_TXT
---------- ---------- ---------- ---------- -----------
         1          1 yadda      note1      comment
         1          2 nadda      note2a     comment2b
         1          2 nadda      note2a     comment2a
         1          2 nadda      note2b     comment2b
         1          2 nadda      note2b     comment2a
         1          2 nadda      note2c     comment2b
         1          2 nadda      note2c     comment2a
         1          3 badda      note3      comment
         1          4 sadda      note4      comment
         1          5 padda      note5      comment

This is the desired result:

   FILE_ID  RECORD_ID REC_TXT    NOTE_COMMENT
---------- ---------- ---------- ---------------------
         1          1 yadda      NOTE1COMMENT
         1          2 nadda      NOTE2ACOMMENT2BNOTE2ACOMMENT2ANOTE2BCOMMENT2BNOTE2BCOMMENT2ANOTE2CCOMMENT2BNOTE2CCOMMENT2A
         1          3 badda      NOTE3COMMENT
         1          4 sadda      NOTE4COMMENT
         1          5 padda      NOTE5COMMENT

The final output should be cut and uppercase. The solution can be SQL or PL/SQL. Any thoughts on how to achieve this?

Select f.file_id,

f.record_id,

f.rec_txt,

listagg(n.note || c.comment_txt) Group (control 1) note_comment

of file_data f.

n notes

c comments

where f.file_id = 1

and f.file_id = n.file_id

and f.record_id = n.record_id

and f.file_id = c.file_id

and f.record_id = c.record_id

F.file_id group,

f.record_id,

f.rec_txt

order of f.file_id,

f.record_id,

f.rec_txt

/

FILE_ID RECORD_ID REC_TXT NOTE_COMMENT
---------- ---------- ------- --------------------------------------------------------------------------------
1 1 note1comment bla
1 2 note2acomment2anote2acomment2bnote2bcomment2anote2bcomment2bnote2ccomment2anote2 nadda
ccomment2b

1 3 badda note3comment
1 4 sadda note4comment
1 5 note5comment padda

Scott@SOL12 >

SY.

Tags: Database

Similar Questions

  • When I send a text message and mobile data are off, it is not given, but I do not see this message for a few minutes. I can then refer using "send as a text message. How can I 'send as a text message' in the first place?

    When I send a text message and mobile data are off, it is not given, but I do not see this message for a few minutes. I can then refer using "send as a text message. How can I 'send as a text message' in the first place?

    Disable the iMessage?

  • How can I recover the modules and their data from a failed HARD drive (the lost BONE areas, but data files are readable)?

    The HARD drive that was my OS (Windows XP Pro SP3) failed and lost quite a few areas which are essential for the operating system running. Other data is still readable. A got another HARD drive and installed Windows XP SP2, Firefox and other programs. I was able to retrieve the bookmarks, security certificates, and other profile information using the information found in bandages.

    None of them addressed how do to recover the modules or their data. Specifically, there are several large, elegant scripts that took months to develop and customize.

    Articles related to migration and other do not work for me because they require the old copy of FF is functional, that is not because the OS on this HARD drive is damaged. Is it possible to recover these data, similar (or not) about how I could get the other profile info?

    Have you copied the entire folder C:\Documents and Settings\username \Application Data\Mozilla\Firefox\ on the old drive?
    If this is not the case, can you?
    If so, make a copy and save this folder just in case.

    If so, you could replace this folder on the new facility by \Profiles\ [with your profiles inside] folder and the profiles.ini file [delete all other files / folders that may also be in the folder "Firefox"] -and then replace with the same folder named from the old failed drive. Note that you will lose what you already have with the new installation / profile!
    Your profile folder contains all your personal data and customizations, including looking for plugins, themes, extensions and their data / customizations - but no plugins.
    But if the user logon name is different on the new facility that the former, any extension that uses an absolute path to the file in its prefs will be problems. Easily rectified, by changing the path to the file in the file prefs, js - keep the brake line formatting intact. The extensions created after the era of Firefox 2.0 or 3.0, due to changes in the 'rules' for creating extensions usually are not a problem, but some real old extensions that need only "minor" since that time can still use absolute paths - even though I have not seen myself since Firefox Firefox 3.6 or 4.0.

    View instead of 'Modules' I mentioned the 4 types of 'Modules' separately - Plugins are seen as 'Add-ons', but they are not installed in the profile [except those mislabelled as a "plugin", when they are installed via an XPI file], but rather in the operating system where Firefox 'find' through the registry.

    Note: Migration articles can tell you do not re - use the prefs.js file, due to an issue that I feel is easily fixed with a little inspection and editing. I think you can manage that my perception is that you have a small shovel in your tool box, if you encounter a problem you are able to do a little digging and fixing problems with the paths to files - once you have been warned.

    Overall, if you go Firefox 35 35 or even Firefox 34 to 35, I don't think you will run in all the problems that you can not handle [that I cross my fingers and "hope" that I'm not on what it is obvious].

    With regard to the recovery of the 'data' for individual extensions - there are many ways that extension developers used to store their data and pref. The original way should save in prefs.js or their own file RDF in the profile folder. While Firefox has been developed more, developers started using their own files in the profile folder. And because Mozilla has started using sqlite database files in Firefox 3.0, Mozilla extended their own use of sqlite, as have extension developers.
    Elegant uses the file stylish.sqlite to store 'styles', but something in the back of my mine tells me that 'the index' maybe not in this file with the data. But then again, I can be confusing myself a question I had with GreaseMonkey awhile back where I copied the gm_scripts folder in a new profile and with already installed GreaseMonkey but with no script. These GM scripts worked, but I could not see them or modify them - they do not appear in the user GM extension interface window in Firefox.

  • Error of Facebook, what can I do? Resource://jid0-wpch2liwmumjc8av1vwejwvgjbi-at-Jetpack/qclean-remove-Facebook-ads-suggested-pages-and-posts/data/qclean.js:53

    Facebook maintains the gel, a problem caused by this script resource://jid0-wpch2liwmumjc8av1vwejwvgjbi-at-jetpack/qclean-remove-facebook-ads-suggested-pages-and-posts/data/qclean.js:53

    I tried many solutions suggested, nothing works. Please advse. Thank you.

    Ed

    Hello ed, this error is caused by the qclean addon that you have installed. Please disable or delete or report the problem to the author of the extension...

    Disable or remove modules

  • I am not able to download apps for my iPhone on the App Store. He just 'waiting '. But never starts the download. I tried with wifi and mobile data. The two are not download apps

    I am not able to download apps for my iPhone on the App Store. He just 'waiting '. But never starts the download. I tried with wifi and mobile data. The two are not downloading the applications Can u find out what's wrong? I use iPhone 5s

    I had the same problem. At the same time hold the screen lock button and the home button until your iPhone restarts. That solved the problem for me.

  • How to eject my iphone, or player card on my macbook air?  I don't want to disconnect and lose data...

    How to eject my iphone, or player card on my macbook air?  I don't want to disconnect and lose data...

    You won't lose data when you remove an iPhone, unless you're in the middle of the backup or synchronization of the device.

    If you see no activity in iTunes/Photos/etc... Then, it is safe to unplug.

    With a card reader (SD card?) you do drag the desktop icon to the trash. It turns into an arrow when you drag an icon ejector.

    Similarly, you can click Finder on the dock, then locate the reader on the left column and click on the "arrow" to the right of the device to eject it.

  • Since the last system upgraded my menu bar top with wifi and time, date etc etc is hidden unless I have sulk my cursor on it. Same thing with apps from shingles. How can I restore it is always there?

    Since the last system upgraded my menu bar top with wifi and time, date etc etc is hidden unless I have sulk my cursor on it. Same thing with apps from shingles. How can I restore it is always there? bar menus hidden-how do I restore?

    SystemPreferences-> Dock: automatically hide / show Dock

    SystemPreferences-> general: automatically hide / show menu bar

  • Prob w/Importing Favorites and other data from Internet Explorer

    Everything by following the steps described in the forum article titled "Importing Favorites and other data from Internet Explorer" after completing step 3, select which points to import, if I select all the option or just the Favorites, I get the same error "Firefox has stopped working... close the program."

    I am importing of IE 8 on laptop Win7 OS. I tried importing every time and cannot get past this error. I made an export of IE8 that takes the form of a html file that there is apparently no option in Firefox to use.

    in Firefox:
    Bookmarks > organize bookmarks-> import and backup - import HTML... = HTML file

  • Is it normal that my iPhone 6 sec to drain the battery overnight so that wifi and cellular data are turned off?

    My 6s iPhone drains the battery overnight

    WiFi and cellular data off

    Not normal.

  • Why the hard disk is divided into partitions of two data (C:Vista and E: Data)?

    I just started a new A200-1V0 and found that disk space is divided into two partitions of sizes equal 'C:Vista' and ' E: Data "(and a small one EISA).

    WHY? What is the logic and purpose? It's not even as if the C:Vista partition is smaller and intended only to the tricks of the 'system' as the root 'Users' (user Documents) is on it also.

    This is the default for Vista (my first use of it), if not, who said that Toshiba could do this without asking me?

    How can I move the root 'Users' in Vista (in the data partition) - if I have two partitions that I might as well use it?

    I can resize partitions in Vista without a utility 3 rd-party (or a complete backup/restore)?

    Thank you

    Hello just YOU

    Please don't be offended because there is no reason for this. You bought the new product with the factory settings. Toshiba and other hardware manufacturer do not know every customer personally and, unfortunately, it was not possible to ask YOU how to set up YOUR laptop.

    Because of this, there is a recovery of product support that allows to configure the HARD disk according to your wishes and needs.

    Please use this DVD and install OS how you want it to be. What recovery procedure starts, you will see CONFIGURATION option on the right side. Click on it and choose the right option.

    Reinstall the OS and enjoy your life. Really, I don't have the time to write on the floors of two partitions, because this is basic stuff and you probably don't want to waste your time to read this.

    Bye and good luck!

  • Re: Satellite L300 - 11G - Configuration and other data is not displayed

    Hello. I have XP on my computer and I have problem with wireless card.
    All drivers are kept for the card but in the configuration utility of the wireless MAC address client and other data are not displayed.

    Can someone help me?

    Hello!

    To be honest I don t understand what you want.
    Maybe you should explain this better.

    The configuration as the IP address and MAC address, you can see in the command line. Start-run-cmd-ipconfig/all online online online

    Good bye

  • Is it possible to add the location and the date on the pictures in a slide show?

    Is it possible to add the place and the date on the pictures in a slide show?

    Only if you manually add a title slide t photo and enter this information manually.  There is no automatic way in Photos.

    Click on the button "+" at the right end of the slide show to add a title slide.

  • When I view my Photos, they have a place and a date. How can I print them with that on them?

    When I view my Photos, they have a place and a date. How can I print them with that on them?

    You want to print the information on the image itself?  To do this, you will need to export the picture on the desk and edit it with a 3rd party image editor that supports the text and layers:

    Some Image editors that support layers and text:


    Photoshop Elements for Mac 11 - $79

    GraphicConverter - $40
    The Rainbow painter - $30

    Photos of affinity- $50

    FX Photo Studio - $30

    Inpaint - $20
    Imaging - $38
    Acorn - $50

    Pixelmator - $60

    Seashore - free

    GIMP for Mac - free (Yosemite & Mavericks only)

  • Date of creation and the Date of importation

    When you import photos or video in the Photos to a folder, the application uses the date of importation of integration rather than the original creation date.  The result is that imports are all presented together under "Today."  Many photos and video taken on different dates, so I would only they listed according to date of creation rather than be grouped under the date of importation.  I went 'View' and checked "date of creation".  Photos don't work with "SORT" because it is always grey.  Any help would be greatly appreciated!

    If you look in the window of Photos photos and videos are sorted by date with the oldest items at the top.  This sort order cannot be change.

    In the pictures window, the elements are sorted by the date imported into the library with the oldest at the top.  The sort order cannot be changed here either.

    So, you can use a smart album to include all your photos in the library and then sort them one of these ways:

    The smart album could be created to this criterion:

    that would include all the photos in the library.  Now you can sort them as you like.  Just make sure that the date is early enough to catch all the photos in the library.

    Moments in Photos are new events, i.e. groups of photos sorted by date of catch.

    When the iPhoto library has been migrated first to the pictures there is a folder created in the box titled iPhoto events and all migrated iPhoto events (which are now Moments) are represented by an album in this folder. Use the Command + Option + S key combination to open the sidebar if it is not already open.

    NOTE: it has been reported by several users that if the albums of the event are moved in the iPhoto Library folder in the sidebar, they disappear.  It is not widespread, but several users have reported this problem.  Therefore, if you want to if ensure that you keep these event albums do not transfer out of the iPhoto events folder.

    Is there a way to simulate events in pictures.

    When new photos are imported in the library of Photos, go to the smart album last import , select all the photos and use the file menu option ➙ New Album or use the key combination command + N.  Call it what you want.  It appears just above the folder to iPhoto events where you can drag it into the events in iPhoto folder

    When you click on the folder to iPhoto events, you will get a window simulated of iPhoto events.

    Albums and smart albums can be sorted by title, by Date, with the oldest first and by Date with the most recent first.

    Tell Apple what missing features you want restored or new features added in Photos Photo-Applefeedback.

  • Hello. I have perchased the new iphone, and I gave my old iphone to my little brother. I erased all the content and the date in the settings menu. This will automatically delete all my photos data old messages etc. thanks

    Hello. I recently perchased the new iphone, and I gave my old iphone to my little brother. I erased all the content and the date in the settings menu. This will automatically delete all my photos data old messages etc. thanks

    Follow the directions here: what to do before you sell or give away your iPhone, iPad or iPod touch - Apple Support before giving the phone to your brother. -AJ

Maybe you are looking for