Bug in WITH clause (subquery factoring clause) in Oracle 11?

I'm using WITH to perform a set comparison in order to qualify a given query as correct or incorrect regarding an existing solution. However, the query does not give the expected result - an empty set - when comparing the solution to itself in Oracle 11 whereas it does in Oracle 10. A minimal example os posted below as script. There are also some observations about changes to the tables or the query that make Oracle 11 returning correct results but in my opinion these changes must not change the semantics of the queries.
Is this a bug or am I getting something wrong? The Oracle versions are mentioned in the script.
-- Bug in WITH clause (subquery factoring clause)
-- in Oracle Database 11g Enterprise Edition 11.2.0.1.0?
DROP TABLE B PURGE;
DROP TABLE K PURGE;
DROP TABLE S PURGE;
CREATE TABLE S (
     m     number NOT NULL,
     x     varchar2(30) NOT NULL
CREATE TABLE K (
     k char(2) NOT NULL,
     x varchar2(50) NOT NULL
CREATE TABLE B (
     m     number NOT NULL ,
     k char(2) NOT NULL ,
     n     number
INSERT INTO S VALUES(1, 'h');
INSERT INTO S VALUES(2, 'l');
INSERT INTO S VALUES(3, 'm');
INSERT INTO K VALUES('k1', 'd');
INSERT INTO K VALUES('k2', 'i');
INSERT INTO K VALUES('k3', 'm');
INSERT INTO K VALUES('k4', 't');
INSERT INTO K VALUES('k5', 't');
INSERT INTO K VALUES('k6', 's');
INSERT INTO B VALUES(1, 'k1', 40);
INSERT INTO B VALUES(1, 'k2', 30);
INSERT INTO B VALUES(1, 'k4', 50);
INSERT INTO B VALUES(3, 'k1', 10);
INSERT INTO B VALUES(3, 'k2', 20);
INSERT INTO B VALUES(3, 'k1', 30);
INSERT INTO B VALUES(3, 'k6', 90);
COMMIT;
ALTER TABLE S ADD CONSTRAINT S_pk PRIMARY KEY (m);
ALTER TABLE K ADD CONSTRAINT K_pk PRIMARY KEY (k);
ALTER TABLE B ADD CONSTRAINT B_S_fk
FOREIGN KEY (m) REFERENCES S(m) ON DELETE CASCADE;
CREATE OR REPLACE VIEW v AS
SELECT S.m, B.n
FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
WHERE K.x='d'
ORDER BY B.n DESC;
-- Query 1: Result should be 0
WITH q AS
SELECT S.m, B.n
FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
WHERE K.x='d'
ORDER BY B.n DESC
SELECT COUNT(*)
FROM
SELECT * FROM q
MINUS
SELECT * FROM v
UNION ALL
SELECT * FROM v
MINUS
SELECT * FROM q
-- COUNT(*)
-- 6
-- 1 rows selected
-- Query 2: Result set should be empty (Query 1 without counting)
WITH q AS
SELECT S.m, B.n
FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
WHERE K.x='d'
ORDER BY B.n DESC
SELECT *
FROM
SELECT * FROM q
MINUS
SELECT * FROM v
UNION ALL
SELECT * FROM v
MINUS
SELECT * FROM q
-- M N
-- null 10
-- null 30
-- null 40
-- 1 40
-- 3 10
-- 3 30
-- 6 rows selected
-- Observations:
-- Incorrect results in Oracle Database 11g Enterprise Edition 11.2.0.1.0:
-- Query 1 returns 6, Query 2 returns six rows.
-- Correct in Oracle Database 10g Enterprise Edition 10.2.0.1.0.
-- Correct without the foreign key.
-- Correct if attribute x is renamed in S or K.
-- Correct if attribute x is left out in S.
-- Correct without the ORDER BY clause in the definition of q.
-- Only two results if the primary key on K is left out.
-- Correct without any change if not using WITH but subqueries (see below).
-- Fixed queries
-- Query 1b: Result should be 0
SELECT COUNT(*)
FROM
SELECT * FROM
SELECT S.m, B.n
FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
WHERE K.x='d'
ORDER BY B.n DESC
MINUS
SELECT * FROM v
UNION ALL
SELECT * FROM v
MINUS
SELECT * FROM
SELECT S.m, B.n
FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
WHERE K.x='d'
ORDER BY B.n DESC
-- COUNT(*)
-- 0
-- 1 rows selected
-- Query 2b: Result set shoud be empty (Query 1b without counting)
SELECT *
FROM
SELECT * FROM
SELECT S.m, B.n
FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
WHERE K.x='d'
ORDER BY B.n DESC
MINUS
SELECT * FROM v
UNION ALL
SELECT * FROM v
MINUS
SELECT * FROM
SELECT S.m, B.n
FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
WHERE K.x='d'
ORDER BY B.n DESC
-- M N
-- 0 rows selected

You're all gonna love this one.....
The WITH clause works. But not easily.
Go ahead, build the query, (as noted in a recent thread, I, too, always use views), set the grants and make sure DISCOVERER and EULOWNER have SELECT privs.
1. Log into Disco Admin as EULOWNER. Trust me.
2. Add the view as a folder to the business area.
3. Log into Disco Desktop as EULOWNER. Don't laugh. It gets better.
4. Build the workbook and the worksheet (or just the worksheet if apropos)
5. Set the appropriate "sharing" roles and such
6. Save the workbook to the database.
7. Save the workbook to your computer.
8. Log out of Desktop.
9. Log back into Desktop as whatever, whoever you usually are to work.
10. elect "open existing workbook"
11. Select icon for "open from my computer". See? I told you it would get better!
12. Open the save .dis file from your computer.
13. Save it to the database.
14. Open a web browser and from there, you're on your own.
Fortran in VMS. Much easier and faster. I'm convinced the proliferation of the web is a detriment to the world at large...On the other hand, I'm also waiting for the Dodgers to return to Brooklyn.

Similar Messages

  • OBIEE 11g "WITH SAWITH0 AS" subquery factoring clause in the generated sql

    I've observed that the OBIEE 11g generates in the query log physical query using the WITH (sub-query factoring) clause to make the generated sql elegantly readable. This is great! Thanks for the developers. However I have some questions about this.
    __Background__
    Oracle Database' default behaviour is that if you have only one sub-query in the WITH section, it executes it as an in-line view and does not materialize it before the main sql is executed. If you have more than one, by default the database engine materializes all of them in the order of the definition. In some cases this can completely blow up the SGA and make the query never ending. To divert this behaviour you can apply two hints that work both in inline views and in sub-queries as well: /*+ MATERIALIZE */ and /*+ INLINE*/, however Analytics 11g does not seem to have hint capabilities at the logical table level, only at physical table level.
    If we go with the current defaults, developers not aware of this feature can bump into serious performance issues for the sake of some syntax candy at the generated sql level, I'm afraid.
    __Questions__
    * Is it possible to turn the Analytics server not to use WITH but use inline views instead?
    * Is there any way to sneak in some hints that would put the /*+ INLINE */ hint to the appropriate place in the generated sub-queries if needed
    * Does the Oracle Database have any initialization parameter that can influence this sub-query factoring behavior and divert from the default?

    The WITH statement is not added to make the query more elegant, it's added for performance reasons. If your queries take long to run then you may have a design issue. In a typical DWH DB SGA needs to be seriously increased since the queries ran are much larger and complex than on an OLTP DB. In any case you can disable the WITH statement in the Admin Tool by double clicking on your database object on the physical layer and going to the Features tab. The feature is called WITH_CLAUSE_SUPPORTED.

  • Recursive WITH (Recursive Subquery Factoring) Never Returns

    11.2.0.2 database on Windows, SQL Developer Version 3.2.20.09, build MAIN-09.87 (Database and SQL Developer are on the same machine. I have also tried connecting to a Linux 11.2 database and have the same results.)
    I've been doing some simple testing with recursive WITH (Recursive Subquery Factoring) and when I run this following statement in SQL*Plus it returns instantly. However when running in SQL Developer it never returns, I've let it run for quite a long time (172 seconds) and gotten nothing, I finally kill the statement. Once I ran it and even killing the job didn't come back. I can get an explain plan but if I try to run it, run as script or autotrace it never returns. I have only one plan in the plan_table for this test, and it's only 4 lines long. No errors, no messages.
    WITH get_plan (query_plan, id, planlevel) as
    select ' '||operation||' '||options||' '||object_name query_plan, id, 1 planlevel
    from plan_table
    where id = 0
    union all
    select lpad(' ',2*planlevel)||p.operation||' '||p.options||' '||p.object_name query_plan, p.id, planlevel+1
    from get_plan g, plan_table p
    where g.id = p.parent_id
    SELECT QUERY_PLAN FROM GET_PLAN ORDER BY PLANLEVEL;

    Hi Jeff, using either give the same results. The query is "running", as is the little graphic with the bouncing gray bar is moving back and forth saying either "Query Results" or "Scriptrunner Task" as appropriate.
    OK this is odd. I run a count(*) on plan_table in SQL*Plus and get 4, in SQL Developer I get 487. Hun? That makes no sense I'm connect as the same user in each. Where are all these other entries coming from and why can't I see them in SQL Plus? Does SQL Developer have it's own PLAN_TABLE?
    **EDIT --- Yes that seems to be the case. The PLAN_ID I see in SQL Plus doesn't even exist in the SQL Deveropler version of the table. OK that's good to know. I assume the plan_table for SQL Developer is local to it somehow? It's not in the database as best I can see.
    Edited by: Ric Van Dyke on Feb 7, 2013 5:19 PM

  • With clause - subquery factoring

    I've got a script that looks like this:
    with X as (select * from atable)
    select x1.*, x2.*
    from X x1,
    X x2
    This works perfectly well in SQL*Plus, in PL/SQL, etc. Yet when I try to add it as "New Folder from Database" to an existing Business area in Discoverer, I get the infamous "ORA-03001 Unimplemented Feature".
    What am I doing wrong?
    Oracle 9i, Disco 9.0.4

    You're all gonna love this one.....
    The WITH clause works. But not easily.
    Go ahead, build the query, (as noted in a recent thread, I, too, always use views), set the grants and make sure DISCOVERER and EULOWNER have SELECT privs.
    1. Log into Disco Admin as EULOWNER. Trust me.
    2. Add the view as a folder to the business area.
    3. Log into Disco Desktop as EULOWNER. Don't laugh. It gets better.
    4. Build the workbook and the worksheet (or just the worksheet if apropos)
    5. Set the appropriate "sharing" roles and such
    6. Save the workbook to the database.
    7. Save the workbook to your computer.
    8. Log out of Desktop.
    9. Log back into Desktop as whatever, whoever you usually are to work.
    10. elect "open existing workbook"
    11. Select icon for "open from my computer". See? I told you it would get better!
    12. Open the save .dis file from your computer.
    13. Save it to the database.
    14. Open a web browser and from there, you're on your own.
    Fortran in VMS. Much easier and faster. I'm convinced the proliferation of the web is a detriment to the world at large...On the other hand, I'm also waiting for the Dodgers to return to Brooklyn.

  • Recursive subquery factoring datatypes?

    Hi all,
    using 11.2.0.2.0
    just mucking around with Recursive Subquery Factoring, trying to get my head around it.
    I can do this fine:
    SQL> with numlist (num) AS (SELECT 1 num
      2                          from dual
      3                          UNION ALL
      4                          SELECT numlist.num + 1
      5                            FROM numlist
      6                          where numlist.num < 10)
      7  SELECT *
      8    from numlist;
           NUM
             1
             2
             3
             4
             5
             6
             7
             8
             9
            10
    10 rows selected.but not with dates:
    SQL> WITH datelist (dte) AS (SELECT to_date('01-01-2011','dd-mm-yyyy') Dte
      2                   FROM dual
      3                 UNION ALL
      4                 SELECT datelist.dte + 1
      5                   FROM datelist
      6                  WHERE datelist.dte < trunc(SYSDATE))
      7  select *
      8    from datelist;
                   SELECT datelist.dte + 1
    ERROR at line 4:
    ORA-01790: expression must have same datatype as corresponding expressionI'm not sure what I need to do.....
    I'm sure it's a fairly straightforward

    Hemant K Chitale wrote:
    I don't have an 11.2.0 environment to test this.
    Try with a CAST at line 4 ? CAST X.DTE to a Date ?
    Hemant K Chitaleahh, that's a little bit better.... it seems a little bit funky though:
    15:38:58 SQL> WITH x (dte) AS (SELECT cast (to_date('01-01-2011','dd-mm-yyyy') as date) Dte
    15:39:02   2                   FROM dual
    15:39:02   3                 UNION ALL
    15:39:02   4                 SELECT cast(x.dte + 1 as date)
    15:39:02   5                   FROM x
    15:39:02   6                  WHERE x.dte < to_date('01-02-2011','dd-mm-yyyy'))
    15:39:02   7  select *
    15:39:02   8    from x;
    DTE
    01-JAN-11
    31-DEC-10
    30-DEC-10
    29-DEC-10
    28-DEC-10
    27-DEC-10
    26-DEC-10
    25-DEC-10
    24-DEC-10
    23-DEC-10
    22-DEC-10
    21-DEC-10
    20-DEC-10
    19-DEC-10
    18-DEC-10
    17-DEC-10
    16-DEC-10
    15-DEC-10
    14-DEC-10
    13-DEC-10
    12-DEC-10
    11-DEC-10
    10-DEC-10
    09-DEC-10
    08-DEC-10
    07-DEC-10
    06-DEC-10
    05-DEC-10
    04-DEC-10
    03-DEC-10
    02-DEC-10
    01-DEC-10
    30-NOV-10
    29-NOV-10
    28-NOV-10
    27-NOV-10
    26-NOV-10
    25-NOV-10
    24-NOV-10
    23-NOV-10
    22-NOV-10
    21-NOV-10
    20-NOV-10
    ...looks like it's going backwards.
    if I cast it like the below, it only gives me one record...
    15:39:03 SQL> WITH x (dte) AS (SELECT cast (to_date('01-01-2011','dd-mm-yyyy') as date) Dte
    15:40:52   2                   FROM dual
    15:40:52   3                 UNION ALL
    15:40:52   4                 SELECT cast(x.dte as date) + 1
    15:40:52   5                   FROM x
    15:40:52   6                  WHERE x.dte < to_date('01-02-2011','dd-mm-yyyy'))
    15:40:52   7  select *
    15:40:52   8    from x;
    DTE
    01-JAN-11
    1 row selected.This is bizarre....

  • How to use subquery factoring ("with" clause) in OWB?

    Hi,
    Is it possible to use subquery factoring (popularly known as "with" clause) in OWB 10gR2? I have a mapping with a splitter and union-all, which generates a query that has repeated scans of the same table. Subquery Factoring would be very useful here. I think this is a very common situation, so, I hope there's a way to achieve this. (If not in this version, this would be my wishlist item for the next version.)
    Appreciate your help.
    Regards,
    Rahul

    Hi Rahul,
    I'm afraid you have to put this on your wishlist. You may put the query with the "with"-clause into a view (or table function if you need parameters) if performance is too bad. But that is somehow against the idea (and benefits) of owb.
    Another possibility is to use a temporary table and spilt the mappings into two parts: first fill the temp table, then the target table.
    Regards,
    Carsten.

  • With clause of select (subquery factoring)

    I've got a script that looks like this:
    with X as (select * from atable)
    select x1.*, x2.*
    from X x1,
    X x2
    This works perfectly well in SQL*Plus, in PL/SQL, etc. Yet when I try to add it as "New Folder from Database" to an existing Business area in Discoverer, I get the infamous "ORA-03001 Unimplemented Feature".
    What am I doing wrong?
    Oracle 9i, Disco 9.0.4

    Hi,
    You will have to define a database view containing your query and load the view into your database. I don't think you can use subquery factoring in a custom folder.
    Rod West

  • WITH Subquery Factoring OR "Scalar SubqueriesRun Another Query per row

    Hi Experts
    Please suggest
    which one query is better
    Involved table p is of size 2GB and c1/c2 of size 800M.
    And we have to run a report on p which will do FTS (no where clause on p)
    So FTS on 2 GB table and then running Another Query per row .. so results job very slow
    1)  Select p.id,
             (select sum(q1) from c1 where c1.id = p.id) c1_sum1,
             (select sum(q2) from c2 where c2.id = p.id) c2_sum2
       from p
    2)
    WITH Subquery Factoring
    with c1_vw as
    (select id, sum(q1) c1_sum1
        from c1
             group by id),
       c2_vw as
       (select id, sum(q2) c2_sum2
           from c2
          group by id),
       c1_c2 as
       (select c1.id, c1.c1_sum1, c2.c2_sum2
           from c1_vw c1, c2_vw c2
          where c1.id = c2.id )
       select p.id, c1_sum1, c2_sum2
          from p, c1_c2
         where p.id = c1_c2.id
       / 10.2..0.4
    AIX 5.3
    Thanks In Advance
    ivw

    ivw wrote:
    which one query is betterThe better query IMHO is the one that returns the the correct results in the shortest amount of time using the least system resources (the last two items usually happen at the same time). Maintainability is an issue too. Which one do you like best?
    Its hard to say which query will run best without running both, getting execution plans, and run-time statistics. At a pure guess I would think all things being equal they would have similar performance but do not really know.

  • Cardinality estimator 2014 is off with OR in where clause

    Here is my test setup on SQL Server 2014.
    -- Create big table
    CREATE TABLE [dbo].[Store](
    Id int IDENTITY(1,1) NOT NULL,
    City int NOT NULL,
    Size int NOT NULL,
    Name varchar(max) NULL,
    CONSTRAINT [PK_Store] PRIMARY KEY CLUSTERED ([Id] ASC)
    GO
    CREATE NONCLUSTERED INDEX [IX_Store] ON [dbo].[Store] (City ASC, Size ASC)
    GO
    -- Fill with 100k rows
    INSERT Store
    SELECT i % 101, i % 11, 'Store ' + CAST(i AS VARCHAR)
    FROM
    (SELECT TOP 100000 ROW_NUMBER() OVER (ORDER BY s1.[object_id]) AS i
    FROM sys.all_objects s1, sys.all_objects s2) numbers
    GO
    -- Create small table
    CREATE TABLE #StoreRequest (City int NOT NULL, Size int NOT NULL)
    GO
    INSERT #StoreRequest values (55, 1)
    INSERT #StoreRequest values (66, 2)
    Now I execute the following query (I force the index to show statistics estimates)
    SELECT s.City
    FROM #StoreRequest AS r
    INNER JOIN Store AS s WITH(INDEX(IX_Store), FORCESEEK)
    ON s.City = r.City AND s.Size = r.Size
    WHERE s.Size <> 1 OR r.City <> 55
    Here are the estimates that I get (I'm not allowed to upload pictures):
    Index Seek IX_Store
    Actual Number of Rows: 90
    Estimated Number of Rows: 50000
    Fixing WHERE clause to use one table not two makes the estimate perfect:
    SELECT s.City
    FROM #StoreRequest AS r
    INNER JOIN Store AS s WITH(INDEX(IX_Store), FORCESEEK)
    ON s.City = r.City AND s.Size = r.Size
    WHERE s.Size <> 1 OR s.City <> 55
    Index Seek IX_Store
    Actual Number of Rows: 90
    Estimated Number of Rows: 89.74
    Switching to 2012 compatibility mode gives estimate of 1 in both cases:
    Index Seek IX_Store
    Actual Number of Rows: 90
    Estimated Number of Rows: 1
    Could anyone explain the first result? I'm a bit worried about it. The fix in this case is trivial, but this problem gave us quite some headache in more complex real life queries with multiple joins.
    Thank you!

    But not full statistics on a field basis, just sometimes some default stats like total row count that some plans will build.  Even your StoreRequest table only has one two-field index that will have a full histogram.
    But I've seen SQL Server make massively bad plans on two-field indexes.
    I've seen SQL Server go wrong one-column indexes, so that is not a very relevant point.
    Temp tables or not, the estimate here is clearly incorrect. SQL Server knows the density of Size and City. It knows the cardinality of the temp table. The density information gives how many rows the the join will produce. The WHERE clause will then remove
    a certain number of rows. With no statistics for the temp table, it does not now how many, but it will apply some standard guess.
    50000 is a completely bogus number, because the join cannot produce that many rows, and SQL Server is able to compute the join with out the WHERE clause decently. (Well, it estimates 90, when the number is 180.) No, this is obviously a case of the cardinality
    estimator giving up completely.
    It is worth noting that both these WHERE clauses gives reasonable estimates:
     WHERE r.Size <> 11 OR r.City <> 550
     WHERE s.Size <> 11 OR s.City <> 550
    Whereas these two gives the spooky 50000:
     WHERE s.Size <> 11 OR r.City <> 550
     WHERE r.Size <> 11 OR s.City <> 550
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Having with more than one clause

    Hi
    Is posssible to have a query with more than one clause in having condition
    Example In my query I have Count , Sum and AVG , I need to use 3 conditions in having, Is It possible ?
    Thank you in advance

    Hi,
    yes, in Having you can also use AND and OR.
    with x as (select 1 nr from dual)
    select nr
    from x
    group by nr
    having count(*) = 1
    and sum(nr) = 1Herald ten Dam
    http://htendam.wordpress.com

  • Prepared Statement with "INTERVAL ? DAY" clause

    Hi,
    I am having problems when using a INTERVAL ? DAY clause in a
    preparedStatement in Oracle 8i with the classes12.zip jdbc
    driver.
    The code following code:
    String sql1 =
    "select from my_table where created_ts > SYSDATE -
    INTERVAL '10' DAY";
    String sql2 =
    "select from my_table where created_ts > SYSDATE -
    INTERVAL '?' DAY";
    String sql3 =
    "select from my_table where created_ts > SYSDATE -
    INTERVAL ? DAY";
    try {
    st = con.prepareStatement(sql1);
    ResultSet rs = st.executeQuery();
    System.out.println("1 successful");
    catch (Exception e) {
    System.err.println(e);
    try {
    st = con.prepareStatement(sql2);
    st.setInt(1, 10);
    ResultSet rs = st.executeQuery();
    System.out.println("2 successful");
    catch (Exception e) {
    System.err.println(e);
    try {
    st = con.prepareStatement(sql3);
    st.setInt(1, 10);
    ResultSet rs = st.executeQuery();
    System.out.println("3 successful");
    catch (Exception e) {
    System.err.println(e);
    produces this output:
    1 successful
    java.sql.SQLException: ORA-01036: illegal variable name/number
    java.sql.SQLException: ORA-00933: SQL command not properly ended
    Can anybody help me figuring out what's wrong with the 2nd or
    3rd prepared statement?
    Thanks
    Bernie

    Hi,
    I am having problems when using a INTERVAL ? DAY clause in a
    preparedStatement in Oracle 8i with the classes12.zip jdbc
    driver.
    The code following code:
    String sql1 =
    "select from my_table where created_ts > SYSDATE -
    INTERVAL '10' DAY";
    String sql2 =
    "select from my_table where created_ts > SYSDATE -
    INTERVAL '?' DAY";
    String sql3 =
    "select from my_table where created_ts > SYSDATE -
    INTERVAL ? DAY";
    try {
    st = con.prepareStatement(sql1);
    ResultSet rs = st.executeQuery();
    System.out.println("1 successful");
    catch (Exception e) {
    System.err.println(e);
    try {
    st = con.prepareStatement(sql2);
    st.setInt(1, 10);
    ResultSet rs = st.executeQuery();
    System.out.println("2 successful");
    catch (Exception e) {
    System.err.println(e);
    try {
    st = con.prepareStatement(sql3);
    st.setInt(1, 10);
    ResultSet rs = st.executeQuery();
    System.out.println("3 successful");
    catch (Exception e) {
    System.err.println(e);
    produces this output:
    1 successful
    java.sql.SQLException: ORA-01036: illegal variable name/number
    java.sql.SQLException: ORA-00933: SQL command not properly ended
    Can anybody help me figuring out what's wrong with the 2nd or
    3rd prepared statement?
    Thanks
    Bernie

  • Select Clause Subquery

    Does anyone know how to do this in Discoverer?
    The subquery feature on the conditions tab is a From Clause Subquery. Here is an example of a query I am trying to duplicate in Discoverer.
    SELECT c.rep_name_master, s.fiscal_year, s.fiscal_month, s.product_summary, sum(s.sum_sales), (SELECT sum(b.budgeted_net_sales)
    FROM weekly_rep_budget b
    WHERE b.rep_name_master = 'IS305'
    and b.product_summary = 'Book'
    and b.fiscal_month = 'July'
    and b.fiscal_year = '2006') as budget
    FROM dwadmin.weekly_shipto_sales_sum s, dwadmin.customer_rep_master_mv c, weekly_rep_budget b
    WHERE c.rep_name_master = 'IS305'
    and b.product_summary = 'Book'
    and b.fiscal_month = 'July'
    and b.fiscal_year = '2006'
    and s.customer_gk=c.customer_gk
    and b.fiscal_year=s.fiscal_year
    and b.fiscal_month=s.fiscal_month
    and b.fiscal_week=s.fiscal_week
    and b.product_summary=s.product_summary
    and b.rep_name_master=c.rep_name_master
    GROUP BY c.rep_name_master, s.fiscal_year, s.fiscal_month, s.product_summary, b.budgeted_net_sales
    Thanks,
    Dave

    weekly_rep_budget                         
    product_summary     fiscal_week     fiscal_month     fiscal_year     budgeted_net_sales     rep_name_master
    Book     1     August     2006     13     IS305
    Book     2     August     2006     13     IS305
    Book     3     August     2006     13     IS305
    Book     4     August     2006     13     IS305
    product_summary     fiscal_week     fiscal_month     fiscal_year     weekly_shipto_sales_sum     customer.gk
    Book     1     August     2006     5     12275722
    Book     1     August     2006     6     12275723
    Book     1     August     2006     7     12275724
    Book     1     August     2006     8     12275725
    Book     1     August     2006     9     12275726
    Book     1     August     2006     10     12275727
    Book     2     August     2006     11     12275729
    Book     2     August     2006     12     12275732
    Book     2     August     2006     13     12275735
    Book     2     August     2006     14     12275741
    Book     2     August     2006     15     12275744
    Book     2     August     2006     16     12275747
    Book     3     August     2006     17     12275753
    Book     3     August     2006     18     12275787
    Book     3     August     2006     19     12275793
    Book     3     August     2006     20     12275803
    Book     3     August     2006     21     12275806
    Book     4     August     2006     22     12275816
    Book     4     August     2006     23     12275819
    Book     4     August     2006     24     12275822
    Book     4     August     2006     25     12275825
    Book     4     August     2006     26     12275828
    Book     4     August     2006     27     12275831
    customer_rep_master_mv                         
    customer_gk     rep_name_master                    
    12275722     IS305                    
    12275723     IS305                    
    12275724     IS305                    
    12275725     IS305                    
    12275726     IS305                    
    12275727     IS305                    
    12275729     IS305                    
    12275732     IS305                    
    12275735     IS305                    
    12275741     IS305                    
    12275744     IS305
    12275747     IS305
    12275753     IS305
    12275787     IS305
    12275793     IS305
    12275803     IS305
    12275806     IS305
    12275816     IS305
    12275819     IS305
    12275822     IS305
    12275825     IS305
    12275828     IS305
    12275831     IS305
    I can get the following:     
    product_summary     fiscal_week     fiscal_month     fiscal_year     weekly_shipto_sales_sum     budgeted_net_sales     rep_name_master
    Book     1     August     2006     45     13     IS305
    Book     2     August     2006     81     13     IS305
    Book     3     August     2006     95     13     IS305
    Book     4     August     2006     147     13     IS305
    I cannot get this:                              
    product_summary          fiscal_month     fiscal_year     weekly_shipto_sales_sum     budgeted_net_sales     rep_name_master
    Book          August     2006     368     52     IS305

  • On success of form save I want to go to another for with a detail where clause

    I have the follow code snippet which is intented to go to a form on a successfull save. I query some data based on the save then build a url to navigate to a new form. I want the form to show only data that is lacking in one column not being populated (column is null). The url works, but the form detail where clause is ignored. Does anyone have any experience with passing detail where clauses to a form? Did I miss something in the code below?
    begin
    select count(rl_id) into n_rl_id_cnt
    from rfq_lines
    where part_part_id is null and rh_rh_id=n_rh_id;
    exception
    when others then
    null;
    end;
    htp.p('cnt '||to_char(n_rl_id_cnt));
    if n_rl_id_cnt>0 then
    htp.p('cnt >1');
    my_url := 'PORTAL30.wwa_app_module.link?' ||
    'p_arg_names=_moduleid&p_arg_values=3677858481' ||
    '&p_arg_names=_show_header&p_arg_values=YES' ||
    '&p_arg_names=rh_id&p_arg_values=' || LTRIM(TO_CHAR(n_rh_id)) ||
    '&p_arg_names=_rh_id_cond&p_arg_values=%3D'||
    '&p_arg_names=_detail_where_clause&p_arg_values=part_part_id%20is%20null'; -- <this is not working right. where clause is ignored.
    htp.p(my_url);
    go (my_url);

    Hi Jeffrey ,
    You need to use a custom Format script for the field.
    Regards
    Sukrit Dhingra

  • Create a view with a changing where clause

    Hi all,
    i'm developing an application with oracle forms i want to create a view in the database with a different where clause in every time , the where clause is determined due to the department id of the current user .
    thanks alot.

    SQL> create view emp_view as select empno, ename, deptno from emp;
    View created.
    SQL> select * from emp_view where deptno = 10;
         EMPNO ENAME          DEPTNO
          7782 CLARK              10
          7839 KING               10
          7934 MILLER             10
    SQL>

  • SELECT FOR UPDATE with the SKIP LOCK clause

    Hi,
    I have a query regarding the SELECT FOR UPDATE with the SKIP LOCK clause.
    Whether this will be really good for parallel processing.
    Also if we are selecting a set of records in a cursor whether the lock will be done at the records level once we fetch the records?
    Also do we have any known issues with this one?
    We are trying to figure out whether this will fit for business requirement, we are trying to do a implement a threading kind of thing for our stored procedure invocation in background using shell script.
    Any suggestion or feedback on this will be helpful for us.
    Thanks a lot for the support given....
    Regards,
    Basil Abraham.

    http://www.oracle.com/technology/oramag/oracle/08-mar/o28plsql.html
    Please read the above thread for few information...Thanks!

Maybe you are looking for

  • Windows 8 Phones not welcome

    Verizon's support of Windows phone is below satisfactory.  Phone selection is poor, little to no accessories in store and customer service reps that will almost fight you not to buy a Windows phone in favor of Apple or Android.  I've owned both, both

  • Adding Members to Planning Data Forms

    <p>I have a form with Periods as the column. If I have threemembers chosen all is fine. If I add a fourth member of Period, theform won't display. I have checked and have write access and allelse looks fine.</p>

  • My Ipod Updater doesn't recognize my Ipod nano

    Yes, everytime i try to hook up my ipod nano or start up my ipod updater, the ipod updater says "Ipod Service Error!". From there I have no clue what to do. I've done everything that has been asked i've restarted the ipod, put it in disk mode, change

  • Sorting Currency conversion Variables in Query Selection screen

    Hi Experts, I have an issue in sorting variables. A Currency translation is used here which has two selection options here, one for "Currency" and one for "Currency conversion date". They just pop in somewhere in the selection screen with out order.

  • Videos stop and start

    I've got a fast computer w/plenty of ram. I can watch videos from all other sources perfectly smooth, including Quicktime HD movie trailers. When I try to watch a video in iTunes it slows my computer down so much that besides the videos stopping and