How to Unpivot, Crosstab, or Pivot using Oracle 9i with PL/SQL?

How to Unpivot, Crosstab, or Pivot using Oracle 9i with PL/SQL?
Here is a fictional sample layout of the data I have from My_Source_Query:
Customer | VIN | Year | Make | Odometer | ... followed by 350 more columns/fields
123 | 321XYZ | 2012 | Honda | 1900 |
123 | 432ABC | 2012 | Toyota | 2300 |
456 | 999PDQ | 2000 | Ford | 45586 |
876 | 888QWE | 2010 | Mercedes | 38332 |
... followed by up to 25 more rows of data from this query.
The exact number of records returned by My_Source_Query is unknown ahead of time, but should be less than 25 even under extreme situations.
Here is how I would like the data to be:
Column1 |Column2 |Column3 |Column4 |Column5 |
Customer | 123 | 123 | 456 | 876 |
VIN | 321XYZ | 432ABC | 999PDQ | 888QWE |
Year | 2012 | 2012 | 2000 | 2010 |
Make | Honda | Toyota | Ford | Mercedes|
Odometer | 1900 | 2300 | 45586 | 38332 |
... followed by 350 more rows with the names of the columns/fields from the My_Source_Query.
From reading and trying many, many, many of the posting on this topic I understand that the unknown number or rows in My_Source_Query can be a problem and have considered working with one row at a time until each row has been converted to a column.
If possible I'd like to find a way of doing this conversion from rows to columns using a query instead of scripts if that is possible. I am a novice at this so any help is welcome.
This is a repost. I originally posted this question to the wrong forum. Sorry about that.

The permission level that I have in the Oracle environment is 'read only'. This is also be the permission level of the users of the query I am trying to build.
As requested, here is the 'create' SQL to build a simple table that has the type of data I am working with.
My real select query will have more than 350 columns and the rows returned will be 25 rows of less, but for now I am prototyping with just seven columns that have the different data types noted in my sample data.
NOTE: This SQL has been written and tested in MS Access since I do not have permission to create and populate a table in the Oracle environment and ODBC connections are not allowed.
CREATE TABLE tbl_MyDataSource
(Customer char(50),
VIN char(50),
Year char(50),
Make char(50),
Odometer long,
InvDate date,
Amount currency)
Here is the 'insert into' to populate the tbl_MyDataSource table with four sample records.
INSERT INTO tbl_MyDataSource ( Customer, VIN, [Year], Make, Odometer, InvDate, Amount )
SELECT "123", "321XYZ", "2012", "Honda", "1900", "2/15/2012", "987";
INSERT INTO tbl_MyDataSource ( Customer, VIN, [Year], Make, Odometer, InvDate, Amount )
VALUES ("123", "432ABC", "2012", "Toyota", "2300", "1/10/2012", "6546");
INSERT INTO tbl_MyDataSource ( Customer, VIN, [Year], Make, Odometer, InvDate, Amount )
VALUES ("456", "999PDQ", "2000", "Ford", "45586", "4/25/2002", "456");
INSERT INTO tbl_MyDataSource ( Customer, VIN, [Year], Make, Odometer, InvDate, Amount )
VALUES ("876", "888QWE", "2010", "Mercedes", "38332", "10/13/2010", "15973");
Which should produce a table containing these columns with these values:
tbl_MyDataSource:
Customer     VIN     Year     Make     Odometer     InvDate          Amount
123 | 321XYZ | 2012 | Honda      | 1900          | 2/15/2012     | 987.00
123 | 432ABC | 2012 | Toyota | 2300 | 1/10/2012     | 6,546.00
456 | 999PDQ | 2000 | Ford     | 45586          | 4/25/2002     | 456.00
876 | 888QWE | 2010 | Mercedes | 38332          | 10/13/2010     | 15,973.00
The desired result is to use Oracle 9i to convert the columns into rows using sql without using any scripts if possible.
qsel_MyResults:
Column1          Column2          Column3          Column4          Column5
Customer | 123 | 123 | 456 | 876
VIN | 321XYZ | 432ABC | 999PDQ | 888QWE
Year | 2012 | 2012 | 2000 | 2010
Make | Honda | Toyota | Ford | Mercedes
Odometer | 1900 | 2300 | 45586 | 38332
InvDate | 2/15/2012 | 1/10/2012 | 4/25/2002 | 10/13/2010
Amount | 987.00 | 6,546.00 | 456.00 | 15,973.00
The syntax in SQL is something I am not yet sure of.
You said:
>
"Don't use the same name or alias for two different things. if you have a table called t, then don't use t as an alais for an in-line view. Pick a different name, like ordered_t, instead.">
but I'm not clear on which part of the SQL you are suggesting I change. The code I posted is something I pieced together from some of the other postings and is not something I full understand the syntax of.
Here is my latest (failed) attempt at this.
select *
  from (select * from tbl_MyDataSource) t;
