Help with oracle 11g pivot operator

i need some help with oracle 11g pivot operator. is it possible to use multiple columns in the FOR clause and then compare it against multiple set of values.
here is the sql to create some sample data
create table pivot_data ( country_code number , dept number, job varchar2(20), sal number );
insert into pivot_data values (1,30 , 'SALESMAN', 5000);
insert into pivot_data values (1,301, 'SALESMAN', 5500);
insert into pivot_data values (1,30 , 'MANAGER', 10000);     
insert into pivot_data values (1,301, 'MANAGER', 10500);
insert into pivot_data values (1,30 , 'CLERK', 4000);
insert into pivot_data values (1,302, 'CLERK',4500);
insert into pivot_data values (2,30 , 'SALESMAN', 6000);
insert into pivot_data values (2,301, 'SALESMAN', 6500);
insert into pivot_data values (2,30 , 'MANAGER', 11000);     
insert into pivot_data values (2,301, 'MANAGER', 11500);
insert into pivot_data values (2,30 , 'CLERK', 3000);
insert into pivot_data values (2,302, 'CLERK',3500);
using case when I can write something like this and get the output i want
select country_code
,avg(case when (( dept = 30 and job = 'SALESMAN' ) or ( dept = 301 and job = 'SALESMAN' ) ) then sal end ) as d30_sls
,avg(case when (( dept = 30 and job = 'MANAGER' ) or ( dept = 301 and job = 'MANAGER' ) ) then sal end ) as d30_mgr
,avg(case when (( dept = 30 and job = 'CLERK' ) or ( dept = 302 and job = 'CLERK' ) ) then sal end ) as d30_clrk
from pivot_data group by country_code;
output
country_code          D30_SLS               D30_MGR               D30_CLRK
1      5250      10250      4250
2      6250      11250      3250
what I tried with pivot is like this I get what I want if I have only one ( dept,job) for one alias name. I want to call (30 , 'SALESMAN') or (301 , 'SALESMAN') AS d30_sls. any help how can I do this
SELECT *
FROM pivot_data
PIVOT (SUM(sal) AS sum
FOR (dept,job) IN ( (30 , 'SALESMAN') AS d30_sls,
          (30 , 'MANAGER') AS d30_mgr,               
(30 , 'CLERK') AS d30_clk
this is a simple example .... my real life scenario is compliated with more fields and more combinations .... So something like using substr(dept,1,2) won't work in my real case .
any suggestions get the result similar to what i get in the case when example is really appreciated.

Hi,
Sorry, I don't think there's any way to get exactly what you requested. The values you give in the PIVOT ... IN clause are exact values, not alternatives.
You could do something like this to map all alternatives to a common value:
WITH     got_dept_grp     AS
     SELECT     country_code, job, sal
     ,     CASE
              WHEN  job IN ('SALESMAN', 'MANAGER') AND dept = 301 THEN 30
              WHEN  job IN ('CLERK')               AND dept = 302 THEN 30
                                                                 ELSE dept
          END     AS dept_grp
     FROM     pivot_data
SELECT     *
FROM     got_dept_grp
PIVOT     (     AVG (sal)
     FOR     (job, dept_grp)
     IN     ( ('SALESMAN', 30)
          , ('MANAGER' , 30)
          , ('CLERK'   , 30)
;In your sample data (and perhaps in your real data), it's about as easy to explicitly define the pivoted groups individually, like this:
WITH     got_pivot_key     AS
     SELECT     country_code, sal
     ,     CASE
              WHEN  job = 'SALESMAN' AND dept IN (30, 301) THEN 'd30_sls'
              WHEN  job = 'MANAGER'  AND dept IN (30, 301) THEN 'd30_mgr'
              WHEN  job = 'CLERK'    AND dept IN (30, 302) THEN 'd30_clrk'
          END     AS pivot_key
     FROM    pivot_data
SELECT     *
FROM     got_pivot_key
PIVOT     (     AVG (sal)
     FOR     pivot_key
     IN     ( 'd30_sls'
          , 'd30_mgr'
          , 'd30_clrk'
;Thanks for posting the CREATE TABLE and INSERT statements; that really helps!

Similar Messages

  • Oracle Tuxedo 8.1 With Oracle 11g Database

    Hi,
    I have an old application that must be compiled with oracle 8.1 and Oracle9i Database.
    We are migrating to Oracle 11g Database, and now we have some inssues to compile with Oracle 11g Database. For example some Libraries that the Tuxedo XA Resource Manager needs from the Oracle Database, that just u can found on older versions like Oracle9i (kpudfo.o file).
    what can be the solution for that problem?
    An Oracle 11g database config or a Tuxedo config ?

    Hi,
    When you say "Tuxedo XA Resource Manager" I'm not sure what you are referring to. Do you mean the Tuxedo transaction management servers (TMS) servers that are built with the buildtms command? If so, if there are linking errors, it has to do with either your library paths or the RM definition for Oracle Database in the $TUXDIR/udataobj/RM file. Tuxedo itself only uses the XA switch from the resource manager such as Oracle database. Now the resource manager may require a bunch of libraries, which is why I suggested you check your library path. If the above doesn't help, can you post the error you are getting and what is generating/creating the error?
    Regards,
    Todd Little
    Oracle Tuxedo Chief Architect

  • Can OBIEE 10.1.3.4 work with Oracle 11g 64bit?

    I Installed Oracle 11 g 64bit with JDK 64bit on my windows 7 Home Premium 64bit machine . After this i installed OBIEE 10.1.3.4 .
    Now OBIEE needs 32 bit JDK.
    How do i solve this?
    Can OBIEE 10.1.3.4 be used with oracle 11g 64 bit edition??

    First i installed Oracle 10g on my windows 7 home premium 64 bit .
    Then i installed OBIEE 10.1.3.4 on my machine
    But then there were some problems cropping up and i wasn't able to use OBIEE 10.1.3.4 with windows 7home premium 64 bit machine.
    I then removed both oracle 10g and OBIEE 10.1.3.4 from my machine.
    Then i installed oracle 11g 64bit and then OBIEE 10.1.3.4 . But again it dint work
    Can anyone help?

  • Problem with Oracle 11g(32 bit) installation on windows 7 ultimate edition

    Hello all,
    I have a problem with Oracle 11g(32 bit) installation on windows 7 ultimate edition (32 bit).
    I have successfully installed it immediately after OS installation. But today, i have decided to deinstall it and go for Oracle 10g version for 32 bit.
    Everything went normal during installation, but i can see the services is not present in services.msc. Also its throwing some exception for dbca, netca
    Now i tried to deinstall it and again go for 11g. But even the same story here..
    Can anybody give me a solution for this..
    -Regards
    Rajesh Menon

    Saqib Alam wrote:
    i recently install Oracle 11g R1 on windows 7 ultimate, i installed it and working perfectly.
    ur problem is that u install latest version and now u trying to installing old version.
    now u need to uninstall 10g and delete oracle from services, if the probleme presist then u should
    install fresh windows 7.
    Regards
    SaqibNo need to install a fresh OS. That's like tearing your house down just because you wired a lamp wrong and blew a circuit breaker.
    There are MeaLink notes on how to eradicate an Oracle install from Windows, but it boils down to this:
    Stop all Oracle services
    In the registery:
    - Delete all oracle services from the register (HKLM\SYSTEM\CurrentControlSet
    - Delete the entire Oralce folder from HKLM\Software
    reboot
    Delete the ORACLE_HOME directory and any other Oracle related directories/files. Offhand, it seems like there is an Oracle directory under Program Files.
    reboot

  • Error Intall RWD Uperform 4.3 on Windows 2008 with Oracle 11G

    Hi,
    I need install RWD Uperform 4.3 on Windows 2008 with Oracle 11G.
    When tried install Uperform 4.3 occurs the next error:
    Product: RWD uPerform Server -- This Release requires Oracle 11.2 R2 ODP Client to be Installed.
    If you are not using Oracle, please use the regular 4.30.0 release.
    If you are using Oracle, please install ODP.NET and then re-run the Setup. Setup will be aborted now.
    I installed the ODP.NET whit the version 11.2.0.2.
    But the errors still occur.
    Thanks.
    Marco Kolombesky

    In the end I solved my problem.
    But I installed RWD uperform 4.4 (not 4.3).
    But I think that the problem was that when I installed uperform 4.3 I didn't run this command at DB level on my SQL Server datadabe:
    ALTER DATABASE AdventureWorks2008R2
        SET READ_COMMITTED_SNAPSHOT ON;
    GO
    Regards
    Matteo Stocco

  • IPlanet 6.0 SP6 compatibility with Oracle 11g Client in Windows server 2003

    Hi All,
    We have issues with our classic ASP application when connecting to Oracle 11g. Our application Database is migrating from oracle 10g to oracle 11g, with oracle 10g we don't have any issues but we are facing issues with Oracle 11g database
    We are running iPlanet-WebServer-Enterprise/6.0SP6. And Chilisoft is Sun ONE ASP 4.0 (formerly known as Chili!Soft ASP) on windows 2003 machine for running ASP application.
    The connection we are trying is
    Provider=OraOLEDB.Oracle; Data Source=xxxx;User Id=xxx;Password=xxx;
    The error we are getting is "OraOLEDB error '80004005' "
    Question: Is iPlanet-WebServer-Enterprise/6.0SP6. And Chilisoft is Sun ONE ASP 4.0 is compatible with Oracle Client 11g in Windows 32 bit machine
    Appreciate your quick response
    Thanks,
    Murthy

    I have the same situation. Could you please share your experience if you resolve it? Thanks.

  • Primavera CM compatibility with Oracle 11g Express Edition

    We are trying to install Primavera CM 13.1 application (on windows 7 32 bit) with oracle 11g express edition (on CentOS 5.4 64 bit). Installation is completed without any warning but while trying to log on in the system with expadmin, it shows Internal Server Error. Through dbconfigcm utility we can connect the database but while running the CMAdminConfig utility, it throws java exception in command line "Unable to parse XML String" with java pop-up warning node has no children.
    Is it due to compatibility issue of Primavera CM 13.0/ 13.1 with oracle 11g express edition or something we are missing?
    Regards,
    Sandip

    Thanks Jim for the quick response. From the link, I understand that TT integration will be available with an extra cost. I presume it is only with EE and not XE, correct? Technically, there is no TT support with XE, Is that a fair statement?
    Thanks

  • Pro*C with Oracle 11g

    Hi !
    I didn't find a forum specific to pro*c, so here i am because i was told this forum had a bit of pro*c activity....
    I've downloaded Oracle 11g and recompiled our applications using pro*c
    We currently precompiling without any problem our sources against Oracle 7, 8, 9, 10.
    With Oracle 11g, it doesn't work !
    every EXEC SQL followed by a command works.
    every EXEC SQL followed by a query generates the same error.
    Example :
    char *oracle_date_courante()
    static char buf[SIZE_ORADATE+1];
    EXEC SQL SELECT sysdate into :buf from DUAL;
    if(ORA_SQLERROR())
    oracle_error("sélection date courante");
    buf[0]=0;
    return buf;
    PRO*C output :
    Erreur Ó la ligne 105, colonne 2 dans le fichier src\oracle.pc
    EXEC SQL
    .1
    PLS-S-00000, SQL Statement ignored
    erreur sÚmantique Ó la ligne 105, colonne 2, fichier src\oracle.pc:
    EXEC SQL
    .1
    PCC-S-02346, PL/SQL a trouvÚ des erreurs sÚmantiques
    So, we investigated... And found that thoses errors come when we use the option sqlcheck=semantics.
    If we use an inferiour check level, it works but because we use PL/SQL keywords, pro*c prints errors and wants us to provide the 'semantics' sqlcheck level !
    So, it's a vicious circle !
    Any ideas ?
    Thanks...
    Vincent

    Adding the option common_parser=yes removes the errors !
    But brings errors linked to the PL/SQL parser such like
    CSF-S-00000, ORA-06544: PL/SQL : erreur interne, arguments : [55916], [], [], []
    1>, [], [], [], []
    1>ORA-06553: PLS-801: erreur interne [55916]
    Really vicious..and still not precompiling !
    By the way : Server is 10.2.0.1... and i guess thoses errors are normal since the common parser is not available in this version...
    So bye bye option common_parser and i'm back to my orignals errors.
    Message was edited by:
    Vicenzo

  • I need help with oracle

    Hi,
    I need some help... if someone can help its great.
    I need to make a statement in Oracle SQL that read data from a file and insert in a Oracle Database ... if someone can show me the syntax of it i appreciate..
    Thanks

    Okay, I see you followed the advice in that other thread and started a new post for you question. Congratulations. Your next lesson in forum etiquette is to give your posts a more relevant subject. Pretty much everybody who posts here needs help with oracle; if they need help with cooking catfish they've come to the wrong place.
    It that other thread I suggested using SQL*Loader or External Tables might be a more suitable solution. Find out more.
    Cheers, APC

  • Oracle SQL Developer 1.2 – Automatic -  is compatible with Oracle 11g?

    Oracle SQL Developer 1.2 – Automatic - is compatible with Oracle 11g?
    Thanks in advance!
    -Babu

    So I'm taking it the question is -
    Is 1.2 Sql Developer compatible with 11g DB?
    The short answer is Yes. We are constantly adding new functionality and better support for the newer Databases. For Example to use the real time Sql monitoring that became available in 11g you will have to be on at least 2.1 Sql Dev. Is there some reason you don't want to upgrade to the latest Sql Dev? If not the current EA version then at least the current production version?
    Thanks,
    Syme

  • How to consume sap xi pi web services or sap RFC with oracle 11g forms.

    Dear All
    how to consume sap xi pi web services or sap RFC with oracle 11g forms.
    or
    how to config 11g forms with sap xi....
    or how to call sap xi web services in 11g forms....
    or can send sample code....
    Regards
    smfatmi
    Edited by: smfatmi on Oct 17, 2011 2:16 AM
    Edited by: smfatmi on Oct 17, 2011 2:17 AM

    Dear All
    how to consume sap xi pi web services or sap RFC with oracle 11g forms.
    or
    how to config 11g forms with sap xi....
    or how to call sap xi web services in 11g forms....
    or can send sample code....
    Regards
    smfatmi
    Edited by: smfatmi on Oct 17, 2011 2:16 AM
    Edited by: smfatmi on Oct 17, 2011 2:17 AM

  • Which latest web logic server compatible with oracle 11g database

    which latest web logic server compatible with oracle 11g database >is weblogic server 12c is compatible with oracle 11gR2

    current environment= forms and reports 10g and database 10gR2,os windows 32-bit.
    wants to implement and configure as below:
    server1: web-logic server 12c with forms and reports upgrade from 10g to 11g where os 64-bit windows.
    server2: upgrade and migrate  from 10gR2 11gR2 from windows xp to windows 2008-R2.
    how to achieve this.what step should perform first.

  • Is practising on Oracle OLAP features free with Oracle 11g EE?

    Hi,
    Is practising on Oracle OLAP features free with Oracle 11g EE??
    Information found in Internet:
    - Oracle Corporation markets the Oracle Database OLAP Option as an extra-cost option to supplement the "Enterprise Edition" of its database.
    - Oracle Database OLAP is there pre-installed along with the rest of Oracle Database EE. You just need to license it for use on the DB Machine when you choose to use it.
    - Oracle OLAP is a world class multidimensional analytic engine embedded in Oracle Database 11g.
    Please confirm if I can try some OLAP features in my office where I have Oracle 11g EE installed as I have been asked to do an initial POC?
    Regards,
    Sudhir

    Hi there,
    I believe that the OLAP license falls under the developer license on OTN - http://www.oracle.com/technetwork/testcontent/standard-license-088383.html
    You should contact your local Oracle sales rep if you are still unsure
    Thanks,
    Stuart Bunby
    OLAP Blog: http://oracleOLAP.blogspot.com
    OLAP Wiki: http://wiki.oracle.com/page/Oracle+OLAP+Option
    OLAP on OTN: http://www.oracle.com/technology/products/bi/olap/index.html
    DW on OTN : http://www.oracle.com/technology/products/bi/db/11g/index.html

  • Forms 6i is not connecting with Oracle 11g database?

    Forms 6i is not connecting with Oracle 11g database?
    How to resolve this issue?

    Hi,
    Once you installed the Forms and Reports, you need to configure the paramters like tnsnames.ora in you path.
    There will be one folder in the Installation path of Forms and Reports search for tnsnames.ora file..and you need to Updated the file as per the which ORACLE Server you are connecting and then try.. it..
    Default path for forms will be "ORACLE_HOME/net80/admin".. search for tnsnames.ora and modify it..
    - Pavan Kumar N

  • Is it possible to run Oracle 6i application with Oracle 11g?

    HI,
    We are running oracle developer 6i (6.0) application with oracle 10g database.
    Due to some management decisions we are in planning to upgrade the database to 11g.
    So, tell us that Is it possible to run Oracle 6i application with Oracle 11g?
    Regards,
    fazijee

    Also see Oracle Support note
    Is Forms/Reports 6i Certified to Work Against Oracle Server 10g Rel 1, Rel 2 or 11gRel 1, Rel 2? [ID 338513.1]
    6i isn't certified nor will be certified against 10.2 and 11.x
    Hemant K Chitale

Maybe you are looking for