Pivot query problem

All (running 11.2 OEL on 5),
I'm fighting figuring how to get the result I want to with the following data:
CREATE TABLE REGION_LOOKUP 
   (     REGION_ID NUMBER NOT NULL ENABLE, 
     REGION VARCHAR2(5) NOT NULL ENABLE, 
     PRIMARY KEY ("REGION_ID") ENABLE
   )
/ 
CREATE TABLE IND_REVENUE 
   (     ID NUMBER, 
     IND_REV_DATE VARCHAR2(30), 
     IND_REVENUE NUMBER, 
     REGION_ID NUMBER, 
     CONSTRAINT IND_REVENUE_PK PRIMARY KEY (ID) ENABLE
   )
/
INSERT INTO REGION_LOOKUP (REGION_ID, REGION VALUES(1,'EMEA');
INSERT INTO REGION_LOOKUP (REGION_ID, REGION VALUES(2,'LAD');
INSERT INTO REGION_LOOKUP (REGION_ID, REGION VALUES(3,'APAC');
INSERT INTO REGION_LOOKUP (REGION_ID, REGION VALUES(4,'NAS');
INSERT INTO REGION_LOOKUP (REGION_ID, REGION VALUES(5,'JAPAN');
/
INSERT INTO IND_REVENUE VALUES(1,'10-Jun',73.10,4);
INSERT INTO IND_REVENUE VALUES(2,'10-Jul',49.30,4);
INSERT INTO IND_REVENUE VALUES(3,'10-Jun',3.20,2);
INSERT INTO IND_REVENUE VALUES(4,'10-Jul',0.30,2);
INSERT INTO IND_REVENUE VALUES(5,'10-Jun',28.60,3);
INSERT INTO IND_REVENUE VALUES(6,'10-Jul',12.40,3);
INSERT INTO IND_REVENUE VALUES(7,'10-Jun',64.00,1);
INSERT INTO IND_REVENUE VALUES(8,'10-Jul',19.80,1);
INSERT INTO IND_REVENUE VALUES(9,'10-Jun',6.60,5);
INSERT INTO IND_REVENUE VALUES(10,'10-Jul',4.70,5);
/
Here's what I would get. The column date 10 - Jun 10 - Jul is 'dynamic', and there will be a new column each month.
Region     10-Jun     10-Jul      Total
APAC      $28.6     $12.4      $41.0
EMEA      $64.0     $19.8      $83.8     
JAPAN       $6.6      $4.7      $11.3
LAD       $3.2      $0.3       $3.5
NAS      $73.1     $49.3     $122.4
Total     $175.5     $86.5     $262.0
I think something like that (I'm stuck) but of course, this does not at all and is also hardcoded regarding columns.
select rn, 10-Jun, 10-Jul, (10-Jun + 10-Jul) as Total from
(select      RL.REGION_NAME as rn, RL.REGION as re, IR.IND_REVENUE as rev
 from      REGION_LOOKUP RL,
      IND_REVENUE IR where IR.region_id = RN.region_id)
pivot (SUM(rev) for rn in
('10-Jun' as 10-Jun,
'10-Jul' as 10-Jul))
All great ideas?

See you soon,.
Andy

Fixed the instructions insert, sorry about that. Copy and paste before the coffee is not good.

Hi, Andy.

A Tael says:
A nice solution,

Thanks, but what solution do you mean? There were at least 4 different solutions on this page.

but is there a way to avoid the queue to a file?

Do you mean the dynamic SQL solution? Yes, the coil is just a way to make the dynamic SQL statements.
In SQL * more you can write the variable part of the query to a substitution variable (see below).
In PL/SQL, you can assemble a select in VARCHAR2 variable.

PROMPT     ==========  2. Dynamic Pivot using Substitution Variable  ==========

--     *****  Preliminary Query:  *****

COLUMN     sql_txt_col     NEW_VALUE     sql_txt

WITH     all_jobs     AS
(
     SELECT DISTINCT
          job
     ,     DENSE_RANK () OVER (ORDER BY job)     AS r_num
     FROM     scott.emp
)
SELECT     SYS_CONNECT_BY_PATH ( job || '''     THEN 1 END) AS '
                      || job
                      || '_CNT'
                      || CHR (10)               -- Newline, for legibility only
                   , ', COUNT (CASE WHEN job = '''     -- Delimiter, goes before each entry
                   )                                       AS sql_txt_col
FROM     all_jobs
WHERE     CONNECT_BY_ISLEAF     = 1
START WITH     r_num = 1
CONNECT BY     r_num = PRIOR r_num + 1
;

--     *****  Main Query  *****

SELECT     deptno
&sql_txt     -- Ends with newline, so occupy that line
FROM     scott.emp
GROUP BY     deptno
ORDER BY     deptno
;

/*
EXPLANATION:

Using a substitution variable is very similar to using a script.
The main difference is that the output of the preliminary query has to
go into one row.  This is done with SYS_CONNECT_BY_PATH, and getting
that requires that the jobs be numbered with consecutive integers, 1, 2, 3, ...
which we get from DENSE_RANK.

The NEWLINE character was added just to make the output line easier
to read during debugging.
*/

Tags: Database

Similar Questions

  • XML PIVOT QUERY QUESTIONS

    I'm new to PIVOT queries.  I was making reference to the discussion that follows, but ran into a problem.  https://forums.Oracle.com/message/9393302

    When I added the XML to format data, I started to have NULL values rather than what I was looking for.

    WITH (AS PIVOT_DATA)

    SELECT * FROM)

    SELECT THE REGION, FCST_PERIOD, PRIME_PART, FINAL_FORECAST

    OF XYZ WHERE FCST_PERIOD > = last_day (trunc (sysdate)) + 1 and FCST_PERIOD < = last_day (add_months(sysdate,12)) AND PRIME_PART IN ('BLAH')

    )

    PIVOT XML (SUM (FINAL_FORECAST) FOR FCST_PERIOD IN (SELECT DISTINCT FCST_PERIOD OF XYZ))

    )

    SELECT PRIME_PART, REGION,

    EXTRACTVALUE(FCST_PERIOD_XML,'/PIVOTSET/ITEM[1]/COLUMN[2]') FCST_PERIOD1,

    EXTRACTVALUE(FCST_PERIOD_XML,'/PIVOTSET/ITEM[2]/COLUMN[2]') FCST_PERIOD2,

    EXTRACTVALUE(FCST_PERIOD_XML,'/PIVOTSET/ITEM[3]/COLUMN[2]') FCST_PERIOD3

    OF PIVOT_DATA;

    RESULTS IN:

    PRIME_PARTREGIONFCST_PERIOD1FCST_PERIOD2FCST_PERIOD3
    BLAMIDWEST(NULL)(NULL)(NULL)
    BLAWEST-NV(NULL)(NULL)(NULL)
    BLASOUTH-EAST(NULL)(NULL)(NULL)
    BLAWEST-CA(NULL)(NULL)(NULL)
    BLASOUTHWEST(NULL)(NULL)(NULL)
    BLAEAST(NULL)(NULL)(NULL)

    The second part of my question is how would I do a group when you use a pivot query.  When I finished, I've has several parts and would like to group by REGION.

    Thank you!

    Names of elements and attributes in XML are case-sensitive.

    Try with:

    EXTRACTVALUE (FCST_PERIOD_XML, ' / PivotSet/item [1] /column [2]') FCST_PERIOD1

    There is also a good chance that EXTRACTVALUE is frowned upon in your version. Instead, use XMLQuery or XMLTable.

    That being said, using XML PIVOT just to grind it later into a number known columns is pretty useless.

    The same can be achieved much more efficiently with regular PIVOT operator (and if necessary analytical function).

    Post some examples of data in the table of your database and your final result expected to get useful assistance.

  • Pivot query

    Hi all

    I wrote a pivot query but it is not giving me the expected output.

    with test as
    ( select 'outgoing' type_of_call, 'local' sub_type_call, '1sec' pulse, 0.3 call_charge from dual union all
      select 'outgoing' type_of_call, 'STD' sub_type_call, '2sec' pulse, 1.5 call_charge from dual union all
      select 'outgoing' type_of_call, 'ISD' sub_type_call, '1sec' pulse, 4 call_charge from dual union all
      select 'SMS' type_of_call, 'local' sub_type_call, '1' pulse, 0.5 call_charge from dual union all
      select 'SMS' type_of_call, 'STD' sub_type_call, '1' pulse, 1 call_charge from dual union all
      select 'SMS' type_of_call, 'ISD' sub_type_call, '1' pulse, 3 call_charge from dual
    )
    select * from test
    pivot(count(type_of_call) for (sub_type_call) in ('local','STD','ISD') );
    
    O/P should look like
    Type_of_call         pulse_local     charge_local  Pulse_STD   charge_STD  pulse_ISD  charge_isd
    outgoing             1sec            0.3            2sec        1.5         1sec        4
    SMS                  1               0.5            1           1           1           3
    
    
    
    

    Is there something that I am missing in the query?

    Thank you

    SID

    SQL> with test as
    ( select 'outgoing' type_of_call, 'local' sub_ty, '1sec' pulse, 0.3 call_charge from dual union all
      select 'outgoing' type_of_call, 'STD' sub_ty, '2sec' pulse, 1.5 call_charge from dual union all
      select 'outgoing' type_of_call, 'ISD' sub_ty, '1sec' pulse, 4 call_charge from dual union all
      select 'SMS' type_of_call, 'local' sub_ty, '1' pulse, 0.5 call_charge from dual union all
      select 'SMS' type_of_call, 'STD' sub_ty, '1' pulse, 1 call_charge from dual union all
      select 'SMS' type_of_call, 'ISD' sub_ty, '1' pulse, 3 call_charge from dual
    )
    select *
    from test
    pivot(max(CALL_CHARGE) as CALL_CHARGE, max(pulse) as pulse for (sub_ty) in ('local' as local,'STD' as std,'ISD' as isd) )
    order by type_of_call desc  2    3    4    5    6    7    8    9  10  11  12
    13  /
    
    TYPE_OF_ LOCAL_CALL_CHARGE LOCA STD_CALL_CHARGE STD_ ISD_CALL_CHARGE ISD_
    -------- ----------------- ---- --------------- ---- --------------- ----
    outgoing                .3 1sec            1.5 2sec              4 1sec
    SMS                    .5 1                  1 1                  3 1
    
  • Pivot query help

    need help on creating pivot query

    SELECT * FROM TEST1

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

    VALUE OF PERSON COMPUTERNAME

    COMP1                    ABC                     3

    COMP2                    ABC                     5

    COMP1                    CAD                     3

    COMP3                    CAD                     5

    COMP2                    TES                      1

    COMP1                    TES                      5

    COMP3                    ABC                      2

    myQuery

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

    Select the link null, label, value1 COUNT (VALUE)

    from 'test1 '.

    CONTROL group PER PERSON

    Results

    ---------

    Link label value1

    -                     ABC                     3

    -                     CAD                     2

    -                     TES                      2

    My requirement

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

    can we have something like that out using the concept of pivot? If so can you share an example query pls.


    Link label value1

    -ABC ORDI1, COMP2, COMP3

    -CAD COMP1, COMP2

    -YOUR ORDI1, COMP3

    Hello

    Subhash C-Oracle wrote:

    need help on creating pivot query

    SELECT * FROM TEST1

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

    VALUE OF PERSON COMPUTERNAME

    COMP1                    ABC                    3

    COMP2                    ABC                    5

    COMP1                    CAD                    3

    COMP3                    CAD                    5

    COMP2                    TES                      1

    COMP1                    TES                      5

    COMP3                    ABC                      2

    myQuery

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

    Select the link null, label, value1 COUNT (VALUE)

    from 'test1 '.

    CONTROL group PER PERSON

    Results

    ---------

    Link label value1

    -                    ABC                    3

    -                    CAD                    2

    -                    TES                      2

    My requirement

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

    can we have something like that out using the concept of pivot? If so can you share an example query pls.

    Link label value1

    -ABC ORDI1, COMP2, COMP3

    -CAD COMP1, COMP2

    -YOUR ORDI1, COMP3

    This sounds like a job for LISTAGG:

    SELECT NULL AS link

    label

    LISTAGG (comp_name, ',')

    THE Group (ORDER BY ComputerName) AS value1

    OF test1

    GROUP BY label

    ;

    If you would care to post CREATE TABLE and INSERT statements for your sample data, then I could test it.

    Are you sure that the results you posted are what you want from data provided?

    Is of the order of the elements in a significant list?  In other words, when you say you want to get the results:

    COMP1, COMP2

    you'd be just as happy with

    ORDI1, COMP2

    ?  If the order is important, explains what this order.

  • pivot query question

    I have a query in Oracle 11:
     select to_char(da,'DY-DD') days
    from (
            select rownum -1 + to_date('2012-10-15','yyyy-mm-dd') da, l
            from   (select level l
                    from   dual  connect by level <= to_date('2012-10-21','yyyy-mm-dd') - to_date('2012-10-15','yyyy-mm-dd')+1)
            order by 1) 
    Result
    "DAYS"
    MON-15
    TUE-16
    WED-17
    THU-18
    FRI-19
    SAT-20
    SUN-21
    What I need which is present in a row instead of a column:
     MON-15  TUE-16  WED-17  THU-18  FRI-19  SAT-20  SUN-21
    This should be done with pivot requests? Any suggestion please!
    Thanks in advance.

    Hello

    user564819 wrote:
    I need in 7 different columns.
    Oracle version is 11.2.0.1.0. Could you give an example of how to do this with pivot query?

    Here's one way:

    WITH     all_days     AS
    (
         SELECT     LEVEL  AS n
         ,     TO_CHAR ( TO_DATE ('2012-10-15','yyyy-mm-dd') + LEVEL - 1
                   , 'DY-DD'
                   )     AS dy_dd
         FROM    dual
         CONNECT BY  LEVEL <= TO_DATE ('2012-10-21','yyyy-mm-dd') + 1
                            - TO_DATE ('2012-10-15','yyyy-mm-dd')
    )
    SELECT     *
    FROM     all_days
    PIVOT     ( MIN (dy_dd)
           FOR  n  IN (  1  AS col_1
                          ,  2  AS col_2
                          ,  3  AS col_3
                          ,  4  AS col_4
                          ,  5  AS col_5
                          ,  6  AS col_6
                          ,  7  AS col_7
                          ,  8  AS col_8
                          ,  9  AS col_9
                          , 10  AS col_10
                   )
          )
    ;
    

    This always displays exactly 10 columns.
    If the subquery produces less than 10 dates, then the last columns will be NULL.
    If the subquery produces more than 10 dates, will be not shown the 11th (and later versions).

    There is nothing special about the number 10; You can have any number of columns you want. The number of columns and their names is fixed when you write the query, regardless of what is in the subquery. If you want a dynamic number of columns, or names derived from data, see {message identifier: = 3527823}

  • Getting counties and divide by the sum in a single Pivot query

    Hello

    I have a pivot query that gives counties of all codes. I have also separated the number with the total in the same query.
    e.g
    
      col1          col2                   col3
    error_1       05-Jun-2012       parts
    error_1      05_june_2012     parts
    error_1      04_june_2012     consumables
    error_2      04_june_2012     consumables
    error_3      03_june_2012     parts
    .
    .
    .
    Now, the output should have the counts / divided into sum multiplied by 100. Basically, the percentage.


    output will be something like
    error                     June-2012                                 May-2012                              Feb-2012 ....      headers
    error_1                    60%                                          0 %                                         0%
    error_2                    20%                                          0                                             0%
    error_3                    20%                                           0%                                         0%
    Any suggestions please?


    Thank you
    Sun
    with
    t1 as
    (select 'error_1' col1,trunc(sysdate) - 1 col2 from dual union all
     select 'error_1',trunc(sysdate) - 1 from dual union all
     select 'error_1',trunc(sysdate) + 30 from dual union all
     select 'error_2',trunc(sysdate) + 31 from dual union all
     select 'error_3',trunc(sysdate) - 2 from dual union all
     select 'error_3',trunc(sysdate) + 30 from dual union all
     select 'error_1',trunc(sysdate) - 3 from dual union all
     select 'error_2',trunc(sysdate) - 2 from dual union all
     select 'error_3',trunc(sysdate) + 30 from dual union all
     select 'error_4',trunc(sysdate) - 6 from dual
    )
    select col1,
           count(case to_char(col2,'mon') when 'jul' then 1 end) one,
           100 * ratio_to_report(count(case to_char(col2,'mon') when 'jul' then 1 end)) over () x,
           count(case to_char(col2,'mon') when 'jun' then 1 end) two,
           100 * ratio_to_report(count(case to_char(col2,'mon') when 'jun' then 1 end)) over () y
      from t1
     group by col1
     order by col1
    

    Concerning

    Etbin

    Edited by: Etbin on 8.6.2012 14:15
    used month next to keep English and slovene "LUN" same ;)

  • pivot table problem

    create the table mytable
    (
    name varchar2 (50).
    name varchar2 (50)
    )

    Insert the table mytable values ('mary', 'john')
    Insert the table mytable values ('mary', 'baby')
    Insert the table mytable values ('mary', 'lady')
    Insert the table mytable values ('sean', 'kate')
    Insert the table mytable values ('sean', 'terry')
    Insert the table mytable values ('kate', 'tom')
    Insert the table mytable values ('kate', 'lary')
    .
    .
    .

    my result of the query is

    last name first name
    Jean-Marie
    baby Marie
    Lady Mary
    Sean kate
    Sean Terry
    Tom Kate
    Kate lary

    I want to like this

    Mary kate sean

    John tom kate
    baby terry lary
    Lady


    It's not all data.
    the data are changeable.there are 3 name as name like sean John 2 2 lik kate and it will be 5 name like paul... I want as column name and surname as the data...
    Thanks for your help...

    Hello

    Try this:

    WITH     number_rows     AS
    (
         SELECT     name
         ,     surname
         ,     ROW_NUMBER () OVER
                   (     PARTITION BY     name
                        ORDER BY     surname
                   )     AS r_num
         FROM     mytable
    )
    SELECT     r_num
    ,     MAX (CASE WHEN name = 'mary'     THEN surname END)     AS mary
    ,     MAX (CASE WHEN name = 'sean'     THEN surname END)     AS sean
    ,     MAX (CASE WHEN name = 'kate'     THEN surname END)     AS kate
    FROM     number_rows
    GROUP BY     r_num
    ORDER BY     r_num;
    

    The output is not quite what you asked:

    .    R_NUM MARY       SEAN       KATE
    ---------- ---------- ---------- ----------
             1 baby       kate       lary
             2 jon        terry      tom
             3 lady
    

    You do not have to display r_num: I showed just to make things easier to understand.
    If the output should really include "Jean" rather than "jon", or if it should appear above 'baby', rather than below, so please explain.

    If the names in columns ("Mary", "sean" and "kate" in your sample data) should be determined at run time, you need dynamic SQL statements to generate a statement like the one above.
    The script below shows one way to do this in SQL * more.

    /*
    How to Pivot a Table with a Dynamic Number of Columns
    
    This works in any version of Oracle
    The "SELECT ... PIVOT" feature introduced in Oracle 11
    is much better for producing XML output.
    
    Say you want to make a cross-tab output of
    the scott.emp table.
    Each row will represent a department.
    There will be a separate column for each job.
    Each cell will contain the number of employees in
         a specific department having a specific job.
    The exact same solution must work with any number
    of departments and columns.
    (Within reason: there's no guarantee this will work if you
    want 2000 columns.)
    
    Case 0 "Basic Pivot" shows how you might hard-code three
    job types, which is exactly what you DON'T want to do.
    Case 1 "Dynamic Pivot" shows how get the right results
    dynamically, using SQL*Plus.
    (This can be easily adapted to PL/SQL or other tools.)
    */
    
    PROMPT     ==========  0. Basic Pivot  ==========
    
    SELECT     deptno
    ,     COUNT (CASE WHEN job = 'ANALYST' THEN 1 END)     AS analyst_cnt
    ,     COUNT (CASE WHEN job = 'CLERK'   THEN 1 END)     AS clerk_cnt
    ,     COUNT (CASE WHEN job = 'MANAGER' THEN 1 END)     AS manager_cnt
    FROM     scott.emp
    WHERE     job     IN ('ANALYST', 'CLERK', 'MANAGER')
    GROUP BY     deptno
    ORDER BY     deptno
    ;
    
    PROMPT     ==========  1. Dynamic Pivot  ==========
    
    --     *****  Start of dynamic_pivot.sql  *****
    
    -- Suppress SQL*Plus features that interfere with raw output
    SET     FEEDBACK     OFF
    SET     PAGESIZE     0
    
    SPOOL     p:\sql\cookbook\dynamic_pivot_subscript.sql
    
    SELECT     DISTINCT
         ',     COUNT (CASE WHEN job = '''
    ||     job
    ||     ''' '     AS txt1
    ,     'THEN 1 END)     AS '
    ||     job
    ||     '_CNT'     AS txt2
    FROM     scott.emp
    ORDER BY     txt1;
    
    SPOOL     OFF
    
    -- Restore SQL*Plus features suppressed earlier
    SET     FEEDBACK     ON
    SET     PAGESIZE     50
    
    SPOOL     p:\sql\cookbook\dynamic_pivot.lst
    
    SELECT     deptno
    @@dynamic_pivot_subscript
    FROM     scott.emp
    GROUP BY     deptno
    ORDER BY     deptno
    ;
    
    SPOOL     OFF
    
    --     *****  End of dynamic_pivot.sql  *****
    
    /*
    EXPLANATION:
    The basic pivot assumes you know the number of distinct jobs,
    and the name of each one.  If you do, then writing a pivot query
    is simply a matter of writing the correct number of ", COUNT ... AS ..."\
    lines, with the name entered in two places on each one.  That is easily
    done by a preliminary query, which uses SPOOL to write a sub-script
    (called dynamic_pivot_subscript.sql in this example).
    
    The main script invokes this sub-script at the proper point.
    In practice, .SQL scripts usually contain one or more complete
    statements, but there's nothing that says they have to.
    This one contains just a fragment from the middle of a SELECT statement.
    
    Before creating the sub-script, turn off SQL*Plus features that are
    designed to help humans read the output (such as headings and
    feedback messages like "7 rows selected.", since we do not want these
    to appear in the sub-script.
    Turn these features on again before running the main query.
    
    */
    
  • foreign key ALTER TABLE QUERY PROBLEM

    HAI ALL,

    ANY SUGGESTION PLEASE?

    UNDER: foreign key ALTER TABLE QUERY PROBLEM

    I want TO CREATE AND ALTER TABLE foreign key:

    1.TABLE:HAEMATOLOGY1
    COLUMN: HMTLY_PATIENT_NUM
    WITH
    TABLE: PATIENTS_MASTER1
    COLUMN: PATIENT_NUM (THIS IS THE KEY PRIMARY AND UNIQUE)

    1.TABLE:HAEMATOLOGY1
    COLUMN: HMTLY_TEST_NAME
    WITH
    TABLE: TESTS_MASTER1
    COLUMN: TEST_NAME ((C'EST LA CLÉ UNIQUE))
    ---------------


    SQL + QUERY DATA:
    -----------
    ALTER TABLE HAEMATOLOGY1
    Key constraint SYS_C002742_1 foreign (HMTLY_PATIENT_NUM)
    references PATIENTS_MASTER1 (PATIENT_NUM);

    ERROR on line 2:
    ORA-01735: invalid option of ALTER TABLE

    NOTE: THE NAME OF THE CONSTRAINTS: SYS_C002742_1 TAKEN FROM ORACLE ENTP TABLE DETAILS. MGR.
    ---------
    ALTER TABLE HAEMATOLOGY1
    Key constraint SYS_C002735_1 foreign (HMTLY_TEST_NAME)
    references TESTS_MASTER1 (TEST_NAME);

    ERROR on line 2:
    ORA-01735: invalid option of ALTER TABLE

    NOTE: THE NAME OF THE CONSTRAINTS: SYS_C002735_1 TAKEN FROM ORACLE ENTP TABLE DETAILS. MGR.

    ==============

    4 TABLES OF LABORATORY CLINIC FOR DATA ENTRY AND GET REPORT ONLY FOR THE TESTS CARRIED OUT FOR PARTICULAR

    PATIENT.

    TABLE1:PATIENTS_MASTER1
    COLUMNS: PATIENT_NUM, PATIENT_NAME,

    VALUES:
    PATIENT_NUM
    1
    2
    3
    4
    PATIENT_NAME
    BENAMER
    GIROT
    KKKK
    PPPP
    ---------------
    TABLE2:TESTS_MASTER1
    COLUMNS: TEST_NUM, TEST_NAME

    VALUES:
    TEST_NUM
    1
    2
    TEST_NAME
    HEMATOLOGY
    DIFFERENTIAL LEUKOCYTE COUNT
    -------------

    TABLE3:HAEMATOLOGY1
    COLUMNS:
    HMTLY_NUM, HMTLY_PATIENT_NUM, HMTLY_TEST_NAME, HMTLY_RBC_VALUE, HMTLY_RBC_NORMAL_VALUE

    VALUES:
    HMTLY_NUM
    1
    2
    HMTLY_PATIENT_NUM
    1
    3
    MTLY_TEST_NAME
    HEMATOLOGY
    HEMATOLOGY
    HMTLY_RBC_VALUE
    5
    4
    HMTLY_RBC_NORMAL_VALUE
    4.6 - 6.0
    4.6 - 6.0
    ------------

    TABLE4:DIFFERENTIAL_LEUCOCYTE_COUNT1
    COLUMNS: DLC_NUM, DLC_PATIENT_NUM, DLC_TEST_NAME, DLC_POLYMORPHS_VALUE, DLC_POLYMORPHS_

    NORMAL_VALUE,

    VALUES:
    DLC_NUM
    1
    2
    DLC_PATIENT_NUM
    2
    3
    DLC_TEST_NAME
    DIFFERENTIAL LEUKOCYTE COUNT
    DIFFERENTIAL LEUKOCYTE COUNT
    DLC_POLYMORPHS_VALUE
    42
    60
    DLC_POLYMORPHS_NORMAL_VALUE
    40-65
    40-65
    -----------------


    Thank you
    RCS
    E-mail:[email protected]
    --------

    ALTER TABLE HAEMATOLOGY1
    ADD Key constraint SYS_C002742_1 foreign (HMTLY_PATIENT_NUM)
    references PATIENTS_MASTER1 (PATIENT_NUM);

  • PIVOT query throwing error

    I have a request pivot within a region of APEX (pl sql function return sql query) report

    declare
      v_term_pivot varchar2(500);
      PIVIN LONG;
      cursor xtoy is SELECT distinct d.JOB FROM emp d;
      v_query LONG;
    begin
      OPEN xtoy;
      LOOP
      FETCH xtoy into v_term_pivot;
      EXIT when xtoy%NOTFOUND;
      PIVIN:=PIVIN||''''||v_term_pivot||''' "'||substr(v_term_pivot,1,30)||'", ';
      END LOOP;
      v_query:='SELECT * FROM
      (SELECT x.ENAME, x.JOB, x.SAL FROM emp x)
      PIVOT (
      SUM(x.SAL)
      FOR x.JOB IN ('||substr(PIVIN, 0, length(PIVIN)-1)||')
      )
       order by 1;';
      --dbms_output.put_line(v_query);
      RETURN v_query;
    end;
    
    

    Get an error:

    Failed to parse the SQL query:

    ORA-01748: only here allowed simple column names

    Can someone advice how can this be corrected?

    I reworked the code to use the scott. EMP table.

    I got the SQL Select function resulting and he ran in SQL Developer.

    Syntax 1

    You must remove aliases for tables of the PIVOT() section.

    line 16 and 17 should be

    SUM (SAL)

    FOR USE IN (...)

    Syntax 2

    Line 11: you add comma and space (2 characters)

    Line 17: you remove only 1 tank

    Syntax 3 (problem semi)

    Although the APEX works with it, I would abandon the semicolon (;) to the end.

    To name the columns, you must create a function that returns the name of the report column.

    Again, this must match the columns listed in the SELECT part

    reminder of my warning:

    Using a "SELECT *" and lack of "ORDER BY" in your cursor will cause you problems. (maybe not now, but it will.)

    MK

  • Eurotherm EPower controller: query problem

    Hello

    I have a problem with communicating with a controller Eurotherm EPower (with 4 units) by OPC server.

    I use:

    -LV 8.5.1

    -iTools OPC Server 7.50 with a number of product formed the social reason (active license)

    -EPower Firmware v3.01

    Communication between LV and OPC server is made by "DataSocket write" and "Read DataSocket".

    I can write => values without problem I only write Main.SP on the evolution of events user and everything's fine.

    But on reading, I would like to read Meas.I Meas.P, Meas.V, continuous for each unit (up to 12 url request)

    The first reading is ok, so I have values, the url are ok. But after that, it is impossible to put in a loop-online no error, (status = 0 on LV and OPC Server) but the values are not updated with the following query.

    I tried to play with the option "wait for updated value", but without success.

    The only way I've found is to open the interface for server, the device, right click and select "Synchronize Active device". But this option is only a shot and very long because, I guess, he gets everything in the device...

    Another point: it works perfectly with the Engineering Studio, commonly called iTools-iTools. It is a client of the OPC server on my application.

    Another point on the other: when I run my application is the ID_EPower.exe in the list of Windows processes and consume resources (0 or 1%) so he lives.

    Complete, with one hour, I thank them but not way with Eurotherm hotline.

    My question is: Y at - it a particular way to obtain ongoing measures such as sending a query each time or a general property to get updated data?

    I used to cruise control disc from the same manufacturer with no problem and no need to send a request to get the values, but here it is perhaps a different case.

    List of requested URL:

    OPC:/Eurotherm.ModbusServer.1/CLA_Gradateurs.192-168-1-222-502-ID001-ePower.network.1.MEAs.V

    OPC:/Eurotherm.ModbusServer.1/CLA_Gradateurs.192-168-1-222-502-ID001-ePower.network.1.MEAs.I

    OPC:/Eurotherm.ModbusServer.1/CLA_Gradateurs.192-168-1-222-502-ID001-ePower.network.1.MEAs.P

    OPC:/Eurotherm.ModbusServer.1/CLA_Gradateurs.192-168-1-222-502-ID001-ePower.network.2.MEAs.V

    OPC:/Eurotherm.ModbusServer.1/CLA_Gradateurs.192-168-1-222-502-ID001-ePower.network.2.MEAs.I

    OPC:/Eurotherm.ModbusServer.1/CLA_Gradateurs.192-168-1-222-502-ID001-ePower.network.2.MEAs.P

    ... Ditto for network 3 and 4

    I joined the part of the code that is dedicated for the reading of values, but it is not really helpful because I think that my method of reading is correct (data arrive but are never updated) is a 'lack' of command to request that the server acquires new data or a bug with the LV-iTools OPC server interface...

    For LabViewers advanced, I know that my attached code is not optimized and not the smartest, but keep cool, I do not need crazy performance

    Any suggestion?

    So, I was not on the spot for the tests, but now it's ok.

    Several series shares have been made to the walkthrough to the problem, but it's hard to know if all were beneficial:

    -An update of software Eurotherm: 7.50 to 7.68

    -An update of the firmware EPower: 3.01 to 3.03

    - and probably the main cause of the problem: change the cable through a cross-wired (we thought it was, but not in reality...). But even if it is the main cause: how it was possible to receive data by forcing the update in the OPC server... strange.

    Thanks for your help.

  • Printable report query problem

    I try to develop a printable report query. I created a report under shared components query which consists of 12 separate queries that collect data are all related to a single page element. The intention is to create a PDF document that is printed to the user on demand that will display all this information on the page element they have chosen.

    The query of the report gathers information and generates an XML file in the following format.
    <DOCUMENT>
        <ROWSET1>
            <ROWSET1_ROW>
                             *Data from query 1*
            </ROWSET1_ROW>
        </ROWSET1>  
        <ROWSET2>
            <ROWSET2_ROW>
                              *Data from query 2*
            </ROWSET2_ROW>
            <ROWSET2_ROW>
                              * Data from query 2*
            </ROWSET2_ROW>
       </ROWSET2>
       <ROWSET3>
           <ROWSET3_ROW>
                              * Data from query 3*
           </ROWSET3_ROW>
           <ROWSET3_ROW>
                              * Data from query 3*
           </ROWSET3_ROW>
       </ROWSET3>
    ......
    </DOCUMENT>
    Then, I took this XML file and developed a model RTF using Office BI Publisher and imported as a layout of the report.
    I then connected this provision of the RTF to the report query and he ran. I don't have all the data to print.

    I found the reason why that it did not work, it is that the XML file that is generated by the report query is not static. The following XML file that was generated by the report query looked like this:
    <DOCUMENT>
        <ROWSET1>
            <ROWSET1_ROW>
                               * Data from query 3*
            </ROWSET1_ROW>
            <ROWSET1_ROW>
                               * Data from query 3*
            </ROWSET1_ROW>
        </ROWSET1>  
        <ROWSET2>
            <ROWSET2_ROW>
                               * Data from query 7*
            </ROWSET2_ROW>
            <ROWSET2_ROW>
                               * Data from query 7*
            </ROWSET2_ROW>
            <ROWSET2_ROW>
                               * Data from query 7*
            </ROWSET2_ROW>
       </ROWSET2>
       <ROWSET3>
           <ROWSET3_ROW>
                               * Data from query 1*
           </ROWSET3_ROW>
       </ROWSET3>
    ......
    </DOCUMENT>
    So I can't develop a RTF model to display the data, if I do not know where these data will appear in the generated XML.

    Questions (I'll offer several POINTS to anyone who can answer all of these questions!)

    I use APEX version 3.1

    * 1. Why the report query seems randomly to renumber and reorganize the XML it produces? *

    * 2. Is it possible to make the report query to display the XML data in the order in which the individual queries are classified each time? *

    * 3. Is it possible to designate exactly the lines of sets of lines or lines supported by APEX? *

    * 4. Are there other methods can I Explorer to produce this report? *

    * 5. Is it a problem because I'm on an older version? Is it not a problem on 4.1? *

    Published by: bhenderson on February 1, 2012 08:22

    So, you have 12 separate petitions? No there is no way to join them in a union to build the required data set? Or even using views inline in a query for each set of values?

    Thank you

    Tony Miller
    Webster, TX

  • Format for a number field in af:query problem. Is this a Bug of the ADF?

    Hi, OTN,.

    Requirement: Format DepartmentId in query Panel

    I created a view of criteria of the Employees (HR diagram) table. I have four items in the view criteria called EmployeeId, DepartmentId, Firstname, LastName and all elements including the posting as selectively requiredproperty. Attribute DepartmentId have Format Type of the property UI tips = number and Format = * 0000 * and Auto submit = true.
    But in the user interface, I'm not able to search the af:Query Panel. It works fine without setting the property UI tips Format and Type of format *.

    Step 1: Type 123 in the DepartmentId field
    Step 2: Click on the search button
    Error: Please provide a value for at least one of the specified areas
    Error message: http://www.freeimagehosting.net/24d51

    Please see the link for downloading the sample application below

    http://formatissue.googlecode.com/svn/trunk/FormatTest/FormatTest.zip
    http://formatissue.googlecode.com/svn/trunk/FormatTest (SVN version)

    Note:

    JDev Version: 11.1.1.5.0
    I use BC ADF and ADF Faces components

    All of the recommendations fully appreciated

    Thank you
    Jean-Marc Mithra

    Published by: Fanny Mithra November 23, 2011 16:51

    Published by: Fanny Mithra November 23, 2011 17:21

    Has filed a bug, bug # copied to the end of this thread - edited previous comment, the problem occurs even on release after 11.1.1.5.0.

    Published by: Jobinesh on December 2, 2011 10:38

  • Sort on dynamic query problem!

    Hello

    I have a dynamic query written in pl/sql, when I check "Sort" for each field in the report attribute, error message resurrected as "ORA-01785: ORDER BY item must include the number of an expression in the SELECT list.
    If I do not check sort, it works very well. In my applications, I need all the fields sorted by user, how do I solve this problem?

    My query as below:

    declare
    Ask varchar2 (2000): = "select";
    s_class varchar2 (1000);
    cursor c1 is select * from demo_preference;
    Start
    for c1_val looping c1
    If c1_val.login is not null then
    query: query = | » ' || 'login ' | ',';
    end if;
    If c1_val.id is not null then
    query: query = | » ' || 'id ' | ',';
    end if;
    .......
    end loop;
    query: = SUBSTR (query, 1, length (query)-1);

    s_class: = ' (NVL (: P2_class, "%" |)) ''null%'') = ''%'' || "zero percent" OR
    EXISTS (SELECT 1 FROM apex_collections WHERE collection_name = "P2CLASSCOL" AND class = c001))';

    query: query = | » ' || ' from ming.reg_report_view1 where '.
    || ' ' || s_class;
    Return (Query);
    end;

    Maybe the internal column used when you clicked the sort is not indicated in the report. Try to use aliases when you build the query string, it might help apex internally to identify a column even if its order is changed to another user. After all, the order of the columns in the code is dynamic and I assume that even the number of displayed columns can vary that could sort on a column that is identified by a number not valid.

    How about somewhere, displaying the report query so that you know what is the exact query processing, it could give you the best information on the problem.

    If the problem persists, use a collection that is extracted these record using the same query string, then replace the report to view the collection and then set the sort column on. This way Summit could get confused about which columns are being sorted and it would just sort on a c001... C050 column as if it were a string (Yes problems with the number of sort columns when you do this).

  • Sub query problem

    Hi all

    Problem with sub query.

    Select * from where the team team_id in (team_id region selection);

    If I run the query above is the length, but the problem is that I don't have team_id in the region table. How oracle to run this query. Please explain.

    If I run select region team_id;

    I got error like team_id invalid.


    I'm using the version of oracle 10g.


    Thank you.

    Sunita.

    sunitha2010 wrote:
    Hi all

    Problem with sub query.

    Select * from where the team team_id in (team_id region selection);

    If I run the query above is the length, but the problem is that I don't have team_id in the region table. How oracle to run this query. Please explain.

    Because of the determination of the scope.
    Oracle uses the "team_id" of the outer query.

    If you were to use:

    select * from team  where team_id in (select region.team_id from region);
    

    THEN, you will get an error.

  • Insert query problem

    I have an insert query that I have not changed, but for some reason it won't insert anything in the database.

    The data is entered by a form of Ajax submission and goes to insert.php

    {if (isset($_POST['message_wall']))}
    / * The database connection * /.
    include ('config.php');

    / * Remove the HTML tag to prevent the injection of the query * /.
    $message = mysql_real_escape_string($_POST['message_wall']);
    $to = mysql_real_escape_string($_POST['profile_to']);

    $sql = "INSERT INTO wall (VALUES) (message)
    « '. $message. " »)';
    mysql_query ($SQL);

    I want to be able to add a user_id in the database too

    The ajax code:

    $(document) .ready (function () {}
    {$("form#submit_wall").submit (function ()}

    var message_wall is $('#message_wall').attr ('value');.

    $.ajax({)
    type: 'POST',
    URL: "insert.php"
    data: "message_wall ="+ message_wall, ".
    success: function() {}
    $("ul#wall").prepend ("< style li =' display: none" > "+ message_wall +"< /li > < br > < HR >");
    $("ul #wall li:first").fadeIn();)
    }
    });
    Returns false;
    });
    });

    Hello

    As it is a form ajax post then the form data should be inserted into your database using the insert.php script. All in the form of ajax jQuery is passed to the script of treatment if you process in the insert script it should work o/k.

    You must then include a text response to aid a statement simple echo in your insert script, this should include everything that you want to appear on your page.

    Php in your insert script would be similar to.

    At the beginning of the script.

    $date = $_POST ['msg_date'];

    At the bottom of the script.

    If {($success)
    echo "Inserted on $date ';
    } else {}
    echo "there was a problem processing your information.';
    }

    The jQuery to achieve code would be-

    Perform tasks of post-tabling
    function showResponse (responseText, statusText) {}
    $('.response').text (responseText);
    }

    More-

    success: showResponse,

    Treatment options in your ajax form

    And just include a

    where you want to display in your html code.

    PZ

    www.pziecina.com

Maybe you are looking for