with data as
(select rownum rnum, t.* from (select * from t order by c1) ordered_t), -- changed 't' to 'ordered_t'
rows_to_have as
(select level rr from dual connect by level <= 7 -- number of columns in T
select rnum,
       max(decode(rr, 1, c1)),
       max(decode(rr, 2, c2)),
       max(decode(rr, 3, c3)),
       max(decode(rr, 4, c3)),      
       max(decode(rr, 5, c3)),      
       max(decode(rr, 6, c3)),      
       max(decode(rr, 7, c3)),       
  from data, rows_to_have
group by rnumIn the above code the "select * from tbl_MyDataSource" is a place holder for my select query which runs without error and has these exact number of fields and data types as order shown in the tbl_MyDataSource above.
This code produces the error 'ORA-00936: missing expression'. The error appears to be starting with the 'with data as' line if I am reading my PL/Sql window correctly. Everything above that row runs without error.
Thank you for your great patients and for sharing your considerable depth of knowledge. Any help is gratefully welcomed.

Similar Messages

  • How to use Oracle partitioning with JPA @OneToOne reference?

    Hi!
    A little bit late in the project we have realized that we need to use Oracle partitioning both for performance and admin of the data. (Partitioning by range (month) and after a year we will move the oldest month of data to an archive db)
    We have an object model with an main/root entity "Trans" with @OneToMany and @OneToOne relationships.
    How do we use Oracle partitioning on the @OneToOne relationships?
    (We'd rather not change the model as we already have millions of rows in the db.)
    On the main entity "Trans" we use: partition by range (month) on a date column.
    And on all @OneToMany we use: partition by reference (as they have a primary-foreign key relationship).
    But for the @OneToOne key for the referenced object, the key is placed in the main/source object as the example below:
    @Entity
    public class Employee {
    @Id
    @Column(name="EMP_ID")
    private long id;
    @OneToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="ADDRESS_ID")
    private Address address;
    EMPLOYEE (table)
    EMP_ID FIRSTNAME LASTNAME SALARY ADDRESS_ID
    1 Bob Way 50000 6
    2 Sarah Smith 60000 7
    ADDRESS (table)
    ADDRESS_ID STREET CITY PROVINCE COUNTRY P_CODE
    6 17 Bank St Ottawa ON Canada K2H7Z5
    7 22 Main St Toronto ON Canada     L5H2D5
    From the Oracle documentation: "Reference partitioning allows the partitioning of two tables related to one another by referential constraints. The partitioning key is resolved through an existing parent-child relationship, enforced by enabled and active primary key and foreign key constraints."
    How can we use "partition by reference" on @OneToOne relationsships or are there other solutions?
    Thanks for any advice.
    /Mats

    Crospost! How to use Oracle partitioning with JPA @OneToOne reference?

  • How to connect from java without using oracle client installation

    hi ,
    Please tell me how to connect from java without using oracle client
    Thanks & Regars

    http://www.orafaq.com/wiki/JDBC#Thin_driver

  • How to Use Oracle 8i with MapX?

    I am trying to work with oracle 8i 1.6 and mapX 4.5 but un-able to do so. I tried by adding server layer but couldn't do so.
    Help !!

    Crossposted: Re: How to use Oracle partitioning with JPA @OneToOne reference?

  • Can I use Oracle IPM with a third party content managemen system?

    Hello,
    Our client has a requirment to use Oracle IPM with a non-Oracle content management system. That is they don't want to Oracle UCM. Is it possible? If yes, can you please direct me to some kind of documentation.
    Any help is greatly appreciated.
    Regards
    Abhishek

    I think you should draw a scheme of your architecture for yourself.
    An A/P solution consists of:
    - scanning (hence, ODC/ODDC)
    - repository of images (IPM based on UCM)
    - workflows (BPM as a part of IPM license)
    - connector to an application (usually, Oracle EBS Adapter is used here)
    If you don't intend to use any part of the solution (e.g. you have a different ERP system than EBS, you have your own repository), you can replace it with your own parts. However, be aware that you will have take care of the integration - Oracle can integrate for you only those parts that Oracle has under control (ODC is integrated to UCM/IPM, IPM/UCM is integrated to EBS, workflows know how to call UCM/IPM services). Of course, it uses open standards (web services or RIDC), so you may implement the integration yourself.

  • Use Oracle Reports with Jdeveloper 11

    Hi,
    My next question. How to use Oracle Reports with jdeveloper 11. I have more oracle reports (used with a existing forms application) and i need to migrate this application to web-adf application. I think that is very powerful to use this oracle definition reports but i not know ho to do it.
    thanks,
    Jordi

    Read the publishing reports manual of Oracle reports to see how to Web enabled your Oracle reports. You can then invoke them from an ADF application either by calling a URL or using a Web service interface.

  • How to create users and groups using WLST Offline with Weblogic 8.1.4

    How to create users and groups using WLST Offline with Weblogic 8.1.4?
    Any ideas?

    Hi this is how i created a user using WLST Offline?
    cd('/Security/' + domainName)
    # Delete the default user name weblogic
    # incase you want to remove the defualt user weblogic
    delete('weblogic','User')
    # Creating a new user defined
    create(userName, 'User')
    # Setting the password of the user you created.
    cd ('/Security/' + domainName + '/User/' + userName)
    cmo.setPassword(password)
    Regards
    Makenzo

  • How to avoid data repetation when using select statements with innerjoin

    how to avoid data repetation when using select statements with innerjoin.
    thanks in advance,
    satheesh

    you can use a query like this...
      SELECT DISTINCT
             frg~prc_group1                  "Product Group 1
             frg~prc_group2                  "Product Group 2
             frg~prc_group3                  "Product Group 3
             frg~prc_group4                  "Product Group 4
             frg~prc_group5                  "Product Group 5
             prc~product_id                  "Product ID
             txt~short_text                  "Product Description
    UP TO 10 ROWS
    INTO TABLE l_i_data
    FROM
    Joining CRMM_PR_SALESG and
    COMM_PR_FRG_ROD
    crmm_pr_salesg AS frg
    INNER JOIN comm_pr_frg_rod AS prd
    ON frgfrg_guid = prdfragment_guid
    Joining COMM_PRODUCT and
    COMM_PR_FRG_ROD
    INNER JOIN comm_product AS prc
    ON prdproduct_guid = prcproduct_guid
    Joining COMM_PRSHTEXT and
    COMM_PR_FRG_ROD
    INNER JOIN comm_prshtext AS txt
    ON prdproduct_guid = txtproduct_guid
    WHERE frg~prc_group1 IN r_zprc_group1
       AND frg~prc_group2 IN r_zprc_group2
       AND frg~prc_group3 IN r_zprc_group3
       AND frg~prc_group4 IN r_zprc_group4
       AND frg~prc_group5 IN r_zprc_group5.
    reward it it helps
    Edited by: Apan Kumar Motilal on Jun 24, 2008 1:57 PM

  • How to select "ISO A" (auto) using Custom Controls with lever assigned to ISO change?

    On 7D Mark II with firmware 1.0.4, I have used Custom Controls to assign ISO change to the lever.  However, it is not possible to change ISO to "ISO A" (auto).  How to select "ISO A" (auto) using Custom Controls with lever assigned to ISO change? 

    Follow Up:
    Ok so ive changed things up a bit and have had some more success.
    I have used a Switch statement in my For loop to perform different actions based on the item selected.
    The code looks like this:
    Workbook.Content.Table1.Row3.AppropriationDetails.Row4.Cell1::change - (JavaScript, client)
    var fFrom = xfa.resolveNodes("Workbook.Content.Table1.Row3.AppropriationDetails[*] .Row4.Cell1");
    var fTo = xfa.resolveNodes("Workbook.Content.Table2.Row3.AppropriationDetails[* ].Row4.Cell1");
    for (var i=0; i <= fFrom.length-1; i++) {
         switch (fFrom.item(i).rawValue)
         case "Option 3":
         fTo.item(i).rawValue = "Enter the details in the field below";
         break;
         default:
         fTo.item(i).rawValue = fFrom.item(i).boundItem(xfa.event.newText);
         break;
    This code solves my problem but has thrown up a new issue:
    When i select Option 1 or 2 from the dropdown list  the change in the text field is instantaneous, however if I select Option 3 it wont appear in the text field until I either select Option 3 a second time or select another item. Its as if the text field is a selction behind what I have enterd in the dropdown list.
    Any thoughts?

  • Oracle Connectivity with MS SQL Server. ORA-00972: identifier is too long

    I have linked Oracle Database with MS SQL Server using HS and DB Link.
    DB Link Script:
    CREATE DATABASE LINK "FCHH"
    CONNECT TO SA
    IDENTIFIED BY <PWD>
    USING 'LISTENER_FCHH';
    Links tested successfully.
    Now "SA" user in Microsoft SQL Server has multiple databases i.e. Master,SecurePerfect,SecurePerfectHistory. when I try following command
    select * from "SecurePerfectHistory.DBO.BadgeHistoryTable"@FCHH
    ORA-00972: identifier is too long

    ORA-00972: identifier is too long
    Cause: An identifier with more than 30 characters was specified.
    Action: Specify at most 30 charactersAman....

  • How can I return multiple values using Oracle 9i Web Services ?

    Hi, Is it possible to return multiple parameters using WebServices in general ? And if yes, how do we do it using Oracle 9i WebServices ?
    At my client usually I call
    return_value = SoapClient.MehtodName(param1, param2, param3)
    If i need more than one return_value...how do we handle that ?
    Thanks,
    -Krishna

    Anyone has any ideas about this ?
    And also if i want a collection in one of the input parameters...how to do that ?
    Does Oracle WS have any such support ? Or we have devise our own way like sending it by separators or something like that ?
    Thanks,
    Krishna

  • How can i use Oracle intermedia with Oracle forms 9i

    Hi all,
    I have a requirment from one of our client that they want to manage a large amount of Images,by seeing the documents about the oracle interMedia we got some idea to manage this images ,but the client is alredy having a software which is been developed by Oracle forms9i and we need to develope this using oracle forms9i can anyone give us an idea that how can we make use of InterMedia through Oracle forms9i ....
    Thanks in advance....

    I am also trying to use interMedia objects with Oracle 9i forms. I've tried everything and I can't get it to work.
    So far I have a solution that loads images using WebUtil into a blob field in Forms 9i, then in a backend stored procedure I move the blob to an interMedia object. Which works, but the problem with the image item in Oracle forms is that the image format cannot be change at runtime, so the images will always be what you set at design time.
    Can someone out there please help.
    Thanks.
    Ray

  • How can i use Oracle interMedia with Oracle forms  Urgent

    Hi all,
    I have a requirment from one of our client that they want to manage a large amount of Images,by seeing the documents about the oracle interMedia we got some idea to manage this images ,but the client is alredy having a software which is been developed by Oracle forms9i and we need to develope this using oracle forms9i can anyone give us an idea that how can we make use of InterMedia through Oracle forms9i ....
    Thanks in advance....

    I will ask, but it would be good to ask in the Oracle Forms forum as well. Many tools recognize the interMedia columns and automatically handle them since they now can say "Oh, this is an image column, I know how to handle this". I am not sure where forms is in this regard.

  • How can i use oracle coherence with JPA/ejb  in web service?

    Hi
    I want to make web service using JPA which calls oracle XE via oracle coherence? i want to use JAX-ws? i searched and found you can make and deployed it using web logic but is there any other way i can make it and deployed in tomcat. i want to use oracle coherence + Oracle XE + JAX-WS? if it possible how can i other wise what are other ways i can do it?
    please any one does know it reply please it helps me lot to get.
    Thanks in advance,
    Edited by: 913837 on Feb 22, 2012 3:51 PM

    If you want data cached in Coherence to find it's way into an Oracle database for persistence, then look at the "CacheStore" section of the Coherence Developer Guide. This also works the other way round too, in that you can get data read into a Coherence cache via a database read. Again, look in the Coherence Developer Guide.
    If you want you applications "entry point" into a piece of code to be a web-service, then Tomcat+CXF will work just fine. Once you are in the service, just use the Coherence API to put the data in a cache.
    But also look at the HTTP access offered in later versions of Coherence in the form of REST. This may save you the Tomcat+CXF install, depending upon your needs. See the Coherence Client Guide.
    Still, what exactly are you trying to achieve here? It's not clear from your post why a web service using JPA for persistence needs to go via Coherence at all. More info needed.
    Cheers,
    Steve

  • How to design Forms and Reports using Oracle workflow 2.6

    Is it possible to design Forms & Reports for Data Entry and
    reporting purposes using oracle workflow standalone version?
    if so how?.
    Please helpme!! is veri urgent.

    Con este apellido seguro que entiendes el Espaqol.
    Mi empresa esta iniciando un proyecto con la tecnologia que
    estas buscando, es decir, Utilizar Forms y Reports para manejar
    las APIS de WorkFlow Server, hemos encontardo muchos problemas,
    el principal es que la API de WorkFlow es demasiado pequeqa para
    manipular todos los procesos de WorkFlow por este motivo nos
    hemos visto obligados a acceder a tablas y vistas del modelo de
    datos de WorkFlow.
    Saludos.

Maybe you are looking for

  • I installed a new video card onto my computer...the monitor wont work!!!?

    So I got a new GPU (VGA MSI NX8800GT 512M OC RT). I installed it last night and plugged the monitor into it...I know the computer sees it because the LED light turns green, then it goes to sleep. So I figure that maybe the GPU is incompatible with my

  • How to upgrade the patches in ACS 5.1

    I want to upgrade the acs 5.1 in distributed system. We have one hub/ primary ACS and two other spoke / secodary acs. I have following querry. Will it be possible to upgrad only one Secondary server.> Will updated secondary ACS will able to sych it c

  • How to create rule groups strp by step-urgent

    Hi All, Can you please provide me the step by step procedure for creating rule groups. I have four date fields ina DSO which have to be mapped to a date field in cube.\ Thanks in adavnce

  • OBI EE 10.1.3.2 installation problem

    Hello, I just installed OBI on Linux with OAS R3 (10.1.3.1.0). I can't manage to use Oracle Application Server Control to edit configuration files (instanceconfig.xml, etc). I've added in the opmn.xml parameters from the documentation (-DSAROOTDIR, -

  • Calendar event location not shown on iPod

    I use iCal to sync with my iPod so that I have all of the information about my scheduled events, i.e. the room number and building of where I need to be at a certain time. In the past this has worked just fine, but for some reason now when I look at