WITH clause query:- Returns No Rows

Hi,
I am using the following query with, WITH clause, but some how it give "0 rows" returned,
The underlying query does returns row when run in stand alone mode,
With v_score_his_old
As
SELECT schs_run_date,schs_loc_shortcut_source,schs_lot_number,schs_facility_new,schs_facility_old, schs_operation_new,
schs_operation_old,schs_route_new,schs_route_old,schs_product_new,schs_product_old,schs_owner_old,schs_intransit,
schs_date,schs_transaction,schs_quantity_1_new,schs_quantity_1_old,/*0,*/schs_if_count_new,schs_if_count_old,
schs_preprocessed,schs_consumed_quantity,/*'Y',*/schs_if_id,schs_if_id_old,fif_fac_loc_id
FROM scm_score_his,full_item_facilities,location_params
WHERE schs_state = 0
AND fif_if_id = schs_if_id_old
AND lopo_param_value = to_char(fif_site_id_fm)
AND lopo_param_name IN ('SITE_FAB', 'SITE_SORT')
AND (schs_loc_shortcut_source = 'MP' OR schs_loc_shortcut_source = 'RE' OR schs_loc_shortcut_source = 'VI')
UNION ALL
SELECT schb_run_date,schb_loc_shortcut_source,schb_lot_number,schb_facility_new,schb_facility_old,schb_operation_new,
schb_operation_old,schb_route_new,schb_route_old,schb_product_new,schb_product_old,schb_owner_old,schb_intransit,
schb_date,schb_transaction,schb_quantity_1_new,schb_quantity_1_old,/*0,*/schb_if_count_new,schb_if_count_old,schb_preprocessed,
schb_consumed_quantity,/*'Y',*/schb_if_id,schb_if_id_old,fif_fac_loc_id
FROM scm_score_his_backups,full_item_facilities,location_params
WHERE schb_state = 0
AND fif_if_id = schb_if_id_old
AND lopo_param_value = to_char(fif_site_id_fm)
AND lopo_param_name IN ('SITE_FAB', 'SITE_SORT')
AND schb_date >= trunc(sysdate - 84)
AND (schb_loc_shortcut_source = 'MP' OR schb_loc_shortcut_source = 'RE' OR schb_loc_shortcut_source = 'VI')
Select schs_run_date,schs_loc_shortcut_source,schs_lot_number
From v_score_his_old
Where schs_loc_shortcut_source = 'MP';
Oracle version is Oracle9i Enterprise Edition Release 9.2.0.6.0
I am not able to get where I can going wrong.
Please help me to understand this issue,
Regards
Umesh..

With v_score_his_old
As
SELECT
schs_run_date,schs_loc_shortcut_source,schs_lot_numbe
,schs_facility_new,schs_facility_old,
schs_operation_new,
chs_operation_old,schs_route_new,schs_route_old,schs_p
roduct_new,schs_product_old,schs_owner_old,schs_intran
sit,
chs_date,schs_transaction,schs_quantity_1_new,schs_qua
ntity_1_old,/*0,*/schs_if_count_new,schs_if_count_old,
chs_preprocessed,schs_consumed_quantity,/*'Y',*/schs_i
f_id,schs_if_id_old,fif_fac_loc_id
FROM
cm_score_his,full_item_facilities,location_params
WHERE schs_state = 0
AND fif_if_id = schs_if_id_old
AND lopo_param_value =
to_char(fif_site_id_fm)
AND lopo_param_name IN ('SITE_FAB',
'SITE_SORT')
AND (schs_loc_shortcut_source = 'MP' OR
schs_loc_shortcut_source = 'RE' OR
schs_loc_shortcut_source = 'VI')
UNION ALL
SELECT
schb_run_date,schb_loc_shortcut_source,schb_lot_number
,schb_facility_new,schb_facility_old,schb_operation_ne
w,
chb_operation_old,schb_route_new,schb_route_old,schb_p
roduct_new,schb_product_old,schb_owner_old,schb_intran
sit,
chb_date,schb_transaction,schb_quantity_1_new,schb_qua
ntity_1_old,/*0,*/schb_if_count_new,schb_if_count_old,
schb_preprocessed,
chb_consumed_quantity,/*'Y',*/schb_if_id,schb_if_id_ol
d,fif_fac_loc_id
FROM
cm_score_his_backups,full_item_facilities,location_par
ams
WHERE schb_state = 0
AND fif_if_id = schb_if_id_old
AND lopo_param_value =
to_char(fif_site_id_fm)
AND lopo_param_name IN ('SITE_FAB',
'SITE_SORT')
AND schb_date >= trunc(sysdate - 84)
AND (schb_loc_shortcut_source = 'MP' OR
schb_loc_shortcut_source = 'RE' OR
schb_loc_shortcut_source = 'VI')
ect
schs_run_date,schs_loc_shortcut_source,schs_lot_number
From v_score_his_old
Where schs_loc_shortcut_source = 'MP';
Hi!
I've a doubt. If u finally picking all the values which matched with field schs_loc_shortcut_source and which is 'MP' - then why r u using multiple condition in the WITH part? So, in that case, u don't have to write that additional filtering of the following lines in the outer query -
Where schs_loc_shortcut_source = 'MP';Regards.
Satyaki De.

