Multiple subqueries

I am trying to do an update with mutiple sub queries. Our product uses oracle, mysql, and MSsql databases. I have got the following to work in mysql and mssql, but not in oracle.
UPDATE table_1 SET table_1.field_1 = (SELECT SUM(amount) FROM table_2 WHERE table_2.condition='A') - (SELECT SUM(amount) FROM table_2 WHERE table_2.condition='B') WHERE table_1.recid = 1
I need to update a field in table_1 with a value from table_2 minus another value from table_2.
I have also tried with success in mysql and mssql but not in oracle:
UPDATE table_1 SET table_1.field_1 = (SELECT SUM(amount) - (SELECT SUM(amount) FROM table_2 WHERE table_2.condition='B') FROM table_2 WHERE table_2.condition='A') WHERE table_1.recid = 1
Thanks in advance for your help.
Chris

When you say it doesn't work, what do you mean? Does it throw an error or are the results not as expected.
Also what version of Oracle are you working on?
SELECT * FROM v$versionLooking at the query, it could be simplified to get rid of 2 table accesses for table_2...
UPDATE table_1
   SET table_1.field_1 =
          (SELECT SUM (CASE
                            WHEN table_2.condition = 'A' THEN
                                amount
                       END
                       ) - SUM( CASE
                                    WHEN table_2.condition = 'B' THEN
                                        amount
                                END
             FROM table_2
            WHERE table_2.condition IN ('A','B'))
WHERE table_1.recid = 1HTH
David

Similar Messages

  • Error using multiple subqueries in a from statement - sorry so long

    From the query below, my results should only be 3 rows but, for whatever reason, I'm getting 3 of each operation number. Can someone PLEASE tell me why this is looking more than once?
    Version - Oracle 9i
    Here's the query
    select base.equivalent_operation_number, ((pip.operation_count/PIPInject.op_inject_count) - (base.operation_count/baseInjecT.Op_inject_count)) as Read_Rate_Difference
    from
    (select T2.EQUIVALENT_OPERATION_NUMBER, count(T2.EQUIVALENT_OPERATION_NUMBER) as operation_count
    FROM
    OPERATION_NUMBER_MAPPING T2, IMAGE_DATA T1, BASELINE_JK T3
    WHERE
    (T3.IMAGE_NAME=T1.IMAGE_NAME AND LENGTH(T3.POSTNET_CODE) > 1)
    AND
    (T1.USPS_OPERATION_NUMBER IN T2.USPS_OPERATION_NUMBER)
    GROUP BY T2.EQUIVALENT_OPERATION_NUMBER) base,
    (select T2.EQUIVALENT_OPERATION_NUMBER, count(T2.EQUIVALENT_OPERATION_NUMBER) as operation_count
    FROM
    OPERATION_NUMBER_MAPPING T2, IMAGE_DATA T1, PIP_JK T3
    WHERE
    (T3.IMAGE_NAME=T1.IMAGE_NAME AND LENGTH(T3.POSTNET_CODE) > 1)
    AND
    (T1.USPS_OPERATION_NUMBER IN T2.USPS_OPERATION_NUMBER)
    GROUP BY T2.EQUIVALENT_OPERATION_NUMBER)pip,
    (select t2.equivalent_operation_number, count(T2.EQUIVALENT_OPERATION_NUMBER) as op_inject_count
    FROM
    OPERATION_NUMBER_MAPPING T2, IMAGE_DATA T1, BASELINE_JK T3
    WHERE
    T3.IMAGE_NAME=T1.IMAGE_NAME
    AND
    (T1.USPS_OPERATION_NUMBER IN T2.USPS_OPERATION_NUMBER)
    GROUP BY T2.EQUIVALENT_OPERATION_NUMBER) BaseInject,
    (select t2.equivalent_operation_number, count(T2.EQUIVALENT_OPERATION_NUMBER) as OP_Inject_count
    FROM
    OPERATION_NUMBER_MAPPING T2, IMAGE_DATA T1, PIP_JK T3
    WHERE
    T3.IMAGE_NAME=T1.IMAGE_NAME
    AND
    (T1.USPS_OPERATION_NUMBER IN T2.USPS_OPERATION_NUMBER)
    GROUP BY T2.EQUIVALENT_OPERATION_NUMBER)PIPInject
    where base.equivalent_operation_number = pip.equivalent_operation_number
    AND
    baseinject.op_inject_count = pipinject.op_inject_count;
    Here's the results which should only return 3 rows.
    EQUIVALENT_OPERATION_NUMBER READ_RATE_DIFFERENCE
    0 -.01728723
    0 -.00131154
    0 -.00010203
    894 -.07047872
    894 -.00041597
    894 -.00534705
    895 -.68284574
    895 -.00403019
    895 -.05180589
    9 rows selected.
    Here's the explain plan
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE
    1 0 MERGE JOIN
    2 1 SORT (JOIN)
    3 2 NESTED LOOPS
    4 3 MERGE JOIN
    5 4 SORT (JOIN)
    6 5 VIEW
    7 6 SORT (GROUP BY)
    8 7 NESTED LOOPS
    9 8 NESTED LOOPS
    10 9 TABLE ACCESS (FULL) OF 'PIP_JK'
    11 9 TABLE ACCESS (BY INDEX ROWID) OF 'IMAGE_
    DATA'
    12 11 INDEX (UNIQUE SCAN) OF 'XPKIMGDATA' (U
    NIQUE)
    13 8 TABLE ACCESS (BY INDEX ROWID) OF 'OPERATIO
    N_NUMBER_MAPPING'
    14 13 INDEX (UNIQUE SCAN) OF 'XPKOPNUM' (UNIQU
    E)
    15 4 SORT (JOIN)
    16 15 VIEW
    17 16 SORT (GROUP BY)
    18 17 NESTED LOOPS
    19 18 NESTED LOOPS
    20 19 TABLE ACCESS (FULL) OF 'BASELINE_JK'
    21 19 TABLE ACCESS (BY INDEX ROWID) OF 'IMAGE_
    DATA'
    22 21 INDEX (UNIQUE SCAN) OF 'XPKIMGDATA' (U
    NIQUE)
    23 18 TABLE ACCESS (BY INDEX ROWID) OF 'OPERATIO
    N_NUMBER_MAPPING'
    24 23 INDEX (UNIQUE SCAN) OF 'XPKOPNUM' (UNIQU
    E)
    25 3 VIEW
    26 25 SORT (GROUP BY)
    27 26 NESTED LOOPS
    28 27 NESTED LOOPS
    29 28 TABLE ACCESS (FULL) OF 'PIP_JK'
    30 28 TABLE ACCESS (BY INDEX ROWID) OF 'IMAGE_DATA
    31 30 INDEX (UNIQUE SCAN) OF 'XPKIMGDATA' (UNIQU
    E)
    32 27 TABLE ACCESS (BY INDEX ROWID) OF 'OPERATION_NU
    MBER_MAPPING'
    33 32 INDEX (UNIQUE SCAN) OF 'XPKOPNUM' (UNIQUE)
    34 1 SORT (JOIN)
    35 34 VIEW
    36 35 SORT (GROUP BY)
    37 36 NESTED LOOPS
    38 37 NESTED LOOPS
    39 38 TABLE ACCESS (FULL) OF 'BASELINE_JK'
    40 38 TABLE ACCESS (BY INDEX ROWID) OF 'IMAGE_DATA'
    41 40 INDEX (UNIQUE SCAN) OF 'XPKIMGDATA' (UNIQUE)
    42 37 TABLE ACCESS (BY INDEX ROWID) OF 'OPERATION_NUMB
    ER_MAPPING'
    43 42 INDEX (UNIQUE SCAN) OF 'XPKOPNUM' (UNIQUE)
    Statistics
    0 recursive calls
    0 db block gets
    4432694 consistent gets
    84423 physical reads
    0 redo size
    958 bytes sent via SQL*Net to client
    425 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    8 sorts (memory)
    0 sorts (disk)
    9 rows processed

    Yeah, I can see why it didn't return any rows... here's what I need:
    Is get the difference between counts from two tables where there are two conditions(numerator is one conditon and the denomenator is another condition) based on matching operation numbers.
    Condition #1 table 1
    OpNum Count
    1 1000
    2 500
    3 200
    Condition #2 table 1
    OpNum Count
    1 500
    2 700
    3 150
    Condition #1 table 2
    OpNum Count
    1 500
    2 300
    3 450
    Condition #2 table 2
    OpNum Count
    1 500
    2 300
    3 450
    The formula
    Conditions applied to each operation number in each table
    (table1.conditon#1/table1.condition#2) - (table2.condition#1/table2.condition#2)

  • Help with multiple subqueries

    Hi guys
    i need to create report using this sql query... i am able to create individual report using OBIEE but need to get figures from both queries in one report... so to achieve this i wrote sql in advanced tab but after running biserver never returns back and after 10 min it gives an oracle error of out of temp tablespace... i have tried after increasing tablespace in db as well but no joy...
    Please help me how can i create this report in obiee.
    Thanks & Regards
    select distinct a.cust_t, c.cust_n, a.region from
    (select count( distinct cust_id)cust_t, s.region from
        fact i, time_dim m, region_dim s
    where i.time_code = m.time_code
        and i.region_code = s.region_code
        and i.region_code in ('03','06')
        and m.year between '2009' and '2010'
        and i.cust_id is not null
    group by region) a,
    (select distinct count(distinct a.cust_id) emp_n, s.region   
    from   fact a, time_dim x, order_status_dim m, region_dim s
    where  a.time_code = x.time_code
        and a.ord_status_code = m.ord_status_code
        and a.region_code = s.region_code
        and x.year between '2009' and '2010'
        and s.region_code in ('03','06')
        and a.cust_id is not null
        and not exists (  select b.cust_id
                         from   fact b, order_status_dim y,time_dim z
                         where  b.ord_status_code = y.ord_status_code
                         and y.ord_status_code ='O'
                         and z.time_code = b.time_code
                         and z.year between '2009' and '2010'
                         and b.cust_id = a.cust_id)
    group by  s.region)c  where a.region = c.region order by a.region;

    1. create a view with the query in the physical layer
    2. create a logical table by dragging the view to the BMM layer
    3. create a duplicate of the logical table and complex join with the original.
    4. drag one of the logical tables to the presentation layer
    pros of direct db req:
    1. tables which are not present in the dw (source tables that are not loaded using etl) can also be queried
    2. custom quesries can be excuted
    3. any databse can be accessed directly
    4. no etl is needed for the reports quering the source databse
    cons:
    1. makes the source database overloaded and slow
    2. it may take longer to show the output as it will join many source tables at the run time (in general).
    Regards,
    Roy.

  • Multiple subqueries to create a Report

    I can't seem to find the appropriate solution for a report. I have Joined two tables together to get all the information I need, but now I have to group data by state and group by three other variables - New, Retained, Cancelled.  Then loop through the amount of states that are in the DB.  Assuming I have UT and WA
    The report should look something like this:
    State: UT
    Number
    Premiums
    New Policies
    3
    $74.97
    Retained Policies
    2
    $13.98
    Cancelled Policies
    1
    $5.99
    Net Policies
    4
    $82.96
    State: WA
    Number
    Premiums
    New Policies
    3
    $74.97
    Retained Policies
    2
    $13.98
    Cancelled Policies
    1
    $5.99
    Net Policies
    4
    $82.96
    Here is my sort of working Code:
    <CFQUERY NAME="ActiveCustomers" DATASOURCE="#db#">
    SELECT * FROM tbl_customers
    INNER JOIN tbl_plans ON tbl_plans.ProductID = tbl_customers.ProductID
    WHERE  Status = "Active" AND Month(DateSignup) < "#Form.Month#"
    ORDER BY DateSignup asc;
    </CFQUERY>
    <cfset ActiveCustomerTotal = 0>
    <cfoutput query="ActiveCustomers">
    <cfset ActiveCustomerTotal = #ActiveCustomerTotal# + #ActiveCustomers.ProductPrice#>
    </cfoutput>
    <CFQUERY NAME="NewCustomers" DATASOURCE="#db#">
    SELECT * FROM tbl_customers
    INNER JOIN tbl_plans ON tbl_plans.ProductID = tbl_customers.ProductID
    WHERE  Status = "Active" AND Month(DateSignup) = "#Form.Month#"
    ORDER BY DateSignup asc;
    </CFQUERY>
    <cfset NewCustomerTotal = 0>
    <cfoutput query="NewCustomers">
    <cfset NewCustomerTotal = #NewCustomerTotal# + #NewCustomers.ProductPrice#>
    </cfoutput>
    <CFQUERY NAME="CancelledCustomers" DATASOURCE="#db#">
    SELECT c.Status, c.ProductID,(SELECT SUM(p.ProductPrice) FROM tbl_plans p WHERE p.ProductID = c.ProductID) AS ItemSum
    FROM tbl_customers c
    WHERE  c.Status = "Cancelled" AND Month(c.Cancelled) = "#Form.Month#"
    ORDER BY Cancelled asc;
    </CFQUERY>
    <cfset CancelledCustTotal = 0>
    <cfoutput query="CancelledCustomers">
    <cfset CancelledCustTotal = #CancelledCustTotal# + #ItemSum#>
    </cfoutput>
    I have looked everywhere for help.

    I don't have Create Scripts because I use Sequel Pro to create everything visually.  I would consider myself More Designer than Programmer - Don't hold it against me.
    "New Policies", "Retained Policies", "Cancelled Policies", and "Net Policies" are just titles to describe the calculations -  They don't exist in the table structure.
    For example:
    tbl_customers has 3 customers that signed up this month (New Policies).
    tbl_customers has 6 customers that signed up prior to this Month but still Active(Retained Policies - carry over from previous Months). 
    tbl_customers has 4 customers that cancelled this Month (Cancelled Policies).
    The "Net" is New + Retained - Cancelled.
    So, I do a query that Joins tbl_customers(this table holds the ProductID(Policy), State, DateSignup, Status(active or cancelled), Cancelled(null if still active)  and tbl_plans holds ProductID(Policy), ProductPrice(PolicyPrice).
    A Join outputs all listings:
    SELECT c.State AS State, p.ProductPrice  AS Price
    FROM tbl_customers c
    INNER JOIN tbl_plans p ON p.ProductID = c.ProductID
    I originally created Three different Queries:
    <CFQUERY NAME="ActiveCustomers" DATASOURCE="#db#">
    SELECT * FROM tbl_customers
    INNER JOIN tbl_plans ON tbl_plans.ProductID = tbl_customers.ProductID
    WHERE  Status = "Active" AND Month(DateSignup) < "#Form.Month#"
    ORDER BY DateSignup asc;
    </CFQUERY>
    <cfset ActiveCustomerTotal = 0>
    <cfoutput query="ActiveCustomers">
    <cfset ActiveCustomerTotal = #ActiveCustomerTotal# + #ActiveCustomers.ProductPrice#>
    </cfoutput>
    <CFQUERY NAME="NewCustomers" DATASOURCE="#db#">
    SELECT * FROM tbl_customers
    INNER JOIN tbl_plans ON tbl_plans.ProductID = tbl_customers.ProductID
    WHERE  Status = "Active" AND Month(DateSignup) = "#Form.Month#"
    ORDER BY DateSignup asc;
    </CFQUERY>
    <cfset NewCustomerTotal = 0>
    <cfoutput query="NewCustomers">
    <cfset NewCustomerTotal = #NewCustomerTotal# + #NewCustomers.ProductPrice#>
    </cfoutput>
    <CFQUERY NAME="CancelledCustomers" DATASOURCE="#db#">
    SELECT c.Status, c.ProductID,(SELECT SUM(p.ProductPrice) FROM tbl_plans p WHERE p.ProductID = c.ProductID) AS ItemSum
    FROM tbl_customers c
    WHERE  c.Status = "Cancelled" AND Month(c.Cancelled) = "#Form.Month#"
    ORDER BY Cancelled asc;
    </CFQUERY>
    <cfset CancelledCustTotal = 0>
    <cfoutput query="CancelledCustomers">
    <cfset CancelledCustTotal = #CancelledCustTotal# + #ItemSum#>
    </cfoutput>
    This works to obtain all calculations for the three variables, but tried to combine the results into one single query with a UNION.
    <CFQUERY NAME="Customers" DATASOURCE="#db#">
    SELECT c.State, SUM(p.ProductPrice ) AS Price FROM tbl_customers c
    INNER JOIN tbl_plans p ON p.ProductID = c.ProductID
    WHERE  Status = "Active" AND Month(DateSignup) = "10"
    GROUP BY Month(c.DateSignup), c.State
    UNION ALL
    SELECT c.State, SUM(p.ProductPrice )AS Price FROM tbl_customers c
    INNER JOIN tbl_plans p ON p.ProductID = c.ProductID
    WHERE  Status = "Active" AND Month(DateSignup) < "10"
    GROUP BY Month(c.DateSignup), c.State
    UNION ALL
    SELECT c.State, SUM(p.ProductPrice )AS Price FROM tbl_customers c
    INNER JOIN tbl_plans p ON p.ProductID = c.ProductID
    WHERE  Status = "Cancelled" AND Month(Cancelled) = "10"
    GROUP BY Month(Cancelled), c.State
    </CFQUERY>
    The Union works, but now I don't know how to group out the table by state.
    What I need to do is start grouping the output.
    Group all policies that where DateSignup is this Month. (New Policies)
    Group all policies that where DateSignup is older than this Month, but are still "Active" (Retained Policies)
    Group all policies that are where Status is "Cancelled" and Cancelled is This Month.
    Then, Output the results like so:
    UT
    Number
    Premiums
    New Policies
    3
    $74.97
    Retained Policies
    6
    $225.98
    Cancelled Policies
    4
    $178.88
    Net
    5
    $122.04
    WA
    Number
    Premiums
    New Policies
    1
    $9.99
    Retained Policies
    3
    $225.98
    Cancelled Policies
    1
    $9.99
    Net
    3
    $225.98

  • Attempting to report using multiple subqueries and filtering on result set

    I have an Oracle view which shows historic logs of changed data, effectively an audit view. The view is over two tables, a header and a detail table. I guess for the purpose of the question that is not too relevant but the structure of the view is. This is the view:
    SQL> desc ifsinfo.history_log_join
    Name Null? Type
    *LOG_ID                                    NOT NULL VARCHAR2(10)
    *MODULE                                    NOT NULL VARCHAR2(6)
    *LU_NAME                                   NOT NULL VARCHAR2(30)
    *TABLE_NAME                                NOT NULL VARCHAR2(30)
    *TIME_STAMP                                NOT NULL DATE
    *USERNAME                                  NOT NULL VARCHAR2(30)
    *KEYS                                      NOT NULL VARCHAR2(600)
    *HISTORY_TYPE                                       VARCHAR2(200)
    *HISTORY_TYPE_DB                           NOT NULL VARCHAR2(20)
    COLUMN_NAME NOT NULL VARCHAR2(30)
    OLD_VALUE VARCHAR2(2000)
    NEW_VALUE VARCHAR2(2000)
    I have indicated header information with *.
    The detail shows every column that was changed for a table (in header) and the old and new values, quite straight forward.
    The table I am interested in the audit of is:
    SQL> desc customer_order_reservation_tab
    Name Null? Type
    * ORDER_NO NOT NULL VARCHAR2(12)
    * LINE_NO NOT NULL VARCHAR2(4)
    * REL_NO NOT NULL VARCHAR2(4)
    * LINE_ITEM_NO NOT NULL NUMBER
    * CONTRACT NOT NULL VARCHAR2(5)
    * PART_NO NOT NULL VARCHAR2(25)
    CONFIGURATION_ID NOT NULL VARCHAR2(50)
    * LOCATION_NO NOT NULL VARCHAR2(35)
    * LOT_BATCH_NO NOT NULL VARCHAR2(20)
    * SERIAL_NO NOT NULL VARCHAR2(15)
    WAIV_DEV_REJ_NO NOT NULL VARCHAR2(15)
    ENG_CHG_LEVEL NOT NULL VARCHAR2(2)
    * PICK_LIST_NO NOT NULL VARCHAR2(15)
    PALLET_ID NOT NULL VARCHAR2(10)
    * LAST_ACTIVITY_DATE DATE
    SOURCE VARCHAR2(25)
    QTY_ASSIGNED NOT NULL NUMBER
    QTY_PICKED NOT NULL NUMBER
    QTY_SHIPPED NOT NULL NUMBER
    DELIV_NO NUMBER
    ROWVERSION DATE
    I have indicated columns that I am interested in (either as a key field or as changed data) by *
    Okay - so that's the background, what am I attempting to report.
    I want to return a single row per log id (for certain criteria) which shows:
    Log_Id
    History_Type
    Time_Stamp
    Username
    Order_No
    Pick_List_No
    Rel_No
    Line_No
    Part_No
    Loc_No
    Lot_Batch_No
    Serial_No
    The SQL I have currently is:
    select grp.*
    from
    (select h1.log_id, h1.history_type, time_stamp, username,
    (select h2.old_value||h2.new_value from ifsinfo.history_log_join h2 where h1.log_id=h2.log_id and h2.column_name ='ORDER_NO') Order_No,
    (select h2.old_value||h2.new_value from ifsinfo.history_log_join h2 where h1.log_id=h2.log_id and h2.column_name ='PICK_LIST_NO') Pick_List_No,
    (select h2.old_value||h2.new_value from ifsinfo.history_log_join h2 where h1.log_id=h2.log_id and h2.column_name ='REL_NO') Rel_No,
    (select h2.old_value||h2.new_value from ifsinfo.history_log_join h2 where h1.log_id=h2.log_id and h2.column_name ='LINE_NO') Line_No,
    (select h2.old_value||h2.new_value from ifsinfo.history_log_join h2 where h1.log_id=h2.log_id and h2.column_name ='PART_NO') Part_No,
    (select h2.old_value||h2.new_value from ifsinfo.history_log_join h2 where h1.log_id=h2.log_id and h2.column_name ='LOCATION_NO') Loc_No,
    (select h2.old_value||h2.new_value from ifsinfo.history_log_join h2 where h1.log_id=h2.log_id and h2.column_name ='LOT_BATCH_NO') Lot_Batch_No,
    (select h2.old_value||h2.new_value from ifsinfo.history_log_join h2 where h1.log_id=h2.log_id and h2.column_name ='SERIAL_NO') Serial_No
    from ifsinfo.history_log_join h1
    where
    table_name = 'CUSTOMER_ORDER_RESERVATION_TAB'
    and
    keys like upper('CONFIGURATION_ID=*^CONTRACT=&company%')
    and
    history_type in ('Delete','Insert')
    and
    column_name ='PICK_LIST_NO'
    and
    username != 'IFSAPP'
    and
    h1.old_value || h1.new_value != '*'
    and
    trunc(h1.time_stamp) > trunc(sysdate-1-&days_ago)
    order by 5, 6, 8, 7,9,10,2, 1) grp
    This is OK but..
    I only want to include rows where the same picklist / rel_no / line_no / part_no combination exist more than once (because there is always an insert and delete for the analysis I am doing).
    AND
    where for that combination, the lot_batch_no OR serial_no are different.
    Effectively the system does an insert / delete rather than an update, so that is why.
    Thanks

    Hi sanny007,
    As your issue is related to Reports, I'm moving your post to a more appropriate forum for better supports, thanks for your undrstanding.
    https://social.msdn.microsoft.com/Forums/en-US/home?forum=vsreportcontrols
    Best regards,
    Youjun Tang
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Converting multiple correlated self-referencing subqueries to Analytic Func

    I have a peoplesoft query that I am trying to improve the performance on. Using DBMS_XPLAN with gather_plan_statistics is showing me that a large portion of the time is being spent on the various correlated self-referencing MAX/MIN subqueries.
    |  24 |       SORT AGGREGATE               |                    |   9461K|      1 |    21 |            |          |        |      |            |   9461K|00:14:31.67 |     139M|  99172 |       |       |          |
    |* 25 |        TABLE ACCESS BY INDEX ROWID | PS_BAS_PARTIC      |   9461K|      1 |    21 |    12   (0)| 00:00:01 |        |      |            |     89M|00:19:10.64 |     139M|  99172 |       |       |          |
    |* 26 |         INDEX RANGE SCAN           | PSBBAS_PARTIC      |   9461K|      9 |       |     3   (0)| 00:00:01 |        |      |            |    131M|00:03:16.21 |      19M|  16193 |       |       |          |I think I understand the basic mechanism of converting a simple case to use a MAX/MIN PARTITION OVER analytic. I.E.
    select emplid, effdt, .....
    from ps_pay_check pchk1
    where pchk1.effdt = (select max(effdt)
                        from ps_pay_check pchk2
                        where pchk2.emplid = pchk1.emplid);converts to
    select emplid, effdt, .....
    from
    (select emplid,
              effdt,
              max(effdt) over (partition by emplid) max_effdt
    from ps_pay_check pchk1)
    where effdt = max_effdt;However, when you have multiple subqueries that have multiple predicates (some referencing the parent some against binds), I get a little confused.
    Here is the main example I am working with (fairly complex/ugly query).
    SELECT   /*+ gather_plan_statistics */
            A.EMPLID, A.EMPL_RCD, A.REG_REGION, A.EMPL_STATUS, A.LOCATION,
             A.ACTION_REASON, A.EFFDT, A.REG_TEMP, A.PAYGROUP, A.FULL_PART_TIME, A.JOBCODE, A.DEPTID,
             A.UNION_CD, A.FLSA_STATUS, A.STD_HOURS, A.ACTION, A.SUPERVISOR_ID, A.SETID_JOBCODE,
             B.MED_ELIG, B.DEP_LIFE_ELIG,B.SUP_LIFE_ELIG
    FROM
       PS_JOB A,
      (SELECT  EMPLID,
       max(( CASE WHEN PLAN_TYPE IN ( '10','11','14')  THEN 'Y' ELSE 'N' END)) med_elig,
       max(( CASE WHEN PLAN_TYPE IN ( '2X','2Z')  THEN 'Y' ELSE 'N' END)) dep_life_elig,
       max(( CASE WHEN PLAN_TYPE IN ( '2Y')  THEN 'Y' ELSE 'N' END)) sup_life_elig
      FROM          
        (SELECT 
           B.EMPLID, B.PLAN_TYPE
         FROM PS_BAS_PARTIC A,
             PS_BAS_PARTIC_PLAN B,
             PS_BAS_PARTIC_OPTN C
         WHERE      A.EVENT_STATUS = 'C'
             AND A.BAS_PROCESS_STATUS = 'FE'
             AND A.BAS_EVT_DISCONNECT = 'N'
             AND A.EVENT_DT = (SELECT MAX (A_ED.EVENT_DT)
                                        FROM PS_BAS_PARTIC A_ED
                                      WHERE        A.EMPLID = A_ED.EMPLID
                                              AND A_ED.EVENT_DT <= :1
                                              AND A_ED.BAS_PROCESS_STATUS = A.BAS_PROCESS_STATUS
                                              AND A_ED.BAS_EVT_DISCONNECT = A.BAS_EVT_DISCONNECT)
             AND A.SCHED_ID = B.SCHED_ID
             AND A.EMPLID = B.EMPLID
             AND A.BENEFIT_RCD_NBR = B.BENEFIT_RCD_NBR
             AND A.EVENT_ID = B.EVENT_ID
             AND B.PLAN_TYPE IN ('10', '11', '14', '2X', '2Z', '2Y')
             AND B.EMPLID = C.EMPLID
             AND B.BENEFIT_RCD_NBR = C.BENEFIT_RCD_NBR
             AND B.EVENT_ID = C.EVENT_ID
             AND B.PLAN_TYPE = C.PLAN_TYPE
             AND B.SCHED_ID = C.SCHED_ID
             AND A.EVENT_DT = (SELECT MAX (D.EVENT_DT)
                                        FROM PS_BAS_PARTIC D
                                      WHERE        A.EMPLID = D.EMPLID
                                              AND D.EVENT_STATUS = A.EVENT_STATUS
                                              AND D.EVENT_DT <= :1
                                              AND D.BAS_PROCESS_STATUS = A.BAS_PROCESS_STATUS
                                              AND D.BAS_EVT_DISCONNECT = A.BAS_EVT_DISCONNECT)
             AND C.BENEFIT_PLAN <> ' '
             AND A.STATUS_DT = (SELECT MAX (E.STATUS_DT)
                                         FROM PS_BAS_PARTIC E
                                        WHERE      E.EVENT_STATUS = A.EVENT_STATUS
                                                AND E.EMPLID = A.EMPLID
                                                AND E.BAS_PROCESS_STATUS = A.BAS_PROCESS_STATUS
                                                AND E.BAS_EVT_DISCONNECT = A.BAS_EVT_DISCONNECT
                                                AND E.EVENT_DT = A.EVENT_DT)
             AND A.EVENT_PRIORITY = (SELECT MIN (F.EVENT_PRIORITY)
                                                FROM PS_BAS_PARTIC F
                                              WHERE        F.EMPLID = A.EMPLID
                                                      AND F.EVENT_STATUS = A.EVENT_STATUS
                                                      AND F.BAS_PROCESS_STATUS = A.BAS_PROCESS_STATUS
                                                      AND F.BAS_EVT_DISCONNECT = A.BAS_EVT_DISCONNECT
                                                      AND F.EVENT_DT = A.EVENT_DT
                                                      AND F.STATUS_DT = A.STATUS_DT)
         GROUP BY EMPLID) B
    WHERE  A.EMPLID = B. EMPLID
                AND  A.PER_ORG = 'EMP'
                AND A.EFFDT = (SELECT MAX (A_SUB.EFFDT)
                                    FROM PS_JOB A_SUB
                                  WHERE        A.EMPLID = A_SUB.EMPLID
                                          AND A.EMPL_RCD = A_SUB.EMPL_RCD
                                          AND A_SUB.EFFDT <= :3)
                AND A.EFFSEQ = (SELECT MAX (A_SUB2.EFFSEQ)
                                     FROM PS_JOB A_SUB2
                                    WHERE      A.EMPLID = A_SUB2.EMPLID
                                            AND A.EMPL_RCD = A_SUB2.EMPL_RCD
                                            AND A.EFFDT = A_SUB2.EFFDT)
    ORDER BY A.EMPLID;As you can see this has a total of 6 different MAX/MIN subqueries. Can all of them be turned into analytic equivalents, and how are the different predicates of the subqueries handled?
    Any help appreciated!
    Thanks
    Wayne

    The full query takes roughly 25 min. With 14.5 min taken by the first correlated subquery, MAX (A_ED.EVENT_DT).
    Here's the full plan:
    | Id  | Operation                          | Name               | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time   |    TQ  |IN-OUT| PQ Distrib | A-Rows |   A-Time   | Buffers | Reads  |  OMem |  1Mem | Used-Mem |
    |   0 | SELECT STATEMENT                   |                    |      1 |        |       |   220M(100)|          |        |      |            |      1 |00:24:59.66 |     181M|    398K|       |       |          |
    |*  1 |  FILTER                            |                    |      1 |        |       |            |          |        |      |            |      1 |00:24:59.66 |     181M|    398K|       |       |          |
    |   2 |   NESTED LOOPS                     |                    |      1 |      6 |   636 |   220M  (1)|733:42:27 |        |      |            |      1 |00:24:59.65 |     181M|    398K|       |       |          |
    |   3 |    VIEW                            |                    |      1 |      1 |    16 |   220M  (1)|733:42:27 |        |      |            |      1 |00:24:59.64 |     181M|    398K|       |       |          |
    |   4 |     SORT AGGREGATE                 |                    |      1 |      1 |   102 |            |          |        |      |            |      1 |00:24:59.64 |     181M|    398K|       |       |          |
    |*  5 |      FILTER                        |                    |      1 |        |       |            |          |        |      |            |     23M|00:23:02.81 |     181M|    398K|       |       |          |
    |   6 |       PX COORDINATOR               |                    |      1 |        |       |            |          |        |      |            |     76M|00:06:42.64 |     300K|    299K|       |       |          |
    |   7 |        PX SEND QC (RANDOM)         | :TQ10004           |      0 |     18M|  1792M|   199K  (2)| 00:39:54 |  Q1,04 | P->S | QC (RAND)  |      0 |00:00:00.01 |       0 |      0 |       |       |          |
    |*  8 |         HASH JOIN BUFFERED         |                    |      0 |     18M|  1792M|   199K  (2)| 00:39:54 |  Q1,04 | PCWP |            |      0 |00:00:00.01 |       0 |      0 |   325M|    16M|          |
    |   9 |          BUFFER SORT               |                    |      0 |        |       |            |          |  Q1,04 | PCWC |            |      0 |00:00:00.01 |       0 |      0 | 73728 | 73728 |          |
    |  10 |           PX RECEIVE               |                    |      0 |   3405K|   152M| 19585   (2)| 00:03:56 |  Q1,04 | PCWP |            |      0 |00:00:00.01 |       0 |      0 |       |       |          |
    |  11 |            PX SEND HASH            | :TQ10001           |      0 |   3405K|   152M| 19585   (2)| 00:03:56 |        | S->P | HASH       |      0 |00:00:00.01 |       0 |      0 |       |       |          |
    |* 12 |             TABLE ACCESS FULL      | PS_BAS_PARTIC      |      1 |   3405K|   152M| 19585   (2)| 00:03:56 |        |      |            |   3302K|00:00:10.18 |   87732 |  87726 |       |       |          |
    |  13 |          PX RECEIVE                |                    |      0 |     24M|  1289M|   179K  (2)| 00:35:59 |  Q1,04 | PCWP |            |      0 |00:00:00.01 |       0 |      0 |       |       |          |
    |  14 |           PX SEND HASH             | :TQ10003           |      0 |     24M|  1289M|   179K  (2)| 00:35:59 |  Q1,03 | P->P | HASH       |      0 |00:00:00.01 |       0 |      0 |       |       |          |
    |* 15 |            HASH JOIN BUFFERED      |                    |      0 |     24M|  1289M|   179K  (2)| 00:35:59 |  Q1,03 | PCWP |            |      0 |00:00:00.01 |       0 |      0 |   730M|    18M|          |
    |  16 |             BUFFER SORT            |                    |      0 |        |       |            |          |  Q1,03 | PCWC |            |      0 |00:00:00.01 |       0 |      0 | 73728 | 73728 |          |
    |  17 |              PX RECEIVE            |                    |      0 |     12M|   279M| 47310   (3)| 00:09:28 |  Q1,03 | PCWP |            |      0 |00:00:00.01 |       0 |      0 |       |       |          |
    |  18 |               PX SEND HASH         | :TQ10000           |      0 |     12M|   279M| 47310   (3)| 00:09:28 |        | S->P | HASH       |      0 |00:00:00.01 |       0 |      0 |       |       |          |
    |* 19 |                INDEX FAST FULL SCAN| PS_BAS_PARTIC_PLAN |      1 |     12M|   279M| 47310   (3)| 00:09:28 |        |      |            |     12M|00:00:57.03 |     213K|    211K|       |       |          |
    |  20 |             PX RECEIVE             |                    |      0 |     84M|  2499M|   132K  (2)| 00:26:30 |  Q1,03 | PCWP |            |      0 |00:00:00.01 |       0 |      0 |       |       |          |
    |  21 |              PX SEND HASH          | :TQ10002           |      0 |     84M|  2499M|   132K  (2)| 00:26:30 |  Q1,02 | P->P | HASH       |      0 |00:00:00.01 |       0 |      0 |       |       |          |
    |  22 |               PX BLOCK ITERATOR    |                    |      0 |     84M|  2499M|   132K  (2)| 00:26:30 |  Q1,02 | PCWC |            |      0 |00:00:00.01 |       0 |      0 |       |       |          |
    |* 23 |                TABLE ACCESS FULL   | PS_BAS_PARTIC_OPTN |      0 |     84M|  2499M|   132K  (2)| 00:26:30 |  Q1,02 | PCWP |            |      0 |00:00:00.01 |       0 |      0 |       |       |          |
    |  24 |       SORT AGGREGATE               |                    |   9461K|      1 |    21 |            |          |        |      |            |   9461K|00:14:31.67 |     139M|  99172 |       |       |          |
    |* 25 |        TABLE ACCESS BY INDEX ROWID | PS_BAS_PARTIC      |   9461K|      1 |    21 |    12   (0)| 00:00:01 |        |      |            |     89M|00:19:10.64 |     139M|  99172 |       |       |          |
    |* 26 |         INDEX RANGE SCAN           | PSBBAS_PARTIC      |   9461K|      9 |       |     3   (0)| 00:00:01 |        |      |            |    131M|00:03:16.21 |      19M|  16193 |       |       |          |
    |  27 |       SORT AGGREGATE               |                    |   1093K|      1 |    23 |            |          |        |      |            |   1093K|00:00:47.55 |      13M|      0 |       |       |          |
    |* 28 |        TABLE ACCESS BY INDEX ROWID | PS_BAS_PARTIC      |   1093K|      1 |    23 |    12   (0)| 00:00:01 |        |      |            |   9182K|00:00:53.32 |      13M|      0 |       |       |          |
    |* 29 |         INDEX RANGE SCAN           | PSBBAS_PARTIC      |   1093K|      9 |       |     3   (0)| 00:00:01 |        |      |            |     12M|00:00:13.00 |    2230K|      0 |       |       |          |
    |  30 |       SORT AGGREGATE               |                    |   1093K|      1 |    31 |            |          |        |      |            |   1093K|00:00:43.48 |      13M|      0 |       |       |          |
    |* 31 |        TABLE ACCESS BY INDEX ROWID | PS_BAS_PARTIC      |   1093K|      1 |    31 |    12   (0)| 00:00:01 |        |      |            |   1122K|00:00:41.05 |      13M|      0 |       |       |          |
    |* 32 |         INDEX RANGE SCAN           | PSBBAS_PARTIC      |   1093K|      9 |       |     3   (0)| 00:00:01 |        |      |            |     12M|00:00:12.98 |    2229K|      0 |       |       |          |
    |  33 |       SORT AGGREGATE               |                    |   1077K|      1 |    35 |            |          |        |      |            |   1077K|00:00:42.82 |      13M|      0 |       |       |          |
    |* 34 |        TABLE ACCESS BY INDEX ROWID | PS_BAS_PARTIC      |   1077K|      1 |    35 |    12   (0)| 00:00:01 |        |      |            |   1079K|00:00:40.67 |      13M|      0 |       |       |          |
    |* 35 |         INDEX RANGE SCAN           | PSBBAS_PARTIC      |   1077K|      9 |       |     3   (0)| 00:00:01 |        |      |            |     12M|00:00:12.62 |    2197K|      0 |       |       |          |
    |  36 |    TABLE ACCESS BY INDEX ROWID     | PS_JOB             |      1 |      6 |   540 |     8   (0)| 00:00:01 |        |      |            |      1 |00:00:00.02 |       4 |      4 |       |       |          |
    |* 37 |     INDEX RANGE SCAN               | PS0JOB             |      1 |      6 |       |     2   (0)| 00:00:01 |        |      |            |      1 |00:00:00.01 |       3 |      3 |       |       |          |
    |  38 |   SORT AGGREGATE                   |                    |      1 |      1 |    19 |            |          |        |      |            |      1 |00:00:00.01 |       3 |      1 |       |       |          |
    |* 39 |    INDEX RANGE SCAN                | PSAJOB             |      1 |      1 |    19 |     3   (0)| 00:00:01 |        |      |            |      1 |00:00:00.01 |       3 |      1 |       |       |          |
    |  40 |   SORT AGGREGATE                   |                    |      1 |      1 |    22 |            |          |        |      |            |      1 |00:00:00.01 |       3 |      0 |       |       |          |
    |* 41 |    INDEX RANGE SCAN                | PSAJOB             |      1 |      1 |    22 |     3   (0)| 00:00:01 |        |      |            |      1 |00:00:00.01 |       3 |      0 |       |       |          |
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Yes, I was also puzzled by the 2 almost identical EVENT_DT subqueries. The second one, with EVENT_STATUS, only takes about 1 min of the execution time (since the EVENT_STATUS filters the records processed by the subquery by an order of magnitude). I haven't had a chance to ask the developers about it yet, but it does make a difference in the output. Though, even if I were to take out the second one, the performance and question of the proper format of the Analytic functions would remain.

  • Server Crashes when using Cursor Vars in Stored Procedure

    Can anyone make a suggestion
    We are experiencing a problem that causes our Weblogic Server to crash
    when a JDBC call is made to our Oracle database.
    Host Details
    Operating System: Solaris Version 8
    SunOS 5.8 Generic_108528-15 sun4u sparc SUNW,UltraAX-i2
    WebLogic Server 6.1 SP1 09/18/2001 14:28:44 #138716
    Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
    JDBC Driver Weblogic JDriver for Oracle
    The jdbc command that causes the problem is similar the spcursor
    example code file:
    // Here we prepare a CallableStatement using a WebLogic extension
    // to JDBC that supports binding an Oracle cursor to an output
    // parameter. Register the output parameter type as OTHER . . .
    cstmt =
         (weblogic.jdbc.common.OracleCallableStatement)conn.prepareCall("BEGIN
    OPEN ? FOR select * from emp; END;");
    cstmt.registerOutParameter(1, java.sql.Types.OTHER);
    The crash happens when the re.next() method is invoked after the
    execute()
    This is the core dump message that is generated:
    An unexpected exception has been detected in native code outside the
    VM.
    Unexpected Signal : 11 occurred at PC=0xd339f37c
    Function name=kpcxk2u
    Library=/u01/app/oracle/product/8.1.7/lib/libclntsh.so.8.0
    Current Java thread:
    at weblogic.db.oci.OciCursor.arrayFetch(Native Method)
    at weblogic.db.oci.OciCursor.oci_arrayFetch(OciCursor.java:2002)
    at weblogic.jdbc.oci.ResultSet.next(ResultSet.java:759)
    at weblogic.jdbc.pool.ResultSet.next(ResultSet.java:180)
    at weblogic.jdbc.rmi.internal.ResultSetImpl.next(ResultSetImpl.java:132)
    at weblogic.jdbc.rmi.internal.ResultSetImpl_WLSkel.invoke(Unknown
    Source)
    at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:296)
    at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:265)
    at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
    Dynamic libraries:
    0x10000 /opt/bea/jdk131/jre/bin/../bin/sparc/native_threads/java
    0xff350000 /usr/lib/libthread.so.1
    0xff390000 /usr/lib/libdl.so.1
    0xff200000 /usr/lib/libc.so.1
    0xff330000 /usr/platform/SUNW,UltraAX-i2/lib/libc_psr.so.1
    0xfe480000 /opt/bea/jdk131/jre/lib/sparc/hotspot/libjvm.so
    0xff2e0000 /usr/lib/libCrun.so.1
    0xff1e0000 /usr/lib/libsocket.so.1
    0xff100000 /usr/lib/libnsl.so.1
    0xff0d0000 /usr/lib/libm.so.1
    0xff310000 /usr/lib/libw.so.1
    0xff0b0000 /usr/lib/libmp.so.2
    0xff080000 /opt/bea/jdk131/jre/lib/sparc/native_threads/libhpi.so
    0xff050000 /opt/bea/jdk131/jre/lib/sparc/libverify.so
    0xfe440000 /opt/bea/jdk131/jre/lib/sparc/libjava.so
    0xff020000 /opt/bea/jdk131/jre/lib/sparc/libzip.so
    0xfe230000 /opt/bea/jdk131/jre/lib/sparc/libnet.so
    0xfe160000 /usr/lib/nss_files.so.1
    0xd3700000 /opt/bea/wlserver6.1/lib/solaris/oci817_8/libweblogicoci37.so
    0xd3000000 /u01/app/oracle/product/8.1.7/lib/libclntsh.so.8.0
    0xfd090000 /usr/lib/libC.so.5
    0xfd3b0000 /u01/app/oracle/product/8.1.7/lib/libwtc8.so
    0xfd070000 /usr/lib/libgen.so.1
    0xfd050000 /usr/lib/libsched.so.1
    0xfd020000 /usr/lib/libaio.so.1
    0xfafd0000 /opt/bea/wlserver6.1/lib/solaris/libmuxer.so
    Local Time = Thu Apr 3 10:39:37 2003
    Elapsed Time = 178
    # The exception above was detected in native code outside the VM
    # Java VM: Java HotSpot(TM) Client VM (1.3.1-b24 mixed mode)
    # An error report file has been saved as hs_err_pid7599.log.
    # Please refer to the file for further information.
    Abort - core dumped
    TIA
    Tony

    Tony,
    "Tony Ross" <[email protected]> wrote in message
    news:[email protected]...
    Thanks Mitesh for your response.
    We have followed your advice on using the 901 driver and updating the
    config.xml file. Alas it has not stopped the Solaris WLS from
    crashing.Actually, Mitesh sugested you replacing weblogic driver
    with oracle one. As it follows from the stacktrace, it has
    not been done.
    I'd also recommend moving to oracle thin driver as it
    doesn't have native code thus is more stable.
    Regards,
    Slava Imeshev
    In addition to this we tried using WLS 6.1 SP2 on a Win2000 box
    (connecting to same database). We managed to crash this instance as
    well. The core dump is as follows:
    An unexpected exception has been detected in native code outside the
    VM.
    Unexpected Signal : EXCEPTION_ACCESS_VIOLATION occurred at
    PC=0x6021bc08
    Function name=kpcxk2u
    Library=C:\Oracle\Ora81\BIN\oracommon8.dll
    Current Java thread:
    at weblogic.db.oci.OciCursor.arrayFetch(Native Method)
    - locked <2956f78> (a weblogic.db.oci.OciCursor)
    at weblogic.db.oci.OciCursor.oci_arrayFetch(OciCursor.java:2022)
    at weblogic.jdbc.oci.ResultSet.next(ResultSet.java:759)
    - locked <3423480> (a weblogic.db.oci.OciConnection)
    at weblogic.jdbc.rmi.internal.ResultSetImpl.next(ResultSetImpl.java:133)
    at weblogic.jdbc.rmi.internal.ResultSetImpl_WLSkel.invoke(Unknown
    Source)
    at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:298)
    atweblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:267)
    atweblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:2
    2)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
    Dynamic libraries:
    0x00400000 - 0x00405000 c:\bea\jdk131\bin\java.exe
    0x77F80000 - 0x77FFB000 C:\WINNT\System32\ntdll.dll
    0x77DB0000 - 0x77E0D000 C:\WINNT\system32\ADVAPI32.dll
    0x77E80000 - 0x77F36000 C:\WINNT\system32\KERNEL32.DLL
    0x77D30000 - 0x77DA1000 C:\WINNT\system32\RPCRT4.DLL
    0x78000000 - 0x78046000 C:\WINNT\system32\MSVCRT.dll
    0x6D420000 - 0x6D4EE000 c:\bea\jdk131\jre\bin\hotspot\jvm.dll
    0x77E10000 - 0x77E75000 C:\WINNT\system32\USER32.dll
    0x77F40000 - 0x77F7C000 C:\WINNT\system32\GDI32.DLL
    0x77570000 - 0x775A0000 C:\WINNT\System32\WINMM.dll
    0x6D220000 - 0x6D227000 c:\bea\jdk131\jre\bin\hpi.dll
    0x6D3B0000 - 0x6D3BD000 c:\bea\jdk131\jre\bin\verify.dll
    0x6D250000 - 0x6D266000 c:\bea\jdk131\jre\bin\java.dll
    0x6D3C0000 - 0x6D3CD000 c:\bea\jdk131\jre\bin\zip.dll
    0x6D2A0000 - 0x6D2BB000 c:\bea\jdk131\jre\bin\jdwp.dll
    0x6D1D0000 - 0x6D1D5000 c:\bea\jdk131\bin\dt_socket.dll
    0x75030000 - 0x75043000 C:\WINNT\System32\ws2_32.dll
    0x75020000 - 0x75028000 C:\WINNT\System32\WS2HELP.DLL
    0x74FD0000 - 0x74FED000 C:\WINNT\system32\msafd.dll
    0x75010000 - 0x75017000 C:\WINNT\System32\wshtcpip.dll
    0x6D340000 - 0x6D348000 C:\bea\jdk131\jre\bin\net.dll
    0x75050000 - 0x75058000 C:\WINNT\System32\WSOCK32.dll
    0x782C0000 - 0x782CC000 C:\WINNT\System32\rnr20.dll
    0x77980000 - 0x779A4000 C:\WINNT\System32\DNSAPI.DLL
    0x77340000 - 0x77353000 C:\WINNT\System32\iphlpapi.dll
    0x77520000 - 0x77525000 C:\WINNT\System32\ICMP.DLL
    0x77320000 - 0x77337000 C:\WINNT\System32\MPRAPI.DLL
    0x75150000 - 0x75160000 C:\WINNT\System32\SAMLIB.DLL
    0x75170000 - 0x751BF000 C:\WINNT\System32\NETAPI32.DLL
    0x77BE0000 - 0x77BEF000 C:\WINNT\System32\SECUR32.DLL
    0x751C0000 - 0x751C6000 C:\WINNT\System32\NETRAP.DLL
    0x77950000 - 0x7797A000 C:\WINNT\system32\WLDAP32.DLL
    0x77A50000 - 0x77B45000 C:\WINNT\system32\OLE32.DLL
    0x779B0000 - 0x77A4B000 C:\WINNT\system32\OLEAUT32.DLL
    0x773B0000 - 0x773DE000 C:\WINNT\System32\ACTIVEDS.DLL
    0x77380000 - 0x773A2000 C:\WINNT\System32\ADSLDPC.DLL
    0x77830000 - 0x7783E000 C:\WINNT\System32\RTUTILS.DLL
    0x77880000 - 0x7790D000 C:\WINNT\System32\SETUPAPI.DLL
    0x77C10000 - 0x77C6E000 C:\WINNT\System32\USERENV.DLL
    0x774E0000 - 0x77512000 C:\WINNT\System32\RASAPI32.DLL
    0x774C0000 - 0x774D1000 C:\WINNT\System32\RASMAN.DLL
    0x77530000 - 0x77552000 C:\WINNT\System32\TAPI32.DLL
    0x71730000 - 0x717BA000 C:\WINNT\system32\COMCTL32.DLL
    0x70BD0000 - 0x70C20000 C:\WINNT\system32\SHLWAPI.DLL
    0x77360000 - 0x77379000 C:\WINNT\System32\DHCPCSVC.DLL
    0x777E0000 - 0x777E8000 C:\WINNT\System32\winrnr.dll
    0x777F0000 - 0x777F5000 C:\WINNT\System32\rasadhlp.dll
    0x10000000 - 0x10055000
    C:\bea\wlserver6.1\bin\oci901_8\weblogicoci37.dll
    0x0DE20000 - 0x0DE3A000 C:\Oracle\Ora81\BIN\OCI.dll
    0x780A0000 - 0x780B2000 C:\WINNT\System32\MSVCIRT.dll
    0x60400000 - 0x60502000 C:\Oracle\Ora81\BIN\OraClient8.Dll
    0x60600000 - 0x60682000 C:\Oracle\Ora81\BIN\oracore8.dll
    0x60800000 - 0x60848000 C:\Oracle\Ora81\BIN\oranls8.dll
    0x0DE40000 - 0x0DE46000 C:\Oracle\Ora81\BIN\oravsn8.dll
    0x60200000 - 0x60264000 C:\Oracle\Ora81\BIN\oracommon8.dll
    0x60000000 - 0x6011F000 C:\Oracle\Ora81\BIN\orageneric8.dll
    0x60350000 - 0x60356000 C:\Oracle\Ora81\BIN\orawtc8.dll
    0x60A00000 - 0x60A2B000 C:\Oracle\Ora81\BIN\oranl8.dll
    0x60B00000 - 0x60BAA000 C:\Oracle\Ora81\BIN\oran8.dll
    0x60E00000 - 0x60E10000 C:\Oracle\Ora81\BIN\orancrypt8.dll
    0x61100000 - 0x61137000 C:\Oracle\Ora81\BIN\oranro8.dll
    0x0DE50000 - 0x0DEAE000 C:\Oracle\Ora81\BIN\orannzsbb8.dll
    0x61500000 - 0x6150E000 C:\Oracle\Ora81\BIN\oranldap8.dll
    0x61700000 - 0x6171C000 C:\Oracle\Ora81\BIN\oraldapclnt8.dll
    0x61900000 - 0x61906000 C:\Oracle\Ora81\BIN\oranhost8.dll
    0x62100000 - 0x62106000 C:\Oracle\Ora81\BIN\oranoname8.dll
    0x0DEB0000 - 0x0DEB6000 C:\Oracle\Ora81\BIN\orancds8.dll
    0x62300000 - 0x62306000 C:\Oracle\Ora81\BIN\orantns8.dll
    0x62500000 - 0x62508000 C:\Oracle\Ora81\BIN\orannds8.dll
    0x0DEC0000 - 0x0DEDC000 C:\Oracle\Ora81\BIN\orannms8.dll
    0x62700000 - 0x62741000 C:\Oracle\Ora81\BIN\ORATRACE8.dll
    0x62900000 - 0x62B1B000 C:\Oracle\Ora81\BIN\orapls8.dll
    0x63100000 - 0x63108000 C:\Oracle\Ora81\BIN\oraslax8.dll
    0x63200000 - 0x63272000 C:\Oracle\Ora81\BIN\orasql8.dll
    0x64700000 - 0x6470C000 C:\Oracle\Ora81\bin\orantcp8.dll
    0x64500000 - 0x6450D000 C:\Oracle\Ora81\bin\orannts8.dll
    0x75500000 - 0x75504000 C:\WINNT\System32\security.dll
    0x782D0000 - 0x782EE000 C:\WINNT\system32\msv1_0.dll
    0x11260000 - 0x11265000 C:\bea\wlserver6.1\bin\wlntio.dll
    0x77920000 - 0x77943000 C:\WINNT\system32\imagehlp.dll
    0x72A00000 - 0x72A2D000 C:\WINNT\system32\DBGHELP.dll
    0x690A0000 - 0x690AB000 C:\WINNT\System32\PSAPI.DLL
    Local Time = Thu Apr 03 17:31:00 2003
    Elapsed Time = 327
    # The exception above was detected in native code outside the VM
    # Java VM: Java HotSpot(TM) Client VM (1.3.1_01 interpreted mode)
    So now we have a situation where - we can crash either server with a
    call to a function. We can now run the spcursors.java example without
    problem. The procedure that does crash the WLS can be run successfully
    from within sqlplus (it involves multiple subqueries and outer joins).
    FYI - the cursors we are returning in the function are weak cursor
    types (TYPE ref_cursor IS REF CURSOR)
    Any other suggestions greatly welcomed.
    Tony
    Mitesh Patel <[email protected]> wrote in message
    news:<[email protected]>...
    Please do the following:
    Make sure you have login delay sec=1 for connection pool in config.xml
    Should have TestConnOnReserve=true
    and use 901 driver instead of 817 driver. Using suggested driver, stillyou can connect to
    your original database.
    Thanks,
    Mitesh
    Tony Ross wrote:
    Can anyone make a suggestion
    We are experiencing a problem that causes our Weblogic Server to crash
    when a JDBC call is made to our Oracle database.
    Host Details
    Operating System: Solaris Version 8
    SunOS 5.8 Generic_108528-15 sun4u sparc SUNW,UltraAX-i2
    WebLogic Server 6.1 SP1 09/18/2001 14:28:44 #138716
    Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
    JDBC Driver Weblogic JDriver for Oracle
    The jdbc command that causes the problem is similar the spcursor
    example code file:
    // Here we prepare a CallableStatement using a WebLogic extension
    // to JDBC that supports binding an Oracle cursor to an output
    // parameter. Register the output parameter type as OTHER . . .
    cstmt =
    (weblogic.jdbc.common.OracleCallableStatement)conn.prepareCall("BEGIN
    OPEN ? FOR select * from emp; END;");
    cstmt.registerOutParameter(1, java.sql.Types.OTHER);
    The crash happens when the re.next() method is invoked after the
    execute()
    This is the core dump message that is generated:
    An unexpected exception has been detected in native code outside the
    VM.
    Unexpected Signal : 11 occurred at PC=0xd339f37c
    Function name=kpcxk2u
    Library=/u01/app/oracle/product/8.1.7/lib/libclntsh.so.8.0
    Current Java thread:
    at weblogic.db.oci.OciCursor.arrayFetch(Native Method)
    atweblogic.db.oci.OciCursor.oci_arrayFetch(OciCursor.java:2002)
    at weblogic.jdbc.oci.ResultSet.next(ResultSet.java:759)
    at weblogic.jdbc.pool.ResultSet.next(ResultSet.java:180)
    atweblogic.jdbc.rmi.internal.ResultSetImpl.next(ResultSetImpl.java:132)
    atweblogic.jdbc.rmi.internal.ResultSetImpl_WLSkel.invoke(Unknown
    Source)
    atweblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:296)
    atweblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:265)
    atweblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:
    atweblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
    Dynamic libraries:
    0x10000/opt/bea/jdk131/jre/bin/../bin/sparc/native_threads/java
    0xff350000 /usr/lib/libthread.so.1
    0xff390000 /usr/lib/libdl.so.1
    0xff200000 /usr/lib/libc.so.1
    0xff330000 /usr/platform/SUNW,UltraAX-i2/lib/libc_psr.so.1
    0xfe480000 /opt/bea/jdk131/jre/lib/sparc/hotspot/libjvm.so
    0xff2e0000 /usr/lib/libCrun.so.1
    0xff1e0000 /usr/lib/libsocket.so.1
    0xff100000 /usr/lib/libnsl.so.1
    0xff0d0000 /usr/lib/libm.so.1
    0xff310000 /usr/lib/libw.so.1
    0xff0b0000 /usr/lib/libmp.so.2
    0xff080000 /opt/bea/jdk131/jre/lib/sparc/native_threads/libhpi.so
    0xff050000 /opt/bea/jdk131/jre/lib/sparc/libverify.so
    0xfe440000 /opt/bea/jdk131/jre/lib/sparc/libjava.so
    0xff020000 /opt/bea/jdk131/jre/lib/sparc/libzip.so
    0xfe230000 /opt/bea/jdk131/jre/lib/sparc/libnet.so
    0xfe160000 /usr/lib/nss_files.so.1
    0xd3700000/opt/bea/wlserver6.1/lib/solaris/oci817_8/libweblogicoci37.so
    0xd3000000 /u01/app/oracle/product/8.1.7/lib/libclntsh.so.8.0
    0xfd090000 /usr/lib/libC.so.5
    0xfd3b0000 /u01/app/oracle/product/8.1.7/lib/libwtc8.so
    0xfd070000 /usr/lib/libgen.so.1
    0xfd050000 /usr/lib/libsched.so.1
    0xfd020000 /usr/lib/libaio.so.1
    0xfafd0000 /opt/bea/wlserver6.1/lib/solaris/libmuxer.so
    Local Time = Thu Apr 3 10:39:37 2003
    Elapsed Time = 178
    # The exception above was detected in native code outside the VM
    # Java VM: Java HotSpot(TM) Client VM (1.3.1-b24 mixed mode)
    # An error report file has been saved as hs_err_pid7599.log.
    # Please refer to the file for further information.
    Abort - core dumped
    TIA
    Tony

  • Sub queries

    i have a longish query which runs correctly in Oracle 8i Lite thro SQL Plus but does not run when using JDBC.
    The query has multiple subqueries and it looks like
    delete from node_initial_values d where d.node_id in (select c.node_id from node_master c where c.node_id=d.node_id and c.node_id in (select e.node_id from network_design e where c.node_id=e.node_id and e.network_id in (select b.network_id from network_master b where e.network_id=b.network_id and b.network_id in (select g.network_id from output_network_scenario g where g.network_id=b.network_id and g.output_network_master_id in (select a.output_network_master_id from output_network_master a where a.output_name= 'network three')))));
    assume all the tables exist with correct data. the above query works perfectly well in SQL*plus but when i use
    the following code i get an error
    PreparedStatement deleteNodeInitialValuesPst=getConn.prepareStatement("delete from node_initial_values d where .... a where a.output_name= ?)))))");
    deleteNodeInitialValuesPst.setString(1,"network three");
    deleteNodeInitialValuesPst.executeUpdate();
    getConn.commit();
    ... rest of the code
    the error code oracle 8i lite gives is
    java.sql.SQLException: [POL-4200] bad action for transaction operation
    would really appreciate any help in this regard...
    specifically can anyone tell me if prepared statement is the correct function to use here...
    thanks

    I made the following changes:
    changes to the code, new code mentioned below
    changed the database to oracle 8i enterprise edition running on NT.
    new code now is
    // connetion parameter and other code here
    String deleteNodeInitialValuesStr=
    "delete from node_initial_values d where d.node_id in (select c.node_id from node_master c where c.node_id=d.node_id and c.node_id in (select e.node_id from network_design e where c.node_id=e.node_id and e.network_id in (select b.network_id from network_master b where e.network_id=b.network_id and b.network_id in (select g.network_id from output_network_scenario g where g.network_id=b.network_id and g.output_network_master_id in (select a.output_network_master_id from output_network_master a where a.output_name='"+nextElementStr+"')))))";
    Statement deleteNodeInitialValuesSt=getConn.createStatement();
              deleteNodeInitialValuesSt.executeQuery(deleteNodeInitialValuesStr);
    getConn.commit();
    } // end try
    catch(SQLException ex) {
         while(ex !=null){
    out.println("Java SQL Exception: " + ex.getMessage()+"<br>");
    out.println("Vendor error code: " + ex.getErrorCode()+ "<br>");
    out.println("SQL State: " + ex.getSQLState() + "<br>");
    ex=ex.getNextException();
    } // end while
    } // end catch
    // more code here
    the output i get is
    Java SQL Exception: 202
    Vendor error code: 0
    SQL State: null
    I turned off getConn.commit(), but the error code remains the same. is there an alternative to the sub queries above. where can i get the meaning of the error codes thrown by the exception ?
    thanks

  • Max date

    I'm trying to pull records that have the max date from multiple subqueries. I've tried different sql statements, but am not able to get the results I want. I want the last record only from the three rows in the result set (the latest/max date). I'm thinking I need to do a max(date) in the from clause and then select out of it but I'm having difficulties.
    Any suggestions welcome!
    Example:
    select w.name, m.ida2a2, m.role, m.ida3a4, max(m.updatestampa2) as "UPDATE"
    from map m , user w
    where m.ida2a2 in (select ida3a5
    from link
    where ida3b5 in (select ida3teamid
    from pdoc)
    and role in ('PI')
    and ida3a4 != 0
    and w.ida2a2 = m.ida3a4
    group by w.name,m.ida2a2, m.role, m.ida3a4
    SQL Results:
    NAME Ida2a2 ROLE Ida3a4 UPDATE
    stella 78420 PI 6171 16-DEC-05
    stella 88057 PI 6171 20-DEC-05
    stella 123432 PI 6171 06-JAN-06

    C,
    Thanks for your help. I don't think I explained myself clearly, may the below will help me clarify.
    I want the max update for each group of rows only. ie stella 06-JAN-06, carson 09-JAN-06, lee I need to get the hour,minute, and seconds to figure out which 31-JAN-06 is max, but I wanted the main algorthim correct first.
    For example:
    group one of result set rows
    NAME Ida2a2 ROLE Ida3a4 UPDATE
    stella 78420 PI 6171 16-DEC-05
    stella 88057 PI 6171 20-DEC-05
    stella 123432 PI 6171 06-JAN-06
    carson 79138 PI 6207 16-DEC-05
    carson 90679 PI 6207 20-DEC-05
    carson 130781 PI 6207 09-JAN-06
    lee 227198 PI 215068 30-JAN-06
    lee 390372PI 215068 31-JAN-06
    lee 390682PI 215068-31-JAN-06

  • LIKE operator in multiple-row subqueries

    Hello,
    in a test i saw 2 questions:
    Which operator can be used with a multiple-row subquery?
    A. =
    B. LIKE
    C. BETWEEN
    D. NOT IN
    E. IS
    F. <>
    Answer: D
    and
    Which two statements about subqueries are true? (Choose two.)
    A. A single row subquery can retrieve data from only one table.
    B. A SQL query statement cannot display data from table B that is referred to in its
    subquery, unless table B is included in the main query's FROM clause.
    C. A SQL query statement can display data from table B that is referred to in its subquery,
    without including table B in its own FROM clause.
    D A single row subquery can retrieve data from more than one table.
    E. A single row subquery cannot be used in a condition where the LIKE operator is used for
    comparison.
    F. A multiple-row subquery cannot be used in a condition where the LIKE operator is used for
    comparison.
    Answer: B & D
    But in the last question, why F is not correct? because the 1st question says that only NOT IN can be used in multiple-row subqueries. I'm confused
    Thanks

    only two, but what principle applies if not specified? First two correct?
    however, in explanation i saw something like this (regarding to the 2nd question)
    Incorrect Answers
    A: A single row sub-query can retrieve data from more than one table.
    C: A SQL query statement cannot display data from table B that is referred to in its subquery,
    unless table B is included in the main query's FROM clause.
    E: A single row sub-query can be used in a condition where the LIKE operator is used for
    comparison.
    F: A multiple-row sub-query can be used in a condition where the LIKE operator is used for
    comparison.
    so, at F: can be used or nor? they aren't so clear. only which operators can be used in multiple-row subquery?

  • Query on  Multiple-Row subqueries

    Multiple-row subqueries:
    -->"They should not be used with the NOT IN operator in the main query if NULL is likely to be part of the result of the subquery "
    -->"They can be used to retrieve multiple rows from a single table only"
    But i checked the following example
    select a.n1
    from t1 a
    where a.n1 not in (Select *
                 from t2 b)Where t2 contains null values
    And query is giving no error
    So the second option is correct i feel.
    Could you suggest me
    Edited by: josh1612 on Mar 7, 2010 10:38 PM

    -->"They should not be used with the NOT IN operator in the main query if NULL is likely to be part of the result of the subquery "Here is a simple example, there is no value in T2 for the column No as 1 but still you dont get any row. That is because NULL means UNKNOWN. You cant use it in comparison.
    create table t1(no integer)
    create table t2(no integer)
    insert into t1 values(1)
    insert into t2 values (null)
    insert into t2 values (2)
    select *
      from t1
    where t1.no not in (select no from t2)
    /Now delete the null value and try
    delete from t2 where no is null
    select *
      from t1
    where t1.no not in (select no from t2)
    /

  • Multiple-row subqueries

    "Multiple-row subqueries should not be used with the NOT IN operator in the main query if NULL is likely to be a part of the result of the subquery"----Is this statement correct?

    gOMzY wrote:
    And i am sure that this is also correct:
    Multiple-row subqueries use the < ALL operator to imply less than the maximum - - - - - - - - - Correct?It would depend on the sub-query. This IN query:
    SQL> with t as (
      2     select 1 id, 'ABC' type from dual union all
      3     select 2, 'DEF' from dual union all
      4     select 3, 'GHI' from dual union all
      5     select 4, 'JKL' from dual),
      6  t1 as (
      7     select 'ABC' col1 from dual union all
      8     select 'JKL' from dual)
      9  SELECT * FROM t
    10  WHERE type IN (SELECT col1 FROM t1);
            ID TYP
             1 ABC
             4 JKLis exactly equivalent to:
    SQL> with t as (
      2     select 1 id, 'ABC' type from dual union all
      3     select 2, 'DEF' from dual union all
      4     select 3, 'GHI' from dual union all
      5     select 4, 'JKL' from dual),
      6  t1 as (
      7     select 'ABC' col1 from dual union all
      8     select 'JKL' from dual)
      9  SELECT * FROM t
    10  WHERE type = ANY (SELECT col1 FROM t1);
            ID TYP
             1 ABC
             4 JKLThere is no < ALL either implied or explicit required by definition.
    John

  • "Invalid Column" on multiple where clauses with subqueries and cfqueryparam

    I'm seeing a behavior in the coldfusion cfquery that I'd like to find an exmplanation for .  I've got a query that does a subquery in the select portion and if I have multiple where lines, I get an "invalid column name" message for my second where clause, but only when I'm using cfqueryparam
    For example on the following I get "Invalid column name 'position_id'"
    SELECT   department_staff_tbl.*,
             (   SELECT   max(bookmark_id)
                 FROM     bookmarked_items_tbl
                 WHERE    item_id = department_staff_tbl.staff_id
             ) AS bookmark_id
    FROM     department_staff_tbl
    WHERE    department_id = <cfqueryparam value="#arguments.deptid#"  cfsqltype="cf_sql_integer">
    AND     position_id   = <cfqueryparam value="#arguments.posid#"   cfsqltype="cf_sql_integer">
    AND     staff_id      = <cfqueryparam value="#arguments.staffid#" cfsqltype="cf_sql_integer">
    If I change the order of my where clause so staff_id is first, then it tells me "department_id" is an invalid column.
    If I only have one where clause, it works.  (i.e. WHERE position_id = <cfqueryparam value="#arguments.posid#" cfsqltype="cf_sql_integer">).
    If I remove the where clause from my subquery (WHERE     item_id = department_staff_tbl.staff_id) it works.
    It also works if I remove the cfqueryparam from my where clause so that my query looks like this:
    SELECT   department_staff_tbl.*,
             (   SELECT   max(bookmark_id)
                 FROM     bookmarked_items_tbl
                 WHERE    item_id = department_staff_tbl.staff_id
             ) AS bookmark_id
    FROM     department_staff_tbl
    WHERE    department_id = #arguments.deptid#
    AND     position_id   = #arguments.posid#
    AND     staff_id      = #arguments.staffid#
    Any thoughts?

    I see two tables. So can the server. So, use qualified column-names.
    SELECT   department_staff_tbl.*,
             (   SELECT   max(bookmarked_items_tbl.bookmark_id)
                 FROM     bookmarked_items_tbl
                 WHERE    bookmarked_items_tbl.item_id = department_staff_tbl.staff_id
             ) AS bookmark_id
    FROM     department_staff_tbl
    WHERE    department_staff_tbl.department_id = <cfqueryparam value="#arguments.deptid#"  cfsqltype="cf_sql_integer">
    AND      department_staff_tbl.position_id   = <cfqueryparam value="#arguments.posid#"   cfsqltype="cf_sql_integer">
    AND      department_staff_tbl.staff_id      = <cfqueryparam value="#arguments.staffid#" cfsqltype="cf_sql_integer">

  • Multiple nested JDOQL subqueries

    Hello,
    we are currnently using the JDOQL Subqueries feature of Kodo as
    described in
    http://solarmetric.com/Software/Documentation/3.4.1/docs/ref_guide_subqueries.html
    My question is if it is possible to nest JDOQL subqueries and, if yes,
    what is
    the syntax for this?
    I tried to perform something like:
    ( x != 0 &&
    (( select from AClass a where
    (a.field1 == "1" &&
    (( select from BClass b where
    b.field2 == 1).contains(a.reference))
    ).contains(anotherreference))
    but I get the following error message:
    " The keyword "from" is in the wrong position. "
    Could you give me some hints on how to correct the query, if possible?
    Thanks,
    Werner
    W?rth Phoenix S.r.l.
    Werner Boninsegna
    Product Development
    Via Kravogl 4
    I-39100 Bolzano
    Direct: +39 0471 564074
    Fax: +39 0471 564122
    E-Mail: mailto:[email protected]
    Website: http://www.wuerth-phoenix.com

    Abe White wrote:
    Please post the full stack trace.Hi,
    sure, thanks.
    ===========================================================================================================================
    kodo.util.UserException: The query string "( _createDate != 0 && (( select from
    com.wuerth.phoenix.Bart.bc.persistent.jdo.CompositePatternPeer CompositePatternAlias424216307483080866 where
    ( CompositePatternAlias424216307483080866._field1 == "1" && (( select from
    com.wuerth.phoenix.Bart.bc.persistent.jdo.BasicTypesPeer BasicTypesAlias424216307483080866 where
    BasicTypesAlias424216307483080866._fieldLong == 1010 ).contains
    ( CompositePatternAlias424216307483080866._parentBasicTypes )) ) ).contains ( _assCompositePattern )) )" is not valid. The
    keyword "from" is in the wrong position.
    at kodo.query.QueryString.fromWords(QueryString.java:154)
    at kodo.query.FilterParser.scan(FilterParser.java:1019)
    at kodo.query.FilterParser.parse(FilterParser.java:727)
    at kodo.query.FilterParser.parseExpression(FilterParser.java:507)
    at kodo.query.JDOQLQuery$DataStoreExecutor.<init>(JDOQLQuery.java:504)
    at kodo.query.JDOQLQuery.newDataStoreExecutor(JDOQLQuery.java:83)
    at kodo.query.AbstractQuery.createExecutor(AbstractQuery.java:625)
    at kodo.query.AbstractQuery.compileForDataStore(AbstractQuery.java:576)
    at kodo.query.AbstractQuery.compileForExecutor(AbstractQuery.java:556)
    at kodo.query.AbstractQuery.compile(AbstractQuery.java:474)
    at com.wuerth.phoenix.internal.bc.server.query.jdo.JDOPhoenixQueryImpl.callQuery(JDOPhoenixQueryImpl.java:2436)
    ===========================================================================================================================
    Regards,
    Werner

  • Case statement in a multiple query

    Hi everyone,
    This is my first time to use case statement in a multiple query. I have tried to implement it but i got no luck.. Please see below
    set define off
    SELECT g.GROUP_NAME as Market
    ,t.NAME as "Template Name"
    ,t.TEMPLATE_ID as "Template ID"
    ,(SELECT created
    FROM material
    where template_id = t.template_id) as "Date Created"
    *,(SELECT DESTINATION_FOLDER_ID,*
    CASE DESTINATION_FOLDER_ID
    WHEN NULL THEN 'Upload'
    ELSE 'HQ'
    END
    from log_material_copy
    where destination_material_id in (select material_id
    from material
    where template_id = t.template_id ))as "Origin"
    ,(select material_id
    from log_material_copy
    where destination_material_id in (select material_id
    from material
    where template_id = t.template_id)) as "HQ/Upload ID"
    ,(SELECT COUNT (mse.ID)
    FROM MATERIAL_SEND_EVENT mse, material m, creative c
    WHERE mse.MATERIAL_ID = m.MATERIAL_ID
    AND mse.MATERIAL_TYPE_ID = m.MATERIAL_TYPE_ID
    AND m.ASSET_ID = c.id
    AND c.TEMPLATE_ID = t.TEMPLATE_ID) as Sent
    ,(SELECT COUNT (de.ID)
    FROM download_event de, material m, creative c
    WHERE de.MATERIAL_ID = m.MATERIAL_ID
    AND de.MATERIAL_TYPE_ID = m.MATERIAL_TYPE_ID
    AND m.ASSET_ID = c.id
    AND c.TEMPLATE_ID = t.TEMPLATE_ID) as Download
    ,(SELECT 'https://main.test.com/bm/servlet/' || 'UArchiveServlet?action=materialInfo&materialId=' || DESTINATION_MATERIAL_ID || '&materialFolderId=' || DESTINATION_FOLDER_ID
    from log_material_copy
    where destination_material_id in (select material_id
    from material
    where template_id = t.template_id)) as "URL to template on MPC layer"
    --, t.AVAILABLE_FOR_TRANSFER as "Available for transfer"
    FROM template t, layout l, groups g
    WHERE t.LAYOUT_ID = l.LAYOUT_ID
    AND l.ORGANIZATION_ID = g.IP_GROUPID
    AND g.IP_GROUPID in ( 1089, 903, 323, 30, 96, 80, 544, 1169, 584, 785, 827, 31, 10, 503, 1025 )
    ORDER BY g.GROUP_NAME ASC;
    The one in bold is my case statement.. Please let me know what is wrong with this.
    Regards,
    Jas

    I think you're getting the idea, but:
    You're still selecting 2 columns in the (scalar) subquery. Did you read the link I posted for you?
    "a) scalar subqueries - *a single row, single column query that you use in place of a "column"*, it looks like a column or function."
    You must move that query outside, join to template.
    Something like:
    NOT TESTED FOR OBVIOUS REASONS SO YOU'LL PROBABLY NEED TO TWEAK IT A BIT
    select g.group_name as market,
           t.name as "Template Name",
           t.template_id as "Template ID",
           m.created  as "Date Created",
           lmc.destination_folder_id,
           case lmc.destination_folder_id
             when null then 'Upload'
             else 'HQ'
           end as "Origin"
           (select material_id
              from log_material_copy
             where destination_material_id in
                   (select material_id
                      from material
                     where template_id = t.template_id)) as "HQ/Upload ID"
           (select count(mse.id)
              from material_send_event mse, material m, creative c
             where mse.material_id = m.material_id
               and mse.material_type_id = m.material_type_id
               and m.asset_id = c.id
               and c.template_id = t.template_id) as sent
           (select count(de.id)
              from download_event de, material m, creative c
             where de.material_id = m.material_id
               and de.material_type_id = m.material_type_id
               and m.asset_id = c.id
               and c.template_id = t.template_id) as download
           (select 'https://main.test.com/bm/servlet/' ||
                   'UArchiveServlet?action=materialInfo&materialId=' ||
                   destination_material_id || '&materialFolderId=' ||
                   destination_folder_id
              from log_material_copy
             where destination_material_id in
                   (select material_id
                      from material
                     where template_id = t.template_id)) as "URL to template on MPC layer"
    --, t.AVAILABLE_FOR_TRANSFER as "Available for transfer"
      from template t
      ,    layout l
      ,    groups group by
      ,    MATERIAL M
      ,    LOG_MATERIAL_COPY LMC
    where t.layout_id = l.layout_id
       and l.organization_id = g.ip_groupid
       and M.TEMPLATE_ID = t.template_id
       and LMC.destination_material_id in ( select material_id
                                            from   material
                                            where  template_id = t.template_id
       and g.ip_groupid in (1089,
                            903,
                            323,
                            30,
                            96,
                            80,
                            544,
                            1169,
                            584,
                            785,
                            827,
                            31,
                            10,
                            503,
                            1025)
    order by g.group_name asc;

Maybe you are looking for

  • CS4 project into CS5?

    Will a CS4 project open in CS5 (Maybe you could do a test on this Harm if you have time.) I would like to know so I can plan project migration to a new system. Answer would be good for the CS5 FAQ sub forum

  • Why do image links in my HTML signature get turned into inline images?

    I have written a program to create HTML signature files for email programs at my workplace. The signature file uses URLs to images hosted on a server. This appears to work fine, but I've noticed that when I send an email from Icedove (Thunderbird reb

  • How to create thumbnail images on the fly from JSP or servlet?

    Hi all, Iam new to this forum. I need a solution for the problem iam facing in building my site. Ihave groups and briefcase section in my site. I allow users to upload files and pictures. When they upload pictures i need to create thumbnail for them

  • Treasury Cash Mngmnt 0TRCM_C01Business content extractors

    Hi, all Have anybody worked with subj. InfoProvider? There is NO help in SAP regarding this Business content. I get data but it is different from data in ECC Cash Management report :/ URGENTLY need help to understand logic of this extractor...

  • Mapping text item

    hi i have a form component text item in oracle forms6i. so i created a <af:inputText> in my jsp page. and i gave the width and height same as the value of form's component text item in pixels. The problem is that even though i gave the same value for