IN SUB QUERY WHICH LINE IS HAVING  ERROR

HI,
OTN MEMBERS.
I HAVE ONE QUESTION THAT WHEN WRITING THE FOLLOWING QUERY.
1) SELECT ENAME,SAL
2) FROM EMP
3) WHERE EMPNO = (
4) SELECT EMPNO
5) FROM EMP
6) WHERE SAL >100 OR SAL <5000)
AS THIS QUERY WILL NOT RUN B'COZ SUBQUERY GENERATES MORE
THEN ONE RESULT AND THE MAIN QUERY IS HAVING (=) SINGLE
ROW OPERATOR , BUT LINE WIZE WHICH LINE SHOULD I CHOOSE AS
WRONG , B'COZ THERE IS TWO OPTIONS :-
3) WHERE EMPNO =
AND LINE
6) WHERE SAL>100 OR SAL<5000
THANKS

It depends on what you need.
6) WHERE SAL >100 OR SAL <5000) : this line generates more than one row, so if you need only one row you have to change it.
If you can accept more than one row, then line 3 should be :
3) WHERE EMPNO in (
BTW, WHERE SAL >100 OR SAL <5000 always extracts all rows. Shouldn't be WHERE SAL >100 and SAL <5000 ?

Similar Messages

  • How can I know which line contains the error in JSP

    Hello, I got following compiling error:
    ava.lang.NullPointerException
         at org.apache.jsp.temp1Public_jsp._jspService(temp1Public_jsp.java:252)"
    Is there a way I can know in which line of the jsp page the null pointer exception occurs.
    "line 252 " doesn't seem to help a lot, since it refers to the rendered java file.
    Thanks so much.
    Oriental Spirit.

    Hello, I got following compiling error:
    ava.lang.NullPointerException
    at
    org.apache.jsp.temp1Public_jsp._jspService(temp1Public
    jsp.java:252)"
    Is there a way I can know in which line of the jsp
    page the null pointer exception occurs.
    "line 252 " doesn't seem to help a lot, since it
    refers to the rendered java file.As far as I know, no. If you are using an IDE that supports JSP compilation, then it may let you click on the error and take you directly to the JSP (e.g. Forte/Netbeans or Jbuilder will do this).

  • Do I need a sub-query and getting ORA-00937 error

    I'm writing a query where I want returned all data that is in a list 510 and all duplicate entries for the AID are eliminated.
    select *
    from entities e
    where e.list_id in
    (select aid
    from entities e
    where e.list_id = 510
    having count(e.aid) > 1);
    When I run this, I get ORA-00937: not a single-group group function.
    I google the error and see
    http://ora-00937.ora-code.com/
    Which tells me I can't have a group function and individual column expression.
    So I removed the group by, but I still get the errors, and for some reason when I put the alias e for the aid in the subquery, I still get the same error.
    Hopefully this makes sense what I'm asking...
    thanks

    if you want to select rows that eliminate duplicates then you should be using distinct. And if you want to get the duplicate rows then,
    select *
    from entities e1
    where e1.rowid <
    (select max(e2.rowid)
    from entities e2
    where e2.list_id = 510
    and e1.aid = e2.aid);

  • Can i use Sub Query Factoring Here ?

    Hi;
    SQL>SELECT * FROM V$VERSION;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE    11.1.0.7.0      Production
    TNS for Linux: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - ProductionSQL
    select /*+ PARALLEL(det, 4) */ '12062' snapshot_id,det.journal_entry_line_id, det.accounting_date,det.company_code,det.account_number,
    det.transaction_id, det.transaction_id_type, det.amount,det.currency_code,det.debit_or_credit,det.category,det.subcategory,det.reference1,det.reference1_type,
    det.reference2,det.reference2_type,det.gl_batch_id,det.marketplace_id,det.cost_center,det.gl_product_line,det.location,det.project,det.sales_channel,
    det.created_by,det.creation_date,det.last_updated_by,det.last_updated_date,agg.age,last_day(to_date('04/21/2010','MM/DD/YYYY')) snapshot_day
    from
    select company_code, account_number, transaction_id,
    decode(transaction_id_type, 'CollectionID', 'SettlementGroupID', transaction_id_type) transaction_id_type,
    (last_day(to_date('04/21/2010','MM/DD/YYYY')) - min(z.accounting_date) ) age,sum(z.amount)
    from
         select /*+ PARALLEL(use, 2) */    company_code,substr(account_number, 1, 5) account_number,transaction_id,
         decode(transaction_id_type, 'CollectionID', 'SettlementGroupID', transaction_id_type) transaction_id_type,use.amount,use.accounting_date
         from financials.unbalanced_subledger_entries use
         where use.accounting_date >= to_date('04/21/2010','MM/DD/YYYY')
         and use.accounting_date < to_date('04/21/2010','MM/DD/YYYY') + 1
    UNION ALL
         select /*+ PARALLEL(se, 2) */  company_code, substr(se.account_number, 1, 5) account_number,transaction_id,
         decode(transaction_id_type, 'CollectionID', 'SettlementGroupID', transaction_id_type) transaction_id_type,se.amount,se.accounting_date
         from financials.temp2_sl_snapshot_entries se,financials.account_numbers an
         where se.account_number = an.account_number
         and an.subledger_type in ('C', 'AC')
    ) z
    group by company_code,account_number,transaction_id,decode(transaction_id_type, 'CollectionID', 'SettlementGroupID', transaction_id_type)
    having abs(sum(z.amount)) >= 0.01
    ) agg,
         select /*+ PARALLEL(det, 2) */ det.journal_entry_line_id,  det.accounting_date, det.company_code, det.account_number, det.transaction_id,  decode(det.transaction_id_type, 'CollectionID', 'SettlementGroupID', det.transaction_id_type) transaction_id_type,
         det.amount, det.currency_code, det.debit_or_credit, det.category, det.subcategory, det.reference1, det.reference1_type, det.reference2, det.reference2_type,
         det.gl_batch_id, det.marketplace_id, det.cost_center, det.gl_product_line, det.location, det.project, det.sales_channel, det.created_by, det.creation_date,
         det.last_updated_by, det.last_updated_date
         from financials.unbalanced_subledger_entries det
         where accounting_date >= to_date('04/21/2010','MM/DD/YYYY')
         and accounting_date < to_date('04/21/2010','MM/DD/YYYY') + 1
    UNION ALL
    select /*+ PARALLEL(det, 2) */  det.journal_entry_line_id, det.accounting_date, det.company_code, det.account_number, det.transaction_id,
    decode(det.transaction_id_type, 'CollectionID', 'SettlementGroupID', det.transaction_id_type) transaction_id_type,  det.amount, det.currency_code,
    det.debit_or_credit, det.category, det.subcategory, det.reference1, det.reference1_type, det.reference2, det.reference2_type, det.gl_batch_id, det.marketplace_id,
    det.cost_center, det.gl_product_line, det.location, det.project, det.sales_channel, det.created_by, det.creation_date, det.last_updated_by, det.last_updated_date
    from financials.temp2_sl_snapshot_entries det,financials.account_numbers an
    where det.account_number = an.account_number
    and an.subledger_type in ('C', 'AC')
    ) det
                       where agg.company_code = det.company_code
                       and agg.account_number = substr(det.account_number, 1, 5)
                       and agg.transaction_id = det.transaction_id
                       and agg.transaction_id_type = det.transaction_id_type
    /Execution Plan
    | Id  | Operation                          | Name                         | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |
    |   0 | SELECT STATEMENT                   |                              |    12M|  8012M|       |   541K  (1)| 01:48:21 |        |      |            |
    |   1 |  PX COORDINATOR                    |                              |       |       |       |            |          |        |      |            |
    |   2 |   PX SEND QC (RANDOM)              | :TQ10005                     |    12M|  8012M|       |   541K  (1)| 01:48:21 |  Q1,05 | P->S | QC (RAND)  |
    |*  3 |    HASH JOIN BUFFERED              |                              |    12M|  8012M|  1098M|   541K  (1)| 01:48:21 |  Q1,05 | PCWP |            |
    |   4 |     PX RECEIVE                     |                              |    35M|  3992M|       |   166K  (2)| 00:33:16 |  Q1,05 | PCWP |            |
    |   5 |      PX SEND HASH                  | :TQ10003                     |    35M|  3992M|       |   166K  (2)| 00:33:16 |  Q1,03 | P->P | HASH       |
    |   6 |       VIEW                         |                              |    35M|  3992M|       |   166K  (2)| 00:33:16 |  Q1,03 | PCWP |            |
    |*  7 |        FILTER                      |                              |       |       |       |            |          |  Q1,03 | PCWC |            |
    |   8 |         HASH GROUP BY              |                              |    35M|  4528M|       |   166K  (2)| 00:33:16 |  Q1,03 | PCWP |            |
    |   9 |          PX RECEIVE                |                              |    35M|  4528M|       |   166K  (2)| 00:33:16 |  Q1,03 | PCWP |            |
    |  10 |           PX SEND HASH             | :TQ10001                     |    35M|  4528M|       |   166K  (2)| 00:33:16 |  Q1,01 | P->P | HASH       |
    |  11 |            HASH GROUP BY           |                              |    35M|  4528M|       |   166K  (2)| 00:33:16 |  Q1,01 | PCWP |            |
    |  12 |             VIEW                   |                              |    35M|  4528M|       |   164K  (1)| 00:33:00 |  Q1,01 | PCWP |            |
    |  13 |              UNION-ALL             |                              |       |       |       |            |          |  Q1,01 | PCWP |            |
    |  14 |               PX BLOCK ITERATOR    |                              |    11 |   539 |       |  1845   (1)| 00:00:23 |  Q1,01 | PCWC |            |
    |* 15 |                TABLE ACCESS FULL   | UNBALANCED_SUBLEDGER_ENTRIES |    11 |   539 |       |  1845   (1)| 00:00:23 |  Q1,01 | PCWP |            |
    |* 16 |               HASH JOIN            |                              |    35M|  2012M|       |   163K  (1)| 00:32:37 |  Q1,01 | PCWP |            |
    |  17 |                BUFFER SORT         |                              |       |       |       |            |          |  Q1,01 | PCWC |            |
    |  18 |                 PX RECEIVE         |                              |    21 |   210 |       |     2   (0)| 00:00:01 |  Q1,01 | PCWP |            |
    |  19 |                  PX SEND BROADCAST | :TQ10000                     |    21 |   210 |       |     2   (0)| 00:00:01 |        | S->P | BROADCAST  |
    |* 20 |                   TABLE ACCESS FULL| ACCOUNT_NUMBERS              |    21 |   210 |       |     2   (0)| 00:00:01 |        |      |            |
    |  21 |                PX BLOCK ITERATOR   |                              |    56M|  2701M|       |   162K  (1)| 00:32:35 |  Q1,01 | PCWC |            |
    |  22 |                 TABLE ACCESS FULL  | TEMP2_SL_SNAPSHOT_ENTRIES    |    56M|  2701M|       |   162K  (1)| 00:32:35 |  Q1,01 | PCWP |            |
    |  23 |     PX RECEIVE                     |                              |    35M|    18G|       | 82859   (1)| 00:16:35 |  Q1,05 | PCWP |            |
    |  24 |      PX SEND HASH                  | :TQ10004                     |    35M|    18G|       | 82859   (1)| 00:16:35 |  Q1,04 | P->P | HASH       |
    |  25 |       BUFFER SORT                  |                              |    12M|  8012M|       |            |          |  Q1,04 | PCWP |            |
    |  26 |        VIEW                        |                              |    35M|    18G|       | 82859   (1)| 00:16:35 |  Q1,04 | PCWP |            |
    |  27 |         UNION-ALL                  |                              |       |       |       |            |          |  Q1,04 | PCWP |            |
    |  28 |          PX BLOCK ITERATOR         |                              |    11 |  2255 |       |   923   (1)| 00:00:12 |  Q1,04 | PCWC |            |
    |* 29 |           TABLE ACCESS FULL        | UNBALANCED_SUBLEDGER_ENTRIES |    11 |  2255 |       |   923   (1)| 00:00:12 |  Q1,04 | PCWP |            |
    |* 30 |          HASH JOIN                 |                              |    35M|  7514M|       | 81936   (1)| 00:16:24 |  Q1,04 | PCWP |            |
    |  31 |           PX RECEIVE               |                              |    21 |   210 |       |     2   (0)| 00:00:01 |  Q1,04 | PCWP |            |
    |  32 |            PX SEND BROADCAST       | :TQ10002                     |    21 |   210 |       |     2   (0)| 00:00:01 |  Q1,02 | P->P | BROADCAST  |
    |  33 |             PX BLOCK ITERATOR      |                              |    21 |   210 |       |     2   (0)| 00:00:01 |  Q1,02 | PCWC |            |
    |* 34 |              TABLE ACCESS FULL     | ACCOUNT_NUMBERS              |    21 |   210 |       |     2   (0)| 00:00:01 |  Q1,02 | PCWP |            |
    |  35 |           PX BLOCK ITERATOR        |                              |    56M|    11G|       | 81840   (1)| 00:16:23 |  Q1,04 | PCWC |            |
    |  36 |            TABLE ACCESS FULL       | TEMP2_SL_SNAPSHOT_ENTRIES    |    56M|    11G|       | 81840   (1)| 00:16:23 |  Q1,04 | PCWP |            |
    Predicate Information (identified by operation id):
       3 - access("AGG"."COMPANY_CODE"="DET"."COMPANY_CODE" AND "AGG"."ACCOUNT_NUMBER"=SUBSTR("DET"."ACCOUNT_NUMBER",1,5) AND
                  "AGG"."TRANSACTION_ID"="DET"."TRANSACTION_ID" AND "AGG"."TRANSACTION_ID_TYPE"="DET"."TRANSACTION_ID_TYPE")
       7 - filter(ABS(SUM(SYS_OP_CSR(SYS_OP_MSR(SUM("Z"."AMOUNT"),MIN("Z"."ACCOUNTING_DATE")),0)))>=0.01)
      15 - filter("USE"."ACCOUNTING_DATE"<TO_DATE(' 2010-04-22 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "USE"."ACCOUNTING_DATE">=TO_DATE('
                  2010-04-21 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
      16 - access("SE"."ACCOUNT_NUMBER"="AN"."ACCOUNT_NUMBER")
      20 - filter("AN"."SUBLEDGER_TYPE"='AC' OR "AN"."SUBLEDGER_TYPE"='C')
      29 - filter("ACCOUNTING_DATE"<TO_DATE(' 2010-04-22 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "ACCOUNTING_DATE">=TO_DATE(' 2010-04-21
                  00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
      30 - access("DET"."ACCOUNT_NUMBER"="AN"."ACCOUNT_NUMBER")
      34 - filter("AN"."SUBLEDGER_TYPE"='AC' OR "AN"."SUBLEDGER_TYPE"='C')
                    This query is failing due to TEMP issue (TEMP SPACE out of space)
    My TEMP tablespace is 70GB and no one is using TEMP space while this query is in execution.
    PGA=16 GB.
    What i can see from execution plan is : Two large resultsets AGG (13Million) and DET (135 Million) is being joined HASH JOIN BUFFERED. Which is getting spilled to TEMP space causing TEMP outage.
    Is there any way, i can re-write this query (probably using SUB QUERY FACTORING...WITH CLAUSE) so that reduce two times access to TEMP2_SL_SNAPSHOT_ENTRIES table. TEMP2_SL_SNAPSHOT_ENTRIES is 12 GB non partition table and i cannot use any other filter to restrict rows from this table.

    Adding more information here :
    Inner sub query (Which forms DET-bottom)
    select /*+ PARALLEL(det, 2) */  det.journal_entry_line_id, det.accounting_date, det.company_code, det.account_number, det.transaction_id,
    decode(det.transaction_id_type, 'CollectionID', 'SettlementGroupID', det.transaction_id_type) transaction_id_type,  det.amount, det.currency_code,
    det.debit_or_credit, det.category, det.subcategory, det.reference1, det.reference1_type, det.reference2, det.reference2_type, det.gl_batch_id, det.marketplace_id,
    det.cost_center, det.gl_product_line, det.location, det.project, det.sales_channel, det.created_by, det.creation_date, det.last_updated_by, det.last_updated_date
    from financials.temp2_sl_snapshot_entries det,financials.account_numbers an
    where det.account_number = an.account_number
    and an.subledger_type in ('C', 'AC');
    Plan hash value: 976020246
    | Id  | Operation               | Name                      | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |
    |   0 | SELECT STATEMENT        |                           |    35M|  7514M|   163K  (1)| 00:32:47 |        |      |            |
    |   1 |  PX COORDINATOR         |                           |       |       |            |          |        |      |            |
    |   2 |   PX SEND QC (RANDOM)   | :TQ10001                  |    35M|  7514M|   163K  (1)| 00:32:47 |  Q1,01 | P->S | QC (RAND)  |
    |*  3 |    HASH JOIN            |                           |    35M|  7514M|   163K  (1)| 00:32:47 |  Q1,01 | PCWP |            |
    |   4 |     BUFFER SORT         |                           |       |       |            |          |  Q1,01 | PCWC |            |
    |   5 |      PX RECEIVE         |                           |    21 |   210 |     2   (0)| 00:00:01 |  Q1,01 | PCWP |            |
    |   6 |       PX SEND BROADCAST | :TQ10000                  |    21 |   210 |     2   (0)| 00:00:01 |        | S->P | BROADCAST  |
    |*  7 |        TABLE ACCESS FULL| ACCOUNT_NUMBERS           |    21 |   210 |     2   (0)| 00:00:01 |        |      |            |
    |   8 |     PX BLOCK ITERATOR   |                           |    56M|    11G|   163K  (1)| 00:32:45 |  Q1,01 | PCWC |            |
    |   9 |      TABLE ACCESS FULL  | TEMP2_SL_SNAPSHOT_ENTRIES |    56M|    11G|   163K  (1)| 00:32:45 |  Q1,01 | PCWP |            |
    Predicate Information (identified by operation id):
       3 - access("DET"."ACCOUNT_NUMBER"="AN"."ACCOUNT_NUMBER")
       7 - filter("AN"."SUBLEDGER_TYPE"='AC' OR "AN"."SUBLEDGER_TYPE"='C')
    Statistics
             31  recursive calls
              3  db block gets
        1634444  consistent gets
        1625596  physical reads
            636  redo size
    1803659818  bytes sent via SQL*Net to client
         125054  bytes received via SQL*Net from client
          11331  SQL*Net roundtrips to/from client
              3  sorts (memory)
              0  sorts (disk)
       56645822  rows processedOther sub query (that forms AGG)
         select /*+ PARALLEL(se, 2) */  company_code, substr(se.account_number, 1, 5) account_number,transaction_id,
         decode(transaction_id_type, 'CollectionID', 'SettlementGroupID', transaction_id_type) transaction_id_type,se.amount,se.accounting_date
         from financials.temp2_sl_snapshot_entries se,financials.account_numbers an
         where se.account_number = an.account_number
         and an.subledger_type in ('C', 'AC');
    Plan hash value: 976020246
    | Id  | Operation               | Name                      | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |
    |   0 | SELECT STATEMENT        |                           |    35M|  2012M|   163K  (1)| 00:32:37 |        |      |            |
    |   1 |  PX COORDINATOR         |                           |       |       |            |          |        |      |            |
    |   2 |   PX SEND QC (RANDOM)   | :TQ10001                  |    35M|  2012M|   163K  (1)| 00:32:37 |  Q1,01 | P->S | QC (RAND)  |
    |*  3 |    HASH JOIN            |                           |    35M|  2012M|   163K  (1)| 00:32:37 |  Q1,01 | PCWP |            |
    |   4 |     BUFFER SORT         |                           |       |       |            |          |  Q1,01 | PCWC |            |
    |   5 |      PX RECEIVE         |                           |    21 |   210 |     2   (0)| 00:00:01 |  Q1,01 | PCWP |            |
    |   6 |       PX SEND BROADCAST | :TQ10000                  |    21 |   210 |     2   (0)| 00:00:01 |        | S->P | BROADCAST  |
    |*  7 |        TABLE ACCESS FULL| ACCOUNT_NUMBERS           |    21 |   210 |     2   (0)| 00:00:01 |        |      |            |
    |   8 |     PX BLOCK ITERATOR   |                           |    56M|  2701M|   162K  (1)| 00:32:35 |  Q1,01 | PCWC |            |
    |   9 |      TABLE ACCESS FULL  | TEMP2_SL_SNAPSHOT_ENTRIES |    56M|  2701M|   162K  (1)| 00:32:35 |  Q1,01 | PCWP |            |
    Predicate Information (identified by operation id):
       3 - access("SE"."ACCOUNT_NUMBER"="AN"."ACCOUNT_NUMBER")
       7 - filter("AN"."SUBLEDGER_TYPE"='AC' OR "AN"."SUBLEDGER_TYPE"='C')
    Statistics
             31  recursive calls
              3  db block gets
        1634444  consistent gets
        1625596  physical reads
            592  redo size
    1803659818  bytes sent via SQL*Net to client
         125054  bytes received via SQL*Net from client
          11331  SQL*Net roundtrips to/from client
              3  sorts (memory)
              0  sorts (disk)
       56645822  rows processed

  • Correlated sub-query/outer join problem

    Hi,
    I have a problem similar to this one (Outer join with correlated subquery but I'm struggling to find a solution for mine!
    The following query works OK unless there is no entry in room_prices, so I need to outer join somehow to that table otherwise it doesn't return any rows.
    The main difference between the query in the other thread and mine is that mine has an extra table (bookings b) in the sub-query, which is complicating things a bit.
    select b.book_from,
         b.book_to,
         b.flat_rate,
         nvl(c.discount,0),
         p.hourly,
         p.half_day,
         p.daily,
         p.discountable,
         p.surcharge,
         l.evening_start,
         nvl(b.full_day,'N')
    from booking.bookings b,
    booking.customer c,
    booking.room_prices p,
    booking.rooms r,
    booking.location l
    where b.id = 9272
    and c.id = b.customer
    and b.room = p.room
    and b.room = r.id
    and r.loc = l.id
    and p.from_date =
    select max(p2.from_date)
    from booking.room_prices p2
    where p2.room = p.room
    and p2.from_date < b.book_from
    Could anyone suggest a way to re-write the query so that it is outer joined to room_prices?
    Thanks,
    Hazel

    Thanks for both of your responses.
    Unfortunately your suggestion didn't work Dmytro - still no rows are returned.
    Here are some table creation scripts and test data to insert:
    CREATE TABLE BOOKINGS
    ID NUMBER NOT NULL,
    ROOM NUMBER NOT NULL,
    CUSTOMER NUMBER NOT NULL,
    BOOK_FROM DATE NOT NULL,
    BOOK_TO DATE NOT NULL,
    CONFIG VARCHAR2(24) NOT NULL,
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    DELEGATES NUMBER,
    NARRATIVE VARCHAR2(256),
    CONTACT_DETAILS VARCHAR2(400),
    CONFIRMED VARCHAR2(1),
    CANC_REASON NUMBER,
    FULL_DAY VARCHAR2(1),
    FLAT_RATE NUMBER,
    STANDBY NUMBER,
    TOTAL_STANDBY_TIME DATE,
    PRE_STANDBY_TIME DATE,
    PRE_STANDBY NUMBER,
    GL_CODE VARCHAR2(20)
    CREATE TABLE CUSTOMER
    ID NUMBER NOT NULL,
    CUSTOMER VARCHAR2(160) NOT NULL,
    CONTACT_ADDRESS VARCHAR2(240),
    CONTACT_TELEPHONE VARCHAR2(20),
    CONTACT_EMAIL VARCHAR2(160),
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    DISCOUNT NUMBER(5,2),
    CUST_TYPE VARCHAR2(1),
    CONTACT_FAX VARCHAR2(20),
    DEBTOR_NO VARCHAR2(20),
    BC_CONTACT VARCHAR2(64)
    CREATE TABLE ROOMS
    ID NUMBER NOT NULL,
    LOC NUMBER NOT NULL,
    NAME VARCHAR2(160) NOT NULL,
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    ACTIVE VARCHAR2(1),
    ROOM_DESC VARCHAR2(2000)
    CREATE TABLE LOCATION
    ID NUMBER NOT NULL,
    NAME VARCHAR2(240) NOT NULL,
    ADDRESS VARCHAR2(240),
    PCODE VARCHAR2(8),
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    CONF_RDF VARCHAR2(10),
    CLOSING VARCHAR2(5),
    EVENING_START VARCHAR2(5)
    CREATE TABLE ROOM_PRICES
    ROOM NUMBER NOT NULL,
    FROM_DATE DATE NOT NULL,
    HOURLY NUMBER(6,2),
    HALF_DAY NUMBER(6,2),
    DAILY NUMBER(6,2),
    DISCOUNTABLE VARCHAR2(1),
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    SURCHARGE NUMBER(6,2)
    Insert into bookings
    (ID, ROOM, CUSTOMER, BOOK_FROM, BOOK_TO, CONFIG, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, DELEGATES, NARRATIVE, CONTACT_DETAILS, CONFIRMED, FLAT_RATE, PRE_STANDBY_TIME, PRE_STANDBY)
    Values
    (9272, 7466, 4946, TO_DATE('10/25/2005 10:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/25/2005 13:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Default', TO_DATE('10/27/2005 15:35:02', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', TO_DATE('10/27/2005 15:36:26', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', 1, 'another meeting', 'Hazel', 'Y', 40, TO_DATE('10/25/2005 09:30:00', 'MM/DD/YYYY HH24:MI:SS'), 1800);
    Insert into customer
    (ID, CUSTOMER, CONTACT_ADDRESS, CONTACT_TELEPHONE, CREATED_DATE, CREATED_BY, CUST_TYPE, BC_CONTACT)
    Values
    (4946, 'Association of Teachers', 'Address', '0191 8887777', TO_DATE('09/22/2003 08:05:47', 'MM/DD/YYYY HH24:MI:SS'), 'Dataload', 'B', 'Miss Jones');
    Insert into rooms
    (ID, LOC, NAME, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, ACTIVE)
    Values
    (7466, 308, ' Counselling Room 1', TO_DATE('04/11/2005 10:55:33', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', TO_DATE('06/22/2005 14:43:50', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', 'Y');
    Insert into location
    (ID, NAME, ADDRESS, PCODE, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, CONF_RDF, CLOSING, EVENING_START)
    Values
    (308, 'Business Centre', 'Address', 'NE30 1NT', TO_DATE('03/19/2003 13:07:35', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', TO_DATE('06/09/2005 11:17:09', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', 'BKCF_2', '22:30', '18:00');
    Thanks,
    Hazel

  • Sub-query question, looking up value within a query

    I have a situation to lookup prior period value within the same query. I tried to use a sub-query but getting a syntax error:
    SELECT [VALUE-BAND_ACCT].GLSeq, [VALUE-BAND_ACCT].NUM_SITES, [VALUE-BAND_ACCT].SGMNT1, 
    [VALUE-BAND_ACCT].SGMNT2, [VALUE-BAND_ACCT].LOB$, [VALUE-BAND_ACCT].PERIOD, [VALUE-BAND_ACCT].RECUR, [VALUE-BAND_ACCT].PROMOTED, [VALUE-BAND_ACCT].COMB_REV_GRS, [VALUE-BAND_ACCT].COMB_REV_NET, [VALUE-BAND_ACCT].ARPSg_ACCT, [VALUE-BAND_ACCT].ARPSn_ACCT,
    [VALUE-BAND_ACCT].COMB_VALUE_BAND,
    (SELECT [VALUE-BAND_ACCT].COMB_VALUE_BAND
     FROM VALUE-BAND_ACCT
     WHERE [VALUE-BAND_ACCT].PERIOD = DateSerial(Year([VALUE-BAND_ACCT].PERIOD), Month([VALUE-BAND_ACCT].PERIOD)-1, 1)) AS PRIOR_VALUE_BAND
    FROM VALUE-BAND_ACCT;
    Appreciating help.

    Try this:
    SELECT [VALUE-BAND_ACCT].GLSeq, [VALUE-BAND_ACCT].NUM_SITES, [VALUE-BAND_ACCT].SGMNT1,
    [VALUE-BAND_ACCT].SGMNT2, [VALUE-BAND_ACCT].LOB$, [VALUE-BAND_ACCT].PERIOD,
    [VALUE-BAND_ACCT].RECUR, [VALUE-BAND_ACCT].PROMOTED, [VALUE-BAND_ACCT].COMB_REV_GRS,
    [VALUE-BAND_ACCT].COMB_REV_NET, [VALUE-BAND_ACCT].ARPSg_ACCT,
    [VALUE-BAND_ACCT].ARPSn_ACCT, [VALUE-BAND_ACCT].COMB_VALUE_BAND,
    [VALUE-BAND_ACCT_1].COMB_VALUE_BAND AS PRIOR_VALUE_BAND
    FROM [VALUE-BAND_ACCT] INNER JOIN [VALUE-BAND_ACCT] AS [VALUE-BAND_ACCT_1]
    ON [VALUE-BAND_ACCT].GLSeq = [VALUE-BAND_ACCT_1].GLSeq AND
    [VALUE-BAND_ACCT].[LOB$] = [VALUE-BAND_ACCT_1].[LOB$]
    WHERE [VALUE-BAND_ACCT_1].PERIOD =
    DateSerial(Year([VALUE-BAND_ACCT].PERIOD), Month([VALUE-BAND_ACCT].PERIOD)-1, 1)
    or
    SELECT [VALUE-BAND_ACCT].GLSeq, [VALUE-BAND_ACCT].NUM_SITES, [VALUE-BAND_ACCT].SGMNT1,
    [VALUE-BAND_ACCT].SGMNT2, [VALUE-BAND_ACCT].LOB$, [VALUE-BAND_ACCT].PERIOD,
    [VALUE-BAND_ACCT].RECUR, [VALUE-BAND_ACCT].PROMOTED, [VALUE-BAND_ACCT].COMB_REV_GRS,
    [VALUE-BAND_ACCT].COMB_REV_NET, [VALUE-BAND_ACCT].ARPSg_ACCT,
    [VALUE-BAND_ACCT].ARPSn_ACCT, [VALUE-BAND_ACCT].COMB_VALUE_BAND,
    [VALUE-BAND_ACCT_1].COMB_VALUE_BAND AS PRIOR_VALUE_BAND
    FROM [VALUE-BAND_ACCT] INNER JOIN [VALUE-BAND_ACCT] AS [VALUE-BAND_ACCT_1]
    ON [VALUE-BAND_ACCT].GLSeq = [VALUE-BAND_ACCT_1].GLSeq AND
    [VALUE-BAND_ACCT].[LOB$] = [VALUE-BAND_ACCT_1].[LOB$] AND
    [VALUE-BAND_ACCT_1].PERIOD =
    DateSerial(Year([VALUE-BAND_ACCT].PERIOD), Month([VALUE-BAND_ACCT].PERIOD)-1, 1)
    Regards, Hans Vogelaar (http://www.eileenslounge.com)

  • Sub Query Error When Passing Dynamic Parameter.

    Dear All, I need help for below query problem.
    I have try below query run no problem when pass a static Parameter into the query but it throw error once i have add in the dynamic parameter:-
    --Sales BatchNum Transaction
    SELECT T0.[ItemCode], T0.[ItemName], T0.[WhsCode], T0.[BatchNum], ISNULL(T4.[AvgPrice],0) AS 'Avg Price', SUM(T0.[Quantity]) AS 'Sales Quantity',
    (SELECT [Quantity] FROM [OIBT] T1 WHERE T1.[ItemCode] = T0.[ItemCode] AND T1.[WhsCode] = T0.[WhsCode] AND T1.[BatchNum]=T0.[BatchNum]) AS 'Stock OnHand'
    FROM [IBT1] T0 INNER JOIN [OITM] T2 ON T0.[ItemCode] = T2.[ItemCode]
                      INNER JOIN [OITB] T3 ON T2.[ItmsGrpCod] = T3.[ItmsGrpCod]
                      INNER JOIN [OITW] T4 ON T0.[ItemCode] = T4.[ItemCode] AND T0.[WhsCode] = T4.[WhsCode]
    WHERE T0.[BaseType] = [%0] AND T0.[DocDate] BETWEEN [%1] AND [%2] AND T3.[ItmsGrpNam] = [%3]
    GROUP BY T0.[ItemCode], T0.[ItemName], T0.[WhsCode], T0.[BatchNum], T4.[AvgPrice]
    --ORDER BY T0.[ItemCode]
    UNION ALL
    --No Sales Batch Transaction
    SELECT T4.[ItemCode], T4.[ItemName],T4.[WhsCode], T4.[BatchNum], ISNULL(T7.[AvgPrice],0) AS 'Avg Price', 0 AS 'Sales Quantity' ,SUM(T4.[Quantity])
    FROM [OIBT] T4 INNER JOIN [OITM] T5 ON T4.[ItemCode] = T5.[ItemCode]
                      INNER JOIN [OITB] T6 ON T5.[ItmsGrpCod] = T6.[ItmsGrpCod]
                      INNER JOIN [OITW] T7 ON T4.[ItemCode] = T7.[ItemCode] AND T4.[WhsCode] = T7.[WhsCode]
    WHERE NOT EXISTS
    ( SELECT T0.[ItemCode], T0.[ItemName], T0.[WhsCode], T0.[BatchNum], ISNULL(T5.[AvgPrice],0) AS 'Avg Price', SUM(T0.[Quantity]) AS 'Sales Quantity'
      FROM [IBT1] T0 INNER JOIN [OITM] T2 ON T0.[ItemCode] = T2.[ItemCode]
                        INNER JOIN [OITB] T3 ON T2.[ItmsGrpCod] = T3.[ItmsGrpCod]
                         INNER JOIN [OITW] T5 ON T0.[ItemCode] = T5.[ItemCode] AND T0.[WhsCode] = T5.[WhsCode]
      WHERE T0.[BaseType] = [%1] AND T0.[DocDate] BETWEEN [%1] AND [%2] AND T4.[ItemCode]=T0.[ItemCode] AND T4.[WhsCode]=T0.[WhsCode] AND T4.[BatchNum]=t0.[BatchNum] AND T3.[ItmsGrpNam] = [%3]
      GROUP BY T0.[ItemCode], T0.[ItemName], T0.[WhsCode], T0.[BatchNum],T5.[AvgPrice]
    AND T6.[ItmsGrpNam] = [%3]
    GROUP BY T4.[ItemCode], T4.[ItemName], T4.[WhsCode], T4.[BatchNum], T7.[AvgPrice]
    HAVING SUM(T4.[Quantity]) > 0
    ORDER BY 1, 2, 3, 5 DESC
    I think SAP Query Manager can support the sub-query, kindly advise how to solve or other alternative way to solve this issue.
    Thanks a lot.

    Dear  Thanga Raj K,
    From your solution i can get my expected result, only within your solution you miss out the @ in line 32 for ToDate variable.
    After i have added it, it working perfectly.
    Thanks once again.
    For other user References code(Corrected):-
    Declare @basetype as int
    Declare @FromDate as Datetime
    Declare @ToDate as Datetime
    Declare @ItemGroup as nvarchar(30)
    set @basetype = (select max(s0.BaseType) from IBT1 S0 where s0.BaseType = '[%0]')
    set @FromDate = (select min(S1.DocDate) from IBT1 S1 where S1.DocDate >= '[%1]')
    set @ToDate = (select max(S2.DocDate) from IBT1 S2 where S2.DocDate <= '[%2]')
    set @ItemGroup = (select max(S3.ItmsGrpNam) from OITB s3 where S3.ItmsGrpNam = '[%3]')
    --Sales BatchNum Transaction
    SELECT T0.ItemCode, T0.ItemName, T0.WhsCode, T0.BatchNum, ISNULL(T4.AvgPrice,0) AS 'Avg Price', SUM(T0.Quantity) AS 'Sales Quantity',
    (SELECT Quantity FROM OIBT T1 WHERE T1.ItemCode = T0.ItemCode AND T1.WhsCode = T0.WhsCode AND T1.BatchNum=T0.BatchNum) AS 'Stock OnHand'
    FROM IBT1 T0 INNER JOIN OITM T2 ON T0.ItemCode = T2.ItemCode
    INNER JOIN OITB T3 ON T2.ItmsGrpCod = T3.ItmsGrpCod
    INNER JOIN OITW T4 ON T0.ItemCode = T4.ItemCode AND T0.WhsCode = T4.WhsCode
    WHERE T0.BaseType = @basetype AND T0.DocDate BETWEEN @FromDate AND @ToDate AND T3.ItmsGrpNam = @ItemGroup
    GROUP BY T0.ItemCode, T0.ItemName, T0.WhsCode, T0.BatchNum, T4.AvgPrice
    --ORDER BY T0.ItemCode
    UNION ALL
    --No Sales Batch Transaction
    SELECT T4.ItemCode, T4.ItemName,T4.WhsCode, T4.BatchNum, ISNULL(T7.AvgPrice,0) AS 'Avg Price', 0 AS 'Sales Quantity' ,SUM(T4.Quantity)
    FROM OIBT T4 INNER JOIN OITM T5 ON T4.ItemCode = T5.ItemCode
    INNER JOIN OITB T6 ON T5.ItmsGrpCod = T6.ItmsGrpCod
    INNER JOIN OITW T7 ON T4.ItemCode = T7.ItemCode AND T4.WhsCode = T7.WhsCode
    WHERE NOT EXISTS
    (SELECT T0.ItemCode, T0.ItemName, T0.WhsCode, T0.BatchNum, ISNULL(T5.AvgPrice,0) AS 'Avg Price', SUM(T0.Quantity) AS 'Sales Quantity'
    FROM IBT1 T0 INNER JOIN OITM T2 ON T0.ItemCode = T2.ItemCode
    INNER JOIN OITB T3 ON T2.ItmsGrpCod = T3.ItmsGrpCod
    INNER JOIN OITW T5 ON T0.ItemCode = T5.ItemCode AND T0.WhsCode = T5.WhsCode
    WHERE T0.BaseType = @basetype AND T0.DocDate BETWEEN @FromDate AND @ToDate AND T4.ItemCode=T0.ItemCode AND T4.WhsCode=T0.WhsCode AND T4.BatchNum=t0.BatchNum AND T3.ItmsGrpNam = @ItemGroup
    GROUP BY T0.ItemCode, T0.ItemName, T0.WhsCode, T0.BatchNum,T5.AvgPrice
    AND T6.ItmsGrpNam = @ItemGroup
    GROUP BY T4.ItemCode, T4.ItemName, T4.WhsCode, T4.BatchNum, T7.AvgPrice
    HAVING SUM(T4.Quantity) > 0
    ORDER BY 1, 2, 3, 5 DESC

  • Use of Sub Query in a filter is throwing error

    Hi
    I am using a sub query in a filter which throws me the following error in owb 9i.
    PLS 00405 : Subquery cannot be used in this context.
    But the use of subquery works fine in a joiner operator.
    Use of Sub Query in a filter works fine in owb 2i.
    Could any one please help me.
    Thanks in Advance
    Nanda Kishore

    Nanda,
    Please wrap the source table in a view containing the subquery and then use the view as a source rather than use the subquery in the filter.
    Regards:
    Igor

  • Query is executed although sub-query is error?

    Hi everyone,
    I have a problem want to explained.
    My sub-query show an error if it's executed alone: "ORA-00904: invalid column name"
    SELECT id FROM table_A WHERE field1 = 'exam' (field1 is not exist)
    But when execute with:
    SELECT * FROM table_B WHERE id IN (SELECT id FROM table_A WHERE field1 = 'exam')
    it's ok, although we don't have any data filtered. I don't known the reason why? Can anyone explain this?
    Thanks a lot!

    I think you're looking at something like this...
    SQL> select deptno from emp where dname = 'SALES';
    select deptno from emp where dname = 'SALES'
    ERROR at line 1:
    ORA-00904: "DNAME": invalid identifier
    SQL> select deptno from dept where deptno in (select deptno from emp where dname in 'SALES');
        DEPTNO
            30
    SQL> select deptno from dept where deptno in (select deptno from emp where emp.dname in 'SALES');
    select deptno from dept where deptno in (select deptno from emp where emp.dname in 'SALES')
    ERROR at line 1:
    ORA-00904: "EMP"."DNAME": invalid identifier
    SQL> ed
    Wrote file afiedt.buf
      1* select deptno from dept where deptno in (select deptno from emp where dept.dname in 'SALES')
    SQL> /
        DEPTNO
            30In this example, "DNAME" doesn't exist in the emp table, but in the second query it seems to work. However what it's really doing is referencing the "DNAME" column of the outer query. This is proved in the third and fourth query by prefixing the DNAME column with the EMP and DEPT table names to explicitly say where we are expecting the column to come from.

  • How to find out which sub query returns more than one row

    Hi all,
    Can any one give me clue ,how to find out which sub query returns more than one row in the following query .
    /* Formatted on 2011/05/17 19:22 (Formatter Plus v4.8.8) */
    SELECT a.*, ROWNUM AS rnm
      FROM (SELECT DISTINCT '1' AS "Page View", ou.org_unit_name AS "Org",
                            prxm.mbr_idntfr AS "Beneficiary ID",
                               md.last_name
                            || ', '
                            || md.first_name AS "Beneficiary Name",
                            pci.idntfr AS "Tracking No.",
                            TO_CHAR (TRUNC (req.pa_rqst_date),
                                     'MM/dd/yyyy'
                                    ) AS "Request Date",
                            sts.status_name AS "Status",
                            req.pa_rqst_sid AS "Request #",
                            prxm.mbr_sid AS "Mbr_sid",
                            TO_CHAR
                                  (TRUNC (req.pa_revision_date),
                                   'MM/dd/yyyy'
                                  ) AS "Last Updated",
                            TO_CHAR (psd.TO_DATE, 'MM/dd/yyyy') AS "TO_DATE",
                            prxpl.prvdr_lctn_iid AS "PRVDR_LCTN_IID",
                            pd.prvdr_sid AS "PRVDR_SID", 'Y' AS "State View",
                            DECODE
                               ((SELECT DISTINCT pd.national_prvdr_idntfr
                                            FROM pa_request_x_provider_location prxplo
                                           WHERE prxplo.pa_rqst_sid =
                                                                   req.pa_rqst_sid
                                             AND prxplo.oprtnl_flag = 'A'
                                             AND prxplo.pa_prvdr_type_lkpcd = 'RR'),
                                0, (SELECT prxplo.prvdr_lctn_idntfr
                                      FROM pa_request_x_provider_location prxplo
                                     WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid
                                       AND prxplo.oprtnl_flag = 'A'
                                       AND prxplo.pa_prvdr_type_lkpcd = 'RR'),
                                NULL, (SELECT prxplo.prvdr_lctn_idntfr
                                         FROM pa_request_x_provider_location prxplo
                                        WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid
                                          AND prxplo.oprtnl_flag = 'A'
                                          AND prxplo.pa_prvdr_type_lkpcd = 'RR'),
                                (SELECT DISTINCT pd.national_prvdr_idntfr
                                            FROM pa_request_x_provider_location prxplo
                                           WHERE prxplo.pa_rqst_sid =
                                                                   req.pa_rqst_sid
                                             AND prxplo.oprtnl_flag = 'A'
                                             AND prxplo.pa_prvdr_type_lkpcd = 'RR')
                               ) AS "NPI/ID",
                            DECODE
                               ((SELECT pd.org_bsns_name
                                   FROM pa_request_x_provider_location prxplo
                                  WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid
                                    AND prxplo.oprtnl_flag = 'A'
                                    AND prxplo.pa_prvdr_type_lkpcd = 'RR'),
                                NULL, (SELECT    pd.last_name
                                              || ', '
                                              || pd.first_name
                                              || ' '
                                              || pd.middle_name
                                         FROM pa_request_x_provider_location prxplo
                                        WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid
                                          AND prxplo.oprtnl_flag = 'A'
                                          AND prxplo.pa_prvdr_type_lkpcd = 'RR'),
                                (SELECT pd.org_bsns_name
                                   FROM pa_request_x_provider_location prxplo
                                  WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid
                                    AND prxplo.oprtnl_flag = 'A'
                                    AND prxplo.pa_prvdr_type_lkpcd = 'RR')
                               ) AS "Prvdr Name",
                            TO_CHAR (psd.from_date,
                                     'MM/dd/yyyy'
                                    ) AS "Srvc From Date",
                            TO_CHAR (req.validity_start_date,
                                     'MM/DD/YYYY'
                                    ) AS "Due Date",
                            (fn_get_busniess_days (TRUNC (req.validity_start_date))
                            ) AS "Days<br>Left",
                            req.pa_mode_type_lkpcd AS "Source",
                            TO_CHAR (TRUNC (wmdtl.rtng_date),
                                     'MM/dd/yyyy'
                                    ) AS "Assigned On",
                            NVL (wmdtl.assigned_to_user_name,
                                 'Not Assigned'
                                ) AS "Assigned To",
                            req.org_unit_sid AS "OrgUnitSid",
                            TO_CHAR
                                 (wmdtl.modified_date,
                                  'MM/dd/yyyy hh24:mi:ss'
                                 ) AS "WTRD_MODIFIED_DATE",
                            TO_CHAR (wmdtl.rtng_date,
                                     'MM/dd/yyyy'
                                    ) AS "WTRD_RTNG_DATE",
                            req.status_cid AS "PA_STATUS_CID",
                            TO_CHAR (req.modified_date,
                                     'MM/dd/yyyy'
                                    ) AS "PA_REQ_MODIFIED_DATE",
                            prs.state_pa_srvc_type_code
                                                     AS "STATE_PA_SRVC_TYPE_CODE",
                            wmdtl.wm_pa_task_rtng_dtl_sid
                                                        AS "WM_TASK_RTNG_DTL_SID",
                            wmdtl.assigned_to_user_acct_sid
                                              AS "WTRD_Assigned_to_user_acct_sid",
                            (fn_get_busniess_days (TRUNC (req.validity_start_date))
                            ) AS "Days<br>LeftSort",
                            wmdtl.assigned_to_org_unit_sid
                                                  AS "WTRD_Assigned_to_OrgUntSid",
                            DECODE
                               ((SELECT COUNT (*)
                                   FROM pa_request_status prs
                                  WHERE prs.pa_rqst_sid = req.pa_rqst_sid
                                    AND prs.status_cid = 5
                                    AND prs.oprtnl_flag = 'I'),
                                0, 'N',
                                'Y'
                               ) AS "SHOW_UTILIZATION"
                       FROM   pa_request req,
                             pa_certification_identifier pci,
                             status sts,
                             pa_request_x_member prxm,
                             wm_pa_task_routing_detail wmdtl,
                             pa_service_date psd,
                             org_unit ou,
                             pa_request_service prs,
                             pa_request_x_provider_location prxpl,
                             provider_location pl,
                             provider_detail pd,
                             provider p,
                             mbr_dmgrphc md
                      WHERE req.oprtnl_flag = 'A'
                        AND req.status_cid NOT IN
                                     (20, 30, 70, 25, 80, 96, 85, 5, 97, 98, 101)
                        AND req.org_unit_sid IN
                               (3057, 3142, 3058, 3143, 3059, 3144, 3060, 3145,
                                3061, 3146, 3062, 3147, 3063, 3148, 3064, 3149,
                                3065, 3150, 3066, 3151, 3067, 3152, 3068, 3153,
                                3069, 3154, 3070, 3155, 3071, 3156, 3072, 3157,
                                3073, 3158, 3074, 3159, 3075, 3160, 3076, 3161,
                                3077, 3162, 3078, 3163, 3079, 3164, 3080, 3165,
                                3081, 3166, 3082, 3167, 3083, 3168, 3084, 3169,
                                3085, 3170, 3086, 3171, 3087, 3172, 3088, 3173,
                                3089, 3174, 3090, 3175, 3091, 3176, 3092, 3177,
                                3093, 3178, 3094, 3179, 3095, 3180, 3096, 3181,
                                3097, 3182, 3098, 3183, 3099, 3184, 3100, 3185,
                                3101, 3186, 3102, 3187, 3103, 3003, 75000104,
                                75000108, 2006, 75000103, 75000102, 75000113,
                                75000111, 75000109, 2001, 2009, 75000105,
                                75000107, 2004, 2010, 2013, 2014, 2005, 2011,
                                75000112, 2002, 1001, 2012, 75000106, 2007,
                                75000101, 2003, 75000110, 2008, 3001, 3002, 3019,
                                3104, 3020, 3105, 3021, 3106, 3022, 3107, 3023,
                                3108, 3024, 3109, 3025, 3110, 3026, 3111, 3027,
                                3112, 3028, 3113, 3029, 3114, 3030, 3115, 3031,
                                3116, 3032, 3117, 3033, 3118, 3034, 3119, 3035,
                                3120, 3036, 3121, 3037, 3122, 3038, 3123, 3039,
                                3124, 3040, 3125, 3041, 3126, 3042, 3127, 3043,
                                3128, 3044, 3129, 3045, 3130, 3046, 3131, 3047,
                                3132, 3048, 3133, 3049, 3134, 3050, 3135, 3051,
                                3136, 3052, 3137, 3053, 3138, 3054, 3139, 3055,
                                3140, 3056, 3141)
                        AND req.pa_rqst_sid = prs.pa_rqst_sid
                        AND prs.oprtnl_flag = 'A'
                        AND prs.pa_rqst_srvc_sid = psd.pa_rqst_srvc_sid
                        AND psd.oprtnl_flag = 'A'
                        AND req.pa_rqst_sid = pci.pa_rqst_sid
                        AND pci.oprtnl_flag = 'A'
                        AND req.pa_rqst_sid = prxm.pa_rqst_sid
                        AND prxm.oprtnl_flag = 'A'
                        AND md.oprtnl_flag = 'A'
                        AND md.status_cid = 2
                        AND TRUNC (SYSDATE) BETWEEN md.from_date AND md.TO_DATE
                        AND prxm.mbr_sid = md.mbr_sid
                        AND ou.org_unit_sid = req.org_unit_sid
                        AND ou.oprtnl_flag = 'A'
                        AND req.pa_rqst_sid = prxpl.pa_rqst_sid
                        AND prxm.pa_rqst_sid = prxpl.pa_rqst_sid
                        AND pci.pa_rqst_sid = prxm.pa_rqst_sid
                        AND pci.pa_rqst_sid = wmdtl.subsystem_task_sid
                        AND pci.pa_rqst_sid = prxpl.pa_rqst_sid
                        AND prxpl.pa_prvdr_type_lkpcd = 'RR'
                        AND prxpl.oprtnl_flag = 'A'
                        AND req.status_cid = sts.status_cid
                        AND sts.status_type_cid = 3
                        AND sts.oprtnl_flag = 'A'
                        AND prxpl.prvdr_lctn_iid = pl.prvdr_lctn_iid
                        AND p.prvdr_sid = pd.prvdr_sid
                        AND p.prvdr_sid = pl.prvdr_sid
                        AND pd.oprtnl_flag = 'A'
                        AND pd.status_cid = 2
                        AND TRUNC (SYSDATE) BETWEEN pd.from_date AND pd.TO_DATE
                        AND wmdtl.subsystem_task_sid = req.pa_rqst_sid
                        AND wmdtl.subsystem_lkpcd = 'PA'
                        AND wmdtl.oprtnl_flag = 'A'
                        AND req.pa_rqst_date > (SYSDATE - 365)
                                       ORDER BY TO_DATE ("Request Date", 'MM/dd/yyyy hh24:mi:ss') DESC,
                            "Beneficiary Name" ASC) a
    WHERE ROWNUM < 102;regards,
    P Prakash
    Edited by: BluShadow on 17-May-2011 15:01
    added {noformat}{noformat} tags around the code                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    833560 wrote:
    Can any one give me clue ,how to find out which sub query returns more than one row in the following query .This is why smaller, simpler queries are easier to work with than huge ones - when something like this goes wrong smaller queries are much eaiser to debug. Unfortunately using smaller, easier-to-work with queries is not always an option
    Ganesh is right - you will have to dissect the big query bit by bit until you find the offending subquery. If there is another way I would like to find out about it too.
    The easiest way to do this is probably to use block comments to isolate parts of the query bit by bit until you find the offending part. If you carefully examine the subqueries you might be able to figure out which one is returning multiple rows without commenting everything
    Good luck!

  • Error in Sub-Query

    Dear All,
    Based on below image show that the error message, As i know is aggregation problem  in sub query, May i know how to solve it ? thank you.  

    Please have enough Netiquette to post DDL and not pictures. 
    Think about how absurd  "MIN(AVG(AGE)))" on two levels. No, really, you can see that this is absurd if you have any concept of sets. 
    No competent programmer would put age in a column. It is a dynamic value! The constant is birith_date.   Age is computed in the presentation  layers. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Form debugging - Which line is causing the error?

    I have a form that I'm working on, and when I run the form like normal, just as the end user would, I keep getting an error, "FRM-41039: Invalid Alert ID 0." I can't figure out where this error is coming from in my code. It seems that it must have something to do with timing, because in trying to track down the error, when I run the form in debug mode, obviously the timing is slower as I go line-by-line in the code to see which line may be causing the error, but when I do that, I don't get the same error. I'm not close to being an expert when it comes to design-time debugging in forms, and I was wondering if someone with more experience could point me in the right direction. Is there any way that I can somehow determine which line of code is causing this error to raise? If I could identify the line of code, I could maybe find out which alert it's looking for, right? Then I could maybe narrow down the problem a bit more. Anyone have any ideas? Thanks in advance.
    YEX
    <)))><

    Like it says :"FRM-41039: Invalid Alert ID 0." Alert does not exist. So try to find line in your code which contain something like:
    Show_Alert("<name of alert>")
    Or Alert with this name dows not exist or you are misspelling the name of existing Alert.

  • Single row sub query error

    Hi All
    I'm having the following query and its giving me "single row sub query returns more than one row". I did some research and all i could come across is using IN,ALL,ANY,NOT IN.... with the WHERE clause but not in the CASE statement so can any one please point me in the right direction?
    SELECT ROW_NUMBER () OVER (PARTITION BY traffic_sample_id ORDER BY bin_data_id)
                                                                  AS row_number_1,
           COUNT (bin_data_id) OVER (PARTITION BY traffic_sample_id) AS count_1,
           (CASE
               WHEN days != 2
                  THEN (SELECT traffic_sample_id
                          FROM (SELECT ROW_NUMBER () OVER (PARTITION BY traffic_sample_id ORDER BY bin_data_id)
                                                                            AS rn,
                                       traffic_sample_id
                                  FROM bin_data)
                         WHERE rn <= 48)
               ELSE (SELECT traffic_sample_id
                       FROM bin_data)
            END
           ) traffic_sample_id
      FROM (SELECT ROW_NUMBER () OVER (PARTITION BY t1.traffic_sample_id ORDER BY t1.bin_data_id)
                                                                    AS ROW_NUMBER,
                   COUNT (t1.bin_data_id) OVER (PARTITION BY t1.traffic_sample_id)
                                                                         AS COUNT,
                   t1.traffic_sample_id, t1.bin_data_id, t1.end_intv_time,
                   (  TO_DATE (t2.end_date, 'mmddyy')
                    - TO_DATE (t2.start_date, 'mmddyy')
                   ) AS days
              FROM bin_data t1, traffic_sample t2
             WHERE t1.traffic_sample_id = t2.traffic_sample_id(+))Thanks

    Hi,
    One of these two SELECT statements must be bringing back more thean one row:
                  THEN (SELECT traffic_sample_id
                          FROM (SELECT ROW_NUMBER () OVER (PARTITION BY traffic_sample_id ORDER BY bin_data_id)
                                                                            AS rn,
                                       traffic_sample_id
                                  FROM bin_data)
                         WHERE rn <= 48)
               ELSE (SELECT traffic_sample_id
                       FROM bin_data)

  • Joining with sub query not working

    Hi
    I am new with these complex queries. I am trying to join a sub query to a query as below;
    SELECT Events1.InvoiceBatch AS BatchNo, Events1.InvoiceBatchDate AS BatchDate, tblClients.Company, tblClients.ID AS ClientID, COUNT(Events1.ID) AS Invoices,
    COUNT(*) - COUNT(Events1.InvoicePrintDate) AS E, Events1.InvoiceBatchFromDate AS BatchFrom, Events1.InvoiceBatchToDate AS BatchTo, (SELECT EventID, SUM(Total) FROM tblStaffBookings AS StaffBookings WHERE StaffBookings.EventID = Events1.ID GROUP BY EventID) AS Total
    FROM tblEvents AS Events1 LEFT OUTER JOIN
    tblClients ON Events1.ClientID = tblClients.ID
    WHERE (Events1.FactoringExportDate IS NULL) OR (Events1.AccountsExportDate IS NULL) OR (Events1.InvoiceSentDate IS NULL)
    GROUP BY Events1.InvoiceBatch, Events1.InvoiceBatchDate, tblClients.Company, tblClients.ID, Events1.InvoiceBatchFromDate, Events1.InvoiceBatchToDate
    HAVING (Events1.InvoiceBatch = 5212)
    ORDER BY tblClients.Company
    I am getting these two errors;
    Msg 8120, Level 16, State 1, Line 2
    Column 'tblEvents.ID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
    Msg 116, Level 16, State 1, Line 2
    Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
    What am I missing?
    Thanks
    Regards

    SELECT Events1.InvoiceBatch AS BatchNo, Events1.InvoiceBatchDate AS BatchDate, tblClients.Company, tblClients.ID AS ClientID, COUNT(Events1.ID) AS Invoices,
    COUNT(*) - COUNT(Events1.InvoicePrintDate) AS E, Events1.InvoiceBatchFromDate AS BatchFrom, Events1.InvoiceBatchToDate AS BatchTo,Total
    FROM tblEvents AS Events1 LEFT OUTER JOIN
    tblClients ON Events1.ClientID = tblClients.ID
    LEFT OUTER JOIN (SELECT EventID, SUM(Total) AS Total FROM tblStaffBookings AS StaffBookings WHERE StaffBookings.EventID = Events1.ID GROUP BY EventID) sb
    ON sb.EventID = Events1.ID
    WHERE (Events1.FactoringExportDate IS NULL) OR (Events1.AccountsExportDate IS NULL) OR (Events1.InvoiceSentDate IS NULL)
    GROUP BY Events1.InvoiceBatch, Events1.InvoiceBatchDate, tblClients.Company, tblClients.ID, Events1.InvoiceBatchFromDate, Events1.InvoiceBatchToDate,Total
    HAVING (Events1.InvoiceBatch = 5212)
    ORDER BY tblClients.Company
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page
    Says;
    Msg 4104, Level 16, State 1, Line 5
    The multi-part identifier "Events1.ID" could not be bound.
    on
    LEFT OUTER JOIN (SELECT EventID, SUM(Total) AS Total FROM tblStaffBookings AS StaffBookings WHERE StaffBookings.EventID = Events1.ID GROUP BY EventID) sb
    Regards

  • Weird prob with sub query

    Hello All,
    I am having trouble with the code. I am using a subquery in the select statment and the same in the where clause(2nd sq in the select which populates on_hand column). I have highlighted the sub query as shown below. The code runs fine when i comment the subquery in select, which gets "sub_inv" column value(3rd subquery in the select). if i include it then i get ora-01427 error though neither of the sub queries return multiple rows.
    Please let me know where i am going wrong.
    select ms.organization_id, ms.segment1,ms.description,
    ms.planner_code,pl.closed_code,ploc.quantity - ploc.quantity_received - ploc.quantity_cancelled qty_rem,
    (select full_name from
              per_all_people_f p,
              inv.mtl_planners mp
              where
              ms.planner_code = mp.planner_code
              and mp.employee_id = p.person_id
              and mp.organization_id = ms.organization_id) planner_name,
    min_minmax_quantity, max_minmax_quantity,
    /***2nd sq***/
    (select sum( oh.transaction_quantity)
                   from mtl_onhand_quantities_detail oh
                   where ms.inventory_item_id = oh.inventory_item_id
                   and ms.organization_id = oh.organization_id
                   ) on_hand,
    /***3rd sq***/
    (select oh.subinventory_code
                   from mtl_onhand_quantities_detail oh
                   where ms.inventory_item_id = oh.inventory_item_id
                   and ms.organization_id = oh.organization_id ) sub_inv,
    ph.segment1, pl.line_num, ploc.shipment_num,
    nvl((select vendor_name from po_vendors where vendor_id = ph.vendor_id),'NONE') vendor_name,
    pr.release_num,
    PL.PO_LINE_ID,
    PH.PO_HEADER_ID
    from
    inv.mtl_system_items_b ms,
    po.po_line_locations_all ploc,
    po_lines_all pl,
    po_headers_all ph,
    po.po_releases_all pr
    where 1=1
    and ms.inventory_item_id = pl.item_id(+)
    and pl.po_line_id = ploc.po_line_id
    and pl.po_header_id = ph.po_header_id
    and ploc.po_release_id = pr.po_release_id(+)
    and ploc.quantity - (ploc.quantity_received + ploc.quantity_cancelled) > 0
    and nvl(pl.closed_code (+), 'OPEN')= 'OPEN'
    AND NVL(PLOC.CLOSED_CODE,'OPEN') = 'OPEN'
    ---and ms.organization_id = 43
    --and ms.inventory_item_id = 708
    and max_minmax_quantity is not null
    and min_minmax_quantity is not null
    and (select sum( oh.transaction_quantity)
                   from mtl_onhand_quantities_detail oh
                   where ms.inventory_item_id =oh.inventory_item_id
                   and ms.organization_id = oh.organization_id
                   ) is not null

    >
    shown below. The code runs fine when i comment the
    subquery in select, which gets "sub_inv" column
    value(3rd subquery in the select). if i include it
    then i get ora-01427 error though neither of the sub
    queries return multiple rows.
    Please let me know where i am going wrong. Are you sure about this ?
    I believe this is Oracle apps tables, and if it's true one item in one org can have multiple rows with the same subinventory_code in mtl_onhand_quantities_detail table.
    Run the query below to check and see if it return any rows :
    select inventory_item_id, organization_id,count(subinventory_code)
    from mtl_onhand_quantities_detail
    group by inventory_item_id,organization_id
    having count(subinventory_code) > 1

Maybe you are looking for

  • Using SDK (SSOToken) with Agent 2.1 on Application Server 8.1

    My environment: Access Manager from JES 2005Q1 unpatched running on Application Server 8.1_02 build b10_fcs An application � protected by agent 2.1 - running on Application Server 8.1_02 build b10_fcs. The application is also using the API for creati

  • How can I reorganize the list of my email accounts in TB 31.5.0?

    How can I change the order of my email accounts in the folder pane? In my current version (31.5.0) there is no way to rearrange the order of my email account.

  • Limit testing

    I'm trying to get an upper and lower limit to display with dynamic dynamic on waveform chart 2 of the attached VI.  The help in the vi states that there should be 4 outputs available to the plot, the original plot, the error plot and the upper and lo

  • How to batch password protect files without having to click "Save" for each file

    Hi! I need help. I'm trying to batch password protect a few hundred PDF files. I've setup an action for this, however when I run the action, Acrobat asks me to save each file. Isn't this kind of defeating the purpose of batch processing? Adrian

  • DHCP Mirgation from 2008 to 2012

    Hi, I am migrating DHCP server 2008 to 2012 Environment. Please let me know the Best practice of migration. I have configured DHCP failover in Windows 2008 R2 Environment. Any help would be very grateful. Thankx & Regards, DD6