Similar Messages

  • TimesTen SQL with group by returning multiple rows

    I have a Active-Standby TimesTen nodes.
    Using group by with or without having clause:
    Whenever I do a group by query on table1 table with or without having clause, SQL returns multiple rows. This looks very strange to me. Each time it gives different count
    Command> select count(*) from table1 group by pname having pname='pool';
    < 390400 >
    1 row found.
    Command> select count(*) from table1 group by pname having pname='pool';
    < 390608 >
    < 32639 >
    2 rows found.
    Command> select count(*) from table1 group by pname having pname='pool';
    < 2394 >
    < 351057 >
    2 rows found.
    Command> select count(*) from table1 group by pname having pname='pool';
    < 305732 >
    1 row found.
    Command> select count(*) from table1 group by pname having pname='pool';
    < 420783 >
    1 row found.
    Command> select count(*),pool_name from root.rms_address_pools group by pool_name order by pool_name;
    < *435473, pool* >
    < *32313, pool* >
    < 453, smvG3 >
    < *28980, pool* >
    < 3786, smvG4 >
    < *26025, pool* >
    < 236120, smvG6 >
    < 131455, smcG3 >
    < *65150, pool* >
    < 23, snt1G1 >
    < 510, snt2G1 >
    < 510, snt2G2 >
    Using where clause:
    Command> select count(*) from table1 where pname='pool';
    < *442354* >
    1 row found.
    Command> select count(*) from table1 where pname='pool';
    < 442354 >
    1 row found.
    Table description:
    Command> desc table1;
    Table table1:
    Columns:
    *IP_ADDRESS                      BIGINT NOT NULL
    PNAME CHAR (32) NOT NULL
    SITEID TINYINT NOT NULL
    1 table found.
    ttVersion:
    bash-3.00# ./ttVersion
    TimesTen Release *7.0.3.1.0 (64 bit Solaris)* (tt70:17001) 2007-10-30T22:17:07Z
    Instance admin: root
    Instance home directory: /TimesTen/tt70
    Daemon home directory: /var/TimesTen/tt70
    bash-3.00#
    Could any one suggest what is wrong with my SQL? or is it a bug with TimesTen?
    Many thanks in advance.
    Br,
    Brij

    Hi Gena,
    When i execute the query with where clause, it gives me the output with more than one pool:
    Command> select pname, count (*) from table1 where pname='pool' group by pname ;
    < smcG3 , 18836 >
    < pool , 423527 >
    2 rows found.
    Command> select pname, count (*) from table1 where pname='pool' group by pname ;
    < intG302 , 17202 >
    < pool , 425159 >
    2 rows found.
    While if give use the having clause it gives me multiple rows for one pool only ( sometimes) :
    select pname, count (*) from table1 group by pname having pname='pool';
    < pool , 32686 >
    < pool , 420445 >
    2 rows found.
    select pname, count (*) from table1 group by pname having pname='pool';
    < pool , 393574 >
    < pool , 5838 >
    < pool , 110943 >
    3 rows found.
    Command> select pname, count (*) from table1 group by pname having pname='pool';
    < pool , 414590 >
    < pool , 8395 >
    2 rows found.
    Please suggest what can be done in this case, need i open a case with Oracle for this.
    Regards, Brij

  • XML attributes makes my query return no rows

    Hello everyone,
    I've an odd problem.
    I'm querying some XML, but the attributes in one of the tags make my query return no rows; if I remove the attributes, then the query works as expected.
    The XML is below; it's the attributes in the Report tag that cause the issues:
    <result errorCode="0">
         <return>
              <Report
                   xsi:schemaLocation="Items_x0020_status_x0020_information http://******-****/ReportServer?%2FReports%2FContent%20Producer%20Reports%2FItems%20status%20information&amp;rs%3AFormat=xml&amp;rc%3ASchema=True"
                   Name="Items status information" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns="Items_x0020_status_x0020_information">
                   <Tablix1>
                        <Details_Collection>
                             <Details ItemId="914P7" Username="test" user_role="IT"
                                  first_name="Barry" last_name="Donovan" organisation=""
                                  content_format="On_Screen" modified_date="26/05/2011 13:16:49"
                                  item_status="Draft" status_date="" component_name="" demand="" />
                        </Details_Collection>
                   </Tablix1>
              </Report>
         </return>
    </result>My query is:
         select
                a.item_id
               ,a.username
               ,a.user_role
               ,a.first_name
               ,a.last_name
               ,a.supplier_id
               ,a.format
               ,a.modified_date
               ,a.item_status
               ,a.completion_date
               ,a.component_code
             from   dual
                   ,xmltable
                    ('/result/return/Report/Tablix1/Details_Collection/Details'
                       passing p_xml
                       columns
                          item_id         varchar2(1000) path '@ItemId'
                         ,username        varchar2(1000) path '@Username'
                         ,user_role       varchar2(1000) path '@user_role'
                         ,first_name      varchar2(1000) path '@first_name'
                         ,last_name       varchar2(1000) path '@last_name'
                         ,supplier_id     varchar2(1000) path '@organisation'
                         ,format          varchar2(1000) path '@content_format'
                         ,modified_date   varchar2(1000) path '@modified_date'
                         ,item_status     varchar2(1000) path '@item_status'
                         ,completion_date varchar2(1000) path '@status_date'
                         ,component_code  varchar2(1000) path '@demand'
                    ) a;I've tried stripping out the attributes in the tag, which does work, but some of the XML I'm expecting back may be quite large (many records), so that caused issues in itself. I'd rather deal with it and not mess with the XML itself if possible.
    Any help would be hugely appreciated!
    Thank you very much in advance.
    Robin
    Edited by: User_resU on Apr 12, 2012 2:50 PM

    Example:
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select xmltype('<result errorCode="0">
      2     <return>
      3             <Report
      4                     xsi:schemaLocation="Items_x0020_status_x0020_information http://******-****/ReportServer?%2FReports%2FContent%20Producer%20Reports%2FItems%20status%20information&amp;rs%3AFormat=xml&amp;rc%3ASchema=True"
      5                     Name="Items status information" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      6                     xmlns="Items_x0020_status_x0020_information">
      7                     <Tablix1>
      8                             <Details_Collection>
      9                                     <Details ItemId="914P7" Username="test" user_role="IT"
    10                                             first_name="Barry" last_name="Donovan" organisation=""
    11                                             content_format="On_Screen" modified_date="26/05/2011 13:16:49"
    12                                             item_status="Draft" status_date="" component_name="" demand="" />
    13                             </Details_Collection>
    14                     </Tablix1>
    15             </Report>
    16     </return>
    17  </result>') as xml from dual)
    18  --
    19  -- end of test data
    20  --
    21       select
    22              a.item_id
    23             ,a.username
    24             ,a.user_role
    25             ,a.first_name
    26             ,a.last_name
    27             ,a.supplier_id
    28             ,a.format
    29             ,a.modified_date
    30             ,a.item_status
    31             ,a.completion_date
    32             ,a.component_code
    33           from   t
    34                 ,xmltable
    35                  (xmlnamespaces('Items_x0020_status_x0020_information' as "x0"),
    36                   '//x0:Report/x0:Tablix1/x0:Details_Collection/x0:Details'
    37                     passing xml
    38                     columns
    39                        item_id         varchar2(1000) path '@ItemId'
    40                       ,username        varchar2(1000) path '@Username'
    41                       ,user_role       varchar2(1000) path '@user_role'
    42                       ,first_name      varchar2(1000) path '@first_name'
    43                       ,last_name       varchar2(1000) path '@last_name'
    44                       ,supplier_id     varchar2(1000) path '@organisation'
    45                       ,format          varchar2(1000) path '@content_format'
    46                       ,modified_date   varchar2(1000) path '@modified_date'
    47                       ,item_status     varchar2(1000) path '@item_status'
    48                       ,completion_date varchar2(1000) path '@status_date'
    49                       ,component_code  varchar2(1000) path '@demand'
    50*                 ) a
    SQL> /
    ITEM_ID
    USERNAME
    USER_ROLE
    FIRST_NAME
    LAST_NAME
    SUPPLIER_ID
    FORMAT
    MODIFIED_DATE
    ITEM_STATUS
    COMPLETION_DATE
    COMPONENT_CODE
    914P7
    test
    IT
    Barry
    Donovan
    On_Screen
    26/05/2011 13:16:49
    Draft

  • Query returns more row than expected

    1. select * from view_name where col1 = 'value1' returns 12 rows
    2. select * from (view script) where col1 = 'value1' returns 24 rows
    i have a view called view_name. If i use view_name directly in the query, it returns 12 rows. But if i use the select script directly in from clause, it returns more rows. I am not able to find out why it is happening so. Any pointers will be helpful.

    Are you saying that the SQL for view_name and view_script are identical? Can you post them?

  • WITH Clause query doesn't work in Oracle Reports.

    Hi Gurus,
    I'm using a WITH clause query and need to build a report using the same query.
    But when i'm trying to build a report, query is giving error as "WITH clause table or view doesn't exists".
    But the same query perfectly works in sql prompt.
    Oracle Reports doesn't supports WITH clause query?
    Please suggest.
    Thanks,
    Onkar

    I ran into a similar problem before and worked around it by moving the query to a pipelined function in the database as described at WITH clause unexpectedly causes ORA-00942 in Reports Builder
    Hope this helps.

  • How to use "with clause query" in DBadapter

    Hi all,
    I need to implement a "with clause" query in oracle soa 11g bpel. When i put the query in db adapter in pure sql, the schema is not getting generated properly. Can any one suggest a solution to my problem.
    Regards,
    Kaushik

    Pure SQL won't work because it is expecting the first word in the SQL to be SELECT (or INSERT,UPDATE,DELETE).
    If your query is WITH ... SELECT ...
    try this:
    delete everything before SELECT. Copy and paste the generated XSD to another window. The SQL test may fail, but that will just mean that it couldn't fill in the types of the columns in the SELECT ... FROM list. You can always do that yourself by hand editing the XSD (including in the wizard before you hit next). Then put back the WITH ... clause before the remaining SELECT .... If the XSD gets overwritten, copy the version you saved in the other window and paste it over top. Then hit next and the runtime should still work.
    Keep in mind that SQL is very complex and hard to fully parse in the UI. However the minimum information the DbAdapter needs is quite limited; basically just the name and number of columns that are coming back. The XSD is meant to be editable in the wizard if the SQL is too complex.
    Thanks
    Steve

  • Silly old fogey (me) cannot figure out why this query returns 1 row

    Hi all,
    In reference to {thread:id=2456973}, why does
    select sum(count(decode(job, 'CLERK', 1, null))) CLERKS
    , sum(count(decode(job, 'SALESMAN', 1, null))) SALESMANS
    from emp group by job;only return 1 row and not 1 for each job? I actually had to test it myself to believe it.
    It returns data as if the query were
    select sum(CLERKS), sum(SALESMANS)
    from (select count(decode(job, 'CLERK', 1, null)) CLERKS, count(decode(job, 'SALESMAN', 1, null)) SALESMANS
             from emp group by job)Using only a single aggregate (either count or sum) returns 1 row per job, as expected

    John Stegeman wrote:
    It returns data as if the query were
    select sum(CLERKS), sum(SALESMANS)
    from (select count(decode(job, 'CLERK', 1, null)) CLERKS, count(decode(job, 'SALESMAN', 1, null)) SALESMANS
    from emp group by job)
    Exactly the point ;-)
    Seems like Oracle actually can do a "double group by" in the same operation.
    Witness the explain plans in this example:
    SQL> select count(decode(job, 'CLERK', 1, null)) CLERKS
      2       , count(decode(job, 'SALESMAN', 1, null)) SALESMANS
      3  from scott.emp group by job;
        CLERKS  SALESMANS
             0          0
             0          0
             0          0
             0          4
             4          0
    Execution Plan
    Plan hash value: 1697595674
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |     5 |    40 |     4  (25)| 00:00:01 |
    |   1 |  HASH GROUP BY     |      |     5 |    40 |     4  (25)| 00:00:01 |
    |   2 |   TABLE ACCESS FULL| EMP  |    14 |   112 |     3   (0)| 00:00:01 |
    ---------------------------------------------------------------------------And compare it to this one with the double aggregates:
    SQL> select sum(count(decode(job, 'CLERK', 1, null))) CLERKS
      2       , sum(count(decode(job, 'SALESMAN', 1, null))) SALESMANS
      3  from scott.emp group by job;
        CLERKS  SALESMANS
             4          4
    Execution Plan
    Plan hash value: 417468012
    | Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT    |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   1 |  SORT AGGREGATE     |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   2 |   HASH GROUP BY     |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   3 |    TABLE ACCESS FULL| EMP  |    14 |   112 |     3   (0)| 00:00:01 |
    ----------------------------------------------------------------------------There is both HASH GROUP BY and SORT AGGREGATE.
    It does not really make sense to do an aggregate on an aggregate - if both aggregates are used "on the same group-by level".
    The sum() aggregates are used upon an already aggregated value, so it does look like Oracle actually treats that as "first do the inner aggregate using the specified group by and then do the outer aggregate on the result with no group by."
    Look at this example where I combine "double" aggregates with "single" aggregates:
    SQL> select sum(count(decode(job, 'CLERK', 1, null))) CLERKS
      2       , sum(count(decode(job, 'SALESMAN', 1, null))) SALESMANS
      3       , count(decode(job, 'SALESMAN', 1, null)) SALESMANS2
      4       , count(*) COUNTS
      5  from scott.emp group by job;
        CLERKS  SALESMANS SALESMANS2     COUNTS
             4          4          1          5
    Execution Plan
    Plan hash value: 417468012
    | Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT    |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   1 |  SORT AGGREGATE     |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   2 |   HASH GROUP BY     |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   3 |    TABLE ACCESS FULL| EMP  |    14 |   112 |     3   (0)| 00:00:01 |
    ----------------------------------------------------------------------------When mixing "double" and "single" aggregates, Oracle decides that single aggregates belong in the "outer" aggregation.
    SALESMAN2 is doing a count on the aggregated job column that is the result of the "inner" group by - therefore only 1.
    The count(*) also counts the result of the "inner" aggregation.
    I am not sure if this is documented or if it is a "sideeffect" of either the internal code used for GROUPING SETS or the internal code used for allowing analytic functions like this:
    SQL> select count(decode(job, 'CLERK', 1, null)) CLERKS
      2       , count(decode(job, 'SALESMAN', 1, null)) SALESMANS
      3       , sum(count(decode(job, 'CLERK', 1, null))) over () CLERKS2
      4       , sum(count(decode(job, 'SALESMAN', 1, null))) over () SALESMANS2
      5  from scott.emp group by job;
        CLERKS  SALESMANS    CLERKS2 SALESMANS2
             0          0          4          4
             4          0          4          4
             0          0          4          4
             0          0          4          4
             0          4          4          4
    Execution Plan
    Plan hash value: 4115955660
    | Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT    |      |     5 |    40 |     4  (25)| 00:00:01 |
    |   1 |  WINDOW BUFFER      |      |     5 |    40 |     4  (25)| 00:00:01 |
    |   2 |   SORT GROUP BY     |      |     5 |    40 |     4  (25)| 00:00:01 |
    |   3 |    TABLE ACCESS FULL| EMP  |    14 |   112 |     3   (0)| 00:00:01 |
    ----------------------------------------------------------------------------Personally I think I would have preferred if Oracle raised an error on this "double aggregation" and thus require me to write it this way (if that is the result I desired):
    select sum(CLERKS), sum(SALESMANS)
    from (select count(decode(job, 'CLERK', 1, null)) CLERKS, count(decode(job, 'SALESMAN', 1, null)) SALESMANS
             from emp group by job)I can not really think of good use-cases for the "double aggregation" - but rather that it could give you unnoticed bugs in your code if you happen to do double aggregation without noticing it.
    Interesting thing to know ;-)

  • SQL Query returning no rows, please help!!

    I have a table that contains user audits for a particular procedures alongwith the date stamp. Now, I want to list all the procedures not accessed by the users within the last 6 months. Or, all the procedures that have not been used/accessed during the last 6 months.
    This is what I am trying but is not returning any rows:
    SELECT DISTINCT proc_name,
    TRUNC (entry_date)
    FROM log_web
    WHERE proc_name NOT IN (SELECT proc_name
    FROM log_web
    WHERE TRUNC (entry_date) > TRUNC (SYSDATE - 180))
    ORDER BY 2 DESC
    Please advise.
    Thank you in advance.

    Two possibilities leap to mind.
    First, are you sure that there are any prodcedures not accessed in the last six months?
    Second, is there a chance that there could be records with a null value in proc_name? If the sub-query used in a NOT IN predicate returns even one null value, the query will return no rows.
    Does this return rows?
    SELECT DISTINCT proc_name, TRUNC(entry_date)
    FROM log_web
    WHERE proc_name NOT IN (SELECT proc_name
                            FROM log_web
                            WHERE TRUNC (entry_date) > TRUNC (SYSDATE - 180) and
                                  proc_name IS NOT NULL)
    ORDER BY 2 DESCJohn

  • Repeating frame not visible when the query returns no rows

    I've developed a report whose output looks like this:
    Subinventory | Part Code |Part Description |Ordered Qty | Received Qty
    Mentone St | BATT | non serialised item | |
    Mentone St | SONY | spare parts MIN MAX | 30| 0
    In the above report
    subinventory, Part Code, Part description are in one repeating frame and Ordered and received qty are in other repeating frame.
    for a perticular part code there may not be ordered or received quantities. Means the seond query fetches no rows for the perticulat partcode. In that case report is showing null(blank) but I want to print ZERO there.
    If I use NVL in the query it'll effect only when the query fetches some rows.
    I've tried with formula columns. for example in the formula column
    IF :ordered_qty IS NULL THEN
    v_ordered_qty :=0;
    ELSE
    v_ordered_qty := :ordered_qty;
    END IF;
    return(v_ordered_qty);
    I've assigned this formula column as source to the Ordered Qty Filed. Then also its not working.
    Any help in this regards is highly apprecialted
    regards,
    Vij

    may be you can modify your code like below:
    SELECT i.subinventory, i.part_code, i.part_description, i.min_qty, i.max_qty,
           NVL (j.quantity, 0) ordered_qty,
           NVL (j.quantity_delivered, 0) received_qty
      FROM (SELECT DISTINCT c.secondary_inventory subinventory,
                            b.segment1 part_code, b.description part_description,
                            c.min_minmax_quantity min_qty,
                            c.max_minmax_quantity max_qty, b.inventory_item_id,
                            b.organization_id
                       FROM mtl_system_items_b b,
                            mtl_item_sub_inventories_all_v c
                      WHERE b.inventory_item_id = c.inventory_item_id
                        AND b.organization_id = c.organization_id
                        AND UPPER (c.secondary_inventory) =
                               NVL (UPPER (DECODE (:p_sub_inv,
                                                   'ALL', '',
                                                   :p_sub_inv
                                    UPPER (c.secondary_inventory)
                                   )) i,
           (SELECT   mtrl.inventory_item_id, mtrl.organization_id,
                     mtrl.to_subinventory_code,
                     NVL (SUM (mtrl.quantity), 0) quantity,
                     NVL (SUM (mtrl.quantity_delivered), 0) quantity_delivered
                FROM mtl_txn_request_lines mtrl, mtl_system_items_b msi
               WHERE mtrl.inventory_item_id = msi.inventory_item_id
                 AND mtrl.organization_id = msi.organization_id
                 AND mtrl.reference_type_code = 2
                 AND UPPER (mtrl.to_subinventory_code) =
                        NVL (UPPER (DECODE (:p_sub_inv, 'ALL', '', :p_sub_inv)),
                             UPPER (mtrl.to_subinventory_code)
                 AND TRUNC (mtrl.creation_date)
                        BETWEEN NVL (TRUNC (TO_DATE (:p_from_date,
                                                     'yyyy/mm/dd hh24:mi:ss'
                                     TRUNC (mtrl.creation_date)
                            AND NVL (TRUNC (TO_DATE (:p_to_date,
                                                     'yyyy/mm/dd hh24:mi:ss'
                                     TRUNC (mtrl.creation_date)
            GROUP BY mtrl.inventory_item_id,
                     mtrl.organization_id,
                     mtrl.to_subinventory_code) j
    WHERE i.inventory_item_id = j.inventory_item_id(+)
           AND i.organization_id = j.organization_id(+)

  • ...where like ('% query returning mul rows %') - how?

    Hi
    I have a situation where in my main query's where clause I have to use like ('% <value returned from query2>%'). However, my query2 can return multiple rows.
    It is something like this:
    Select .....
    from table1 t1
    where path like ('%<query2>%').
    Path can have multiple values - it is just representing a parent child relationship like 1/2/3. 1 is a parent of 2. 2 is a parnt of 3 and so on. What I get from query2 could be either of these. So I have to use like and not in. How may I achieve this?

    select lvl,
           Path
      from (select distinct level as lvl,
                   sys_connect_by_path(parent,'/') Path
              from table1 t1
            connect by prior child = parent)
    where instr(path,((select parent                                                                   --+
                          from (select parent, sm, rank() over (order by sm desc) r                       |
                                  from (SELECT parent, SUM(CT1) as sm                                     |
                                          FROM ((select parent,count(child) ct1                           |
                                                   from table1 t1                                         |
                                                  where group by parent                                   |
                                        -- end level 1)                                                   |
                                        UNION ALL                                                         |
                                        (select parent, count(child) ct2                                  | try to move this sub-query
                                           from table1 t1                                                 | at the FROM clause
                                          where child in --first level                                    |
                                                (select parent                                            |
                                                   from (select distinct parent,count(child) ct1          |
                                                           from table1 t1                                 |
                                                          where group by parent) q1)-- end level 1        |
                                                 group by parent))--MAIN SEL                              |
                         GROUP BY parent))                                                                |
                        where r =1))) > 0--end instr                                                    --+
       and lvl = 1
    you may try to move sub-queries in your WHERE clause to the FROM clause.
    Message was edited by:
    Warren Tolentino
    justin has the same idea :D

  • Query Returning Multiple Rows

    I have a problem with a query that includes 5 tables!
    Equipment ec, (ec.cost, ec.workid)
    Material mc, (mc.cost, mc.workid)
    Labor lc, (lc.cost, lc.workid)
    Work wo, (wo.workid)
    Entity en
    The primary key is the work id
    The columns I need to extract are all the same - "cost"
    The problem is that I need to extract the costs from all the tables (equipment/labor/material) where the work "id" is equal to the work "id".
    The work table has a unique wo.workid but the other three tables can have
    multiple nn.workid ('s).
    This is the query I am working from at this time...
    SELECT distinct wo.workid, wo.description, wo.supervisor, wo.acctnum,
    wo.shop, wo.woaddress, wo.initiatedate,
    TO_NUMBER (TO_CHAR (wo.initiatedate, 'MM')) AS mnth,
    TO_NUMBER (TO_CHAR (wo.initiatedate, 'YYYY')) AS yr,
    wo.actualfinishdate, wo.assetgroup, wo.unitsaccompdesc,
    wo.unitsaccomplished,
    sum(decode (lc.cost, 0, null, lc.cost)) labour_cost,
    lc.laborname AS labour_name,
    SUM (decode(mc.COST, 0, null, mc.cost)) AS material_cost,
    mc.description AS mat_desc,
    SUM (decode(ec.COST, 0, null, ec.cost)) AS equipment_cost,
    ec.description AS equip_desc, en.module
    FROM work wo,
    equipment ec,
    material mc,
    labor lc,
    entity en
    WHERE (lc.COST <> 0 AND mc.COST <> 0 AND ec.COST <> 0)
    AND wo.applytoentity = en.code
    AND mc.workid = wo.workid
    AND ec.workid = wo.workid
    AND lc.workid = wo.workid
    GROUP BY wo.workid,
    wo.description,
    wo.supervisor,
    wo.acctnum,
    wo.shop,
    wo.woaddress,
    wo.initiatedate,
    wo.actualfinishdate,
    wo.assetgroup,
    wo.unitsaccompdesc,
    wo.unitsaccomplished,
    lc.COST,
    lc.laborname,
    mc.COST,
    mc.description,
    ec.COST,
    ec.description,
    en.module
    any help would be appreciated!

    Hi John...
    I am still getting duplicate values.
    When the query grabs a value from the labour table it also grabs the values from the other tables and puts them in the same row... There are many rows in the three costs
    tables and only one in the work table.
    I have a dump of the rows but I cannot find a way to save it here.
    Here is a cut down version of the data I am retrieving.
    ID DESCRIPTION LAB MAT EQUIP
    345     General Building Interior Maintenance Activities          136.60     59.89     133.60
    345     General Building Interior Maintenance Activities          64.38     59.89     133.60
    345     General Building Interior Maintenance Activities          42.92     59.89     133.60
    345     General Building Interior Maintenance Activities          91.28     59.89     133.60
    345     General Building Interior Maintenance Activities          374.24     59.89     133.60
    345     General Building Interior Maintenance Activities          182.56     59.89     133.60
    345     General Building Interior Maintenance Activities          175.68     59.89     133.60
    345     General Building Interior Maintenance Activities          48.80     59.89     58.80
    345     General Building Interior Maintenance Activities          89.48     59.89     58.80
    345     General Building Interior Maintenance Activities          79.80     59.89     58.80
    345     General Building Interior Maintenance Activities          294.88     59.89     58.80
    345     General Building Interior Maintenance Activities          24.92     59.89     58.80
    345     General Building Interior Maintenance Activities          147.44     59.89     58.80
    345     General Building Interior Maintenance Activities          182.56     59.89     58.80
    345     General Building Interior Maintenance Activities          98.59     59.89     58.80
    345     General Building Interior Maintenance Activities          126.84     59.89     58.80
    345     General Building Interior Maintenance Activities          55.00     59.89     6,656.00
    345     General Building Interior Maintenance Activities          182.56     59.89     6,656.00
    345     General Building Interior Maintenance Activities          98.59     59.89     6,656.00
    345     General Building Interior Maintenance Activities          191.36     59.89     6,656.00
    345     General Building Interior Maintenance Activities          136.60     59.89     66.96
    345     General Building Interior Maintenance Activities          55.00     59.89     66.96
    345     General Building Interior Maintenance Activities          491.04     59.89     66.96
    345     General Building Interior Maintenance Activities          24.92     59.89     66.96
    345     General Building Interior Maintenance Activities          182.56     59.89     66.96
    345     General Building Interior Maintenance Activities          110.00     59.89     66.96
    345     General Building Interior Maintenance Activities          162.80     59.89     66.96
    345     General Building Interior Maintenance Activities          85.84     59.89     66.96
    345     General Building Interior Maintenance Activities          65.44     59.89     66.96
    345     General Building Interior Maintenance Activities          64.38     59.89     736.00
    345     General Building Interior Maintenance Activities          79.80     59.89     736.00

  • Need help in 'WITH CLAUSE' Query

    Hello Gurus,
    I am trying to calculate the count of distinct members for each provid.
    I am using the with clause to get information regarding the provid.
       WITH T AS
      (SELECT a.UD_ID MRR_ID,
                            A.UD_LASTNAME LAST_NAME,
                            A.UD_FIRSTNAME FIRST_NAME,
                            COUNT(DISTINCT DP.PA_PROVIDERID) PROVIDERS_ASSIGNED
                       FROM (SELECT UD.UD_ID,
                                    UD_LASTNAME,
                                    UD_FIRSTNAME
                               FROM USER_DETAILS       UD,
                                    MAP_USERS_TO_ROLES MR
                              WHERE MR.MUR_UR_ID_REF = 1000
                                AND MR.MUR_UD_ID_REF = UD.UD_ID) A,
                            D4C_PROVIDER_ASSIGNMENT DP
                      WHERE A.UD_ID = DP.PA_ASSIGNEDTO
                      AND dp.pa_status ='A'
                      GROUP BY A.UD_ID,
                               A.UD_LASTNAME,
                               A.UD_FIRSTNAME
                      ORDER BY 3 DESC)    OUTPUT of just above query without WITH clause.
    MRR_ID     LAST_NAME     FIRST_NAME     PROVIDERS_ASSIGNED
    1229    mrrTest         mrrTest         4
    1228    mrr2Last        mrr2First       5
    1230    mrr1Last        mrr1First       7
    1226    Panwar          SIngh           1
    1181    MRRLast         MRRTest         4
    1221    One             MRR             1
    1322    Thakuria        Bibhuthi        2I am creating this and get all the information to show on front end. Now I want to calculate the no of members as per the providers assigned for each MRR_ID
    Below query show the no of members for all the providers assigned to a provider.
    ex:
    SELECT * FROM (   
    SELECT COUNT(DISTINCT dmpc_hicn) countmember
    FROM D4C_HICN_PROVIDER_claims  a WHERE trim(DPMC_PROVIDER_NO) IN 
    (SELECT trim(pa_providerid)
       FROM d4c_provider_assignment
       WHERE pa_assignedto = 1181  (mrr_id)    --here i have use the mrrid from with clause and get the member count with all the columns coming from WITH CLAUSE.
       AND pa_roleid = 1000
       AND PA_STATUS ='A'
    GROUP BY a.dmpc_ss_id_ref)Right now I am using materialized view i dont wanna use the same..
    I am sending the materialized view code as well what i am doing ..
    ( SELECT SUM(member_count)member_count_bynpi ,mrr_id  FROM (
    (SELECT count(DISTINCT hp.dmpc_hicn) member_count,hp.DMPC_SS_ID_REF ,a1.ud_id mrr_id FROM  D4C_HICN_PROVIDER_claims hp ,
    (SELECT   a.UD_ID ,DP.PA_PROVIDERID
         FROM (SELECT UD.UD_ID, UD_LASTNAME, UD_FIRSTNAME
                 FROM USER_DETAILS UD, MAP_USERS_TO_ROLES MR
                WHERE MR.MUR_UR_ID_REF = 1000
                  AND MR.MUR_UD_ID_REF = UD.UD_ID) A,
              D4C_PROVIDER_ASSIGNMENT DP
        WHERE A.UD_ID = DP.PA_ASSIGNEDTO
        AND dp.pa_status ='A'
        /*AND dp.PA_ASSIGNEDTO = 1221*/) a1
        WHERE trim(a1.PA_PROVIDERID) = trim(hp.dpmc_provider_no)
        GROUP BY a1.ud_id,hp.DMPC_SS_ID_REF))
        GROUP BY mrr_id)Please help me to write the code with the materialized view. Thanks in Advance.
    Kind regards,
    UP
    Edited by: BluShadow on 22-Aug-2011 07:58
    fixed {noformat}{noformat} tags.  Please use lowercase "code" rather than uppercase "CODE" in the tags.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Probably, this may help
    WITH T1 as(
               SELECT UD.UD_ID,
                      UD_LASTNAME,
                      UD_FIRSTNAME
                FROM USER_DETAILS UD, MAP_USERS_TO_ROLES MR
                WHERE MR.MUR_UR_ID_REF = 1000
                AND MR.MUR_UD_ID_REF = UD.UD_ID)
          T2 as (SELECT a.UD_ID ,DP.PA_PROVIDERID
                 FROM T1 A, D4C_PROVIDER_ASSIGNMENT DP
                 WHERE A.UD_ID = DP.PA_ASSIGNEDTO
                 AND dp.pa_status ='A')
           T3 as(SELECT count(DISTINCT hp.dmpc_hicn) member_count,
                              hp.DMPC_SS_ID_REF ,
                               a1.ud_id mrr_id
                  FROM T2 A1 ,D4C_HICN_PROVIDER_claims hp
                  WHERE trim(a1.PA_PROVIDERID) = trim(hp.dpmc_provider_no)
                  GROUP BY a1.ud_id,hp.DMPC_SS_ID_REF)
    SELECT SUM(member_count)member_count_bynpi ,mrr_id from T3
    GROUP BY mrr_id

  • Problem with database control returning multiple rows as Array  using Oracle

    Has anybody using Oracle gotten a Database control that
    returns multiple rows to work returning an array?
    The only way I can seem to return multiple rows is by returning
    a RowSet. Returning an array gives me a NullPointerException
    (when called within a pageFlow). When calling a database control
    that returns an array from a web service I get a
    "java.sql.SQLException: ResultSet has no more data." error.
    The samples using the pointbase database seem to work, but when I
    converted the CustomerDBClient web service to use Oracle, it starts
    failing on calling the database control that returns an array
    with: "java.sql.SQLException: ResultSet has no more data."
    Has anybody gotten this to work using Oracle?
    I'm also having some problem returning an Iterator. It seems
    to work when called from a web service, but returns nothing
    if called from a page flow.
    I'm using Oracle 8.1.7 and WebLogic 8.1.
    Eric

    Do you need a particular service pack installed to return an array of custom object?
    I am getting a ResultSet contained no data error when trying.
    Thanks,
    -Thomas
    "Robin Karlin" <[email protected]> wrote:
    >
    Eddie O'Neil <[email protected]> wrote:
    All--
    Unfortunately, returning an Iterator to a JPF (or JSP) from a
    database control is broken in WLW 8.1, though it will work inside of
    a
    JWS or JCS.
    There shouldn't be a problem with returning an array of objects out
    of Oracle to the JPF, and if you need an Iterator specifically, youcan
    wrap the array in an Iterator implementation.
    Sorry for the inconvenience.
    Eddie
    Lenny wrote:
    I have gotten it to work on Oracle using Array:)
    However, I haven't gotten it to work on Oracle using Iterator:( Itis so
    simple, but doesn't work:(
    "Eric Dokken" <[email protected]> wrote in message
    news:[email protected]...
    Has anybody using Oracle gotten a Database control that
    returns multiple rows to work returning an array?
    The only way I can seem to return multiple rows is by returning
    a RowSet. Returning an array gives me a NullPointerException
    (when called within a pageFlow). When calling a database control
    that returns an array from a web service I get a
    "java.sql.SQLException: ResultSet has no more data." error.
    The samples using the pointbase database seem to work, but when I
    converted the CustomerDBClient web service to use Oracle, it starts
    failing on calling the database control that returns an array
    with: "java.sql.SQLException: ResultSet has no more data."
    Has anybody gotten this to work using Oracle?
    I'm also having some problem returning an Iterator. It seems
    to work when called from a web service, but returns nothing
    if called from a page flow.
    I'm using Oracle 8.1.7 and WebLogic 8.1.
    Eric
    I get the same error that Eric reported when trying to return an Array
    of objects.
    It is really frustrating because I can't use much of the built-in control
    logic
    that WLW provides. All I did was create a data pool for Oracle and a
    datasource.
    I modified the sample app in C:\bea81\weblogic81\samples\workshop\SamplesApp\WebApp\callJavaControl
    to point to that datasource and I get the error that Eric reports above.
    Can
    anyone help me out????
    Thanks,
    Robin

  • WITH clause querying other WITH clause

    I want to do something like this:
    with t1 as
        select * from table1
    ,t2 as
        select col1,col2 from t1
    select * from t1,t2as you all can see, t2 WITH clause queries t1 WITH clause. how do I do this? because this doesn't work. thanks

    how do I do this?Works fine for me on my 11.2.0.2:
    SQL> with t1 as (select dname from dept),
         t2 as (select dname from t1)
    select t1.dname d1, t2.dname d2
      from t1, t2
    D1                    D2                  
    ACCOUNTING            ACCOUNTING          
    ACCOUNTING            RESEARCH            
    ACCOUNTING            SALES               
    ACCOUNTING            OPERATIONS          
    ACCOUNTING            SALES               
    RESEARCH              ACCOUNTING          
    RESEARCH              RESEARCH            
    RESEARCH              SALES               
    RESEARCH              OPERATIONS          
    RESEARCH              SALES               
    SALES                 ACCOUNTING          
    SALES                 RESEARCH            
    SALES                 SALES               
    SALES                 OPERATIONS          
    SALES                 SALES               
    OPERATIONS            ACCOUNTING          
    OPERATIONS            RESEARCH            
    OPERATIONS            SALES               
    OPERATIONS            OPERATIONS          
    OPERATIONS            SALES               
    SALES                 ACCOUNTING          
    SALES                 RESEARCH            
    SALES                 SALES               
    SALES                 OPERATIONS          
    SALES                 SALES               
    25 rows selected.

  • How to use hint on with clause query

    Hi all,
    I have a query and it consits full of tabs with WITH clause. Top level I am just selecting all the tabs (queries with WITH clause) by saying select * from tab1,tab2,.....so on .
    Now my question is If I want to use hint on my SQL can I use the same by using tab1,tab2...
    tab1, tab2 are not actually tables ....each tab represents one SQL with WITH clause.
    Please let me know if there is any confusion on my post.

    What's stopping you from trying it yourself?
    Post your results here to help others.

Maybe you are looking for

  • Since I updated my itune software can no longer burn cd's

    Since I updated the software I can no longer burn cd's. It says a message on the top window 'Disc burner or software not found'. Can anyone offer assistance?

  • Display slow to come on when waking from sleep.

    There have been quite a few entries of similar problems lately with no real answers that I found. I have a FW800 dp 1.42 machine running 10.4.11. When coming up from sleep the machine comes up but the display may say black for up to 5 min. This is wi

  • When phone not muted, why isn't there any audio when using facetime?

    When phone not muted, why isn't there any audio when using facetime?

  • Iphone 3GS Emergency

    Im about to have a nervous break down Ok Story - Got new iphone 3gs about a month ago, absolutely in love with it (first apple product) constantly downloading music, apps, ect as u do when u get a new iphone LOL Last Saturday as i was synching stuff,

  • Forms: avoiding "record changed by another user"

    I have a form with a DB block. There is also a DB trigger on the same table, so when an update is performed in the form, the BEFORE UPDATE trigger updates the same row. Of course, when I try to change the same record again, I get "record changed by a