Count all values with a special WHERE clause in a select for a group?

Hello,
I have the following table1:
code, month, value
*1,1,40*
*1,2,50*
*1,3,0*
*1,4,0*
*1,5,20*
*1,6,30*
*1,7,30*
*1,8,30*
*1,9,20*
*1,10,20*
*1,11,0*
*1,12,0*
*2,1,10*
*2,2,10*
*2,3,20*
*2,4,20*
*2,5,20*
*2,6,30*
*2,7,40*
*2,8,50*
*2,9,20*
*2,10,20*
*2,11,20*
*2,12,20*
This is a table with 3 columns, first column is a code, second one is the number of month, third one is a value.
Now I want to select the records for each code. For example all records for code=1.
I want to count how much values=0 for this code=1. After this counting I want to update the value with this count of 0.
For my example:
For code 1 there are 4 fields with value 0. Therefore I want to update all values of code1 to 4.
For the second code=2 there are no value=0. Therefore I want to update the values of code2 to 0.
This should be the result:
code, month, value
*1,1,4*
*1,2,4*
*1,3,4*
*1,4,4*
*1,5,4*
*1,6,4*
*1,7,4*
*1,8,4*
*1,9,4*
*1,10,4*
*1,11,4*
*1,12,4*
*2,1,0*
*2,2,0*
*2,3,0*
*2,4,0*
*2,5,0*
*2,6,0*
*2,7,0*
*2,8,0*
*2,9,0*
*2,10,0*
*2,11,0*
*2,12,0*
My question is:
Is there any possibility in oracle to count in a select (or in a insert/update statement) all values=0 for one group (in this example named CODE) and do an update in the same statement for this group?
Hope anyone can give me a hint if this is possible?
Thanks a lot.
Best regards,
Tim

Here's the select:
SQL> select code, month
  2        ,count(decode(value,0,1,null)) over (partition by code) ct
  3  from   t
  4  order by code, month
  5  ;
                CODE                MONTH                   CT
                   1                    1                    4
                   1                    2                    4
                   1                    3                    4
                   1                    4                    4
                   1                    5                    4
                   1                    6                    4
                   1                    7                    4
                   1                    8                    4
                   1                    9                    4
                   1                   10                    4
                   1                   11                    4
                   1                   12                    4
                   2                    1                    0
                   2                    2                    0
                   2                    3                    0
                   2                    4                    0
                   2                    5                    0
                   2                    6                    0
                   2                    7                    0
                   2                    8                    0
                   2                    9                    0
                   2                   10                    0
                   2                   11                    0
                   2                   12                    0

Similar Messages

  • 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]

  • Parsing an input parameter for the where clause or record select value

    In my limited CR experience, I've always used a command database connection so that I can write my own SQL.  However, now I have to parse a  pipe delimited parameter to get my value for the where clause, so I'm selecting several tables and joining them through the Database Expert Links tab.  All works fine, but after doing that and then parsing the parameter with the below formula in the Select Expert, I notice that there is no where clause in the SQL query, and although the report eventually displays the proper values, it runs through thousands of records first.  Here is my Select Expert - Record formula:
    StringVar array Parm1;
    Parm1 := Split({?DATA_AREA}, "|");
    {SO_ORDERS.CASE_ID} = Parm1[2]
    If I change "Parm1[2]" on the last line to a valid Case ID, then there is a where clause in the SQL and the report generates immediately. 
    It seems like the record select formula is applied AFTER all of the records (without a where clause) are searched when I use the parsed parameter value, but when I hard code a valid value, it places that into the where clause BEFORE the sql is executed.  Is there a way to get the parameter parsed first and then use that parsed value in the SQL where clause?
    Thanks.
    Bill

    Yes crystal will run the query first to get 100% data and then applies record selection condition. To increase the performance you need to pass the where condition at the command level instead of report level. So you need to create a report using add command like this
    select * from tablename where field={?Parameter}
    {?Parameter} is a command level parameter.
    Now insert this report as a subreport in another report which has no connection but has a parameter
    {?DATA_AREA} and create a formula like this in the main report
    Split({?DATA_AREA}, "|")[2]
    Now right click on the subreport and go to change subreport links and add this formula from main report and link this to sub report parameter {?Parameter} without linking any database field from the subreport.
    Now your subreport runs with the where clause to get the data.
    Regards,
    Raghavendra

  • 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>

  • Define a Standalone Download Integrator with an Additional Where clause - SQL error

    Hi,
    I am trying to create a standalone integrator with an Additional Where clause. Followed the steps mentioned in the metalink note 360105.1. When I run the integrator, I get the following error message.
    Please resolve the following error to continue.
    SQL error: ORA-00936: missing expression occurred
    processing stored SQL for Content 20007:GENERAL_441_CNT.
    When I look at the log file, here is what I can see:
    10/22/14 10:50 AM AJPRequestHandler-HTTPThreadGroup-15 TRACE          BneHrSQLControl - SQL:SELECT  FROM PER_PEOPLE_V where last_name=$PARAM$.last_name
    10/22/14 10:50 AM AJPRequestHandler-HTTPThreadGroup-15 TRACE          validateSQLStatement value of sqlStatement is: SELECT  FROM PER_PEOPLE_V where last_name=:RSQLP1
    10/22/14 10:50 AM AJPRequestHandler-HTTPThreadGroup-15 DETAIL         BneHrSQLControl.validateSQLStatement() paramName: last_name
    10/22/14 10:50 AM AJPRequestHandler-HTTPThreadGroup-15 DETAIL         BneHrSQLControl.validateSQLStatement() error in SQL: java.sql.SQLSyntaxErrorException: ORA-00936: missing expression
    So, clearly, the SQL statement that is getting built internally is wrong. Ideally, I would expect the statement to be something like this:
    SELECT *  FROM PER_PEOPLE_V where last_name=$PARAM$.last_name.
    RDBMS : 11.2.0.3.0
    Oracle Applications : 12.1.3
    Any pointers towards the resolution of the issue would be of great help.
    Thanks in Advance!
    Lalitha.

    This is a duplicate post of your other question:  create trigger automatic
    DO NOT start duplicate threads for the same question.
    Locking this thread

  • Values from a Multi-Select in the where clause of a Select statement

    I have a web page that solicits query parameters from the user.
    The selections that the user makes will populate the WHERE clause of a Select statement.
    One of the controls on the page is a multi-select control.
    When this page posts, I would like to execute a Select statement wherein the selected values from this control appear in the .. Column IN ( <list here> ) portion of the WHERE clause.
    This is an extremely common scenario, but I cannot seem to locate a how-to or message thread that addresses this specific case.
    I have an idea that it may involve dynamic SQL or Execute Immediate, but cannot seem to pin down the answer.
    Any help would be greatly appreciated!

    anonymous - As illustrated here: Re: Search on a typed in list of values
    Scott

  • Why is it that on a 5s you can by pass all security measures via Siri, where as the 4S asks for an unlock?

    On a 5s you can by pass all security measures via Siri, where as the 4S asks for an unlock.  Why?

    My daughter has had her Razr for about 9 months now.  About two weeks ago she picked up her phone in the morning on her way to school when she noticed two cracks, both starting at the camera lens. One goes completely to the bottom and the other goes sharply to the side. She has never dropped it and me and my husband went over it with a fine tooth comb. We looked under a magnifying glass and could no find any reason for the glass to crack. Not one ding, scratch or bang. Our daughter really takes good care of her stuff, but we still wanted to make sure before we sent it in for repairs. Well we did and we got a reply from Motorola with a picture of the cracks saying this was customer abuse and that it is not covered under warranty. Even though they did not find any physical damage to back it up. Well I e-mailed them back and told them I did a little research and found pages of people having the same problems. Well I did not hear from them until I received a notice from Fed Ex that they were sending the phone back. NOT FIXED!!! I went to look up why and guess what there is no case open any more for the phone. It has been wiped clean. I put in the RMA # it comes back not found, I put in the ID #, the SN# and all comes back not found. Yet a day earlier all the info was there. I know there is a lot more people like me and all of you, but they just don't want to be bothered so they pay to have it fix, just to have it do it again. Unless they have found the problem and only fixing it on a customer pay only set up. I am furious and will not be recommending this phone to anyone. And to think I was considering this phone for my next up grade! NOT!!!!

  • Call a function in a where clause of a select

    hello,
    is it possible to call a function in a where clause of a select????
    ex: select col1, col2
    from my_table
    where my_package.my_function(32199, 2008, col3, 'P');
    and i have error message "ORA-00920: invalid relational operator"
    FUNCTION my_function(v_matricule IN NUMBER,
              v_Year IN NUMBER,
              v_date IN DATE,
              v_type IN CHAR DEFAULT 'P')
    RETURN BOOLEAN;
    @+Rosagio

    user10225229 wrote:
    hello,
    is it possible to call a function in a where clause of a select????
    ex: select col1, col2
    from my_table
    where my_package.my_function(32199, 2008, col3, 'P');
    and i have error message "ORA-00920: invalid relational operator"
    FUNCTION my_function(v_matricule IN NUMBER,
              v_Year IN NUMBER,
              v_date IN DATE,
              v_type IN CHAR DEFAULT 'P')
    RETURN BOOLEAN;You can call a function if it returns a datatype that is supported by SQL. BOOLEAN is NOT supported by SQL.

  • Hi all, Please suggest a case where there is a requirement for new SOAP sender adapter module. I wanted to develop a module but in my current project i am unable to find any such requirement.

    Hi all, Please suggest a case where there is a requirement for new SOAP sender adapter module. I wanted to develop a module but in my current project i am unable to find any such requirement. So please give me inputs for the same..
    Thank you,
    Vinay Kumar A

    You can try converting a synchrnous soap call to asynchronous using a custom module
    Here your module will send a response back to the sender system and make an asynchronous call forward

  • Performance - composite index with 'OR' in 'WHERE' clause

    I have a problem with the performance of the following query:
    select /*+ index_asc(omschact oma_index1) */ knr, projnr, actnr from omschact where ((knr = 100 and actnr > 30) or knr > 100)
    and rownum = 1;
    (rownum used only for test purpose)
    index:
    create index on omschact (knr, projnr);
    Execution plan:
    Id Operation
    0 SELECT STATEMENT
    1 COUNT STOPKEY
    2 TABLE ACCESS BY INDEX ROWID
    3 INDEX FULL SCAN
    If I'm correct, the 'OR' in the 'WHERE' clause is responsible for the INDEX FULL SCAN, what makes the query slow.
    A solution would be then to separate the 'WHERE' clause in 2 separate select's (1 with 'knr = 100 and actnr > 30' and 1 with 'knr > 100' and combine the results with a UNION ALL.
    Since it's necessary to have all rows in ascending order (oma_index1) I still have to use an ORDER BY to make sure the order of the rows is correct. This results again in a (too) low performance.
    Another solution that does the trick is to create an index with the 2 fields (knr, projnr) concatenated and to use the same in the 'WHERE' clause:
    create index oma_index2 on omschact (knr || projnr);
    select /*+ index_asc(omschact oma_index2) */ knr, projnr, actnr from omschact where (knr || projnr) > 10030;
    I just can't believe this work-around is the only solution, so I was hoping that someone here knows of a better way to solve this.

    padders,
    I'll give the real data instead of the example. The index I really use consists of 4 fields. In this table the fields are just numbers, but in other tables I need to use char-fields in indexes, so that's why I concatenate instead of using formula's (allthough I would prefer the latter).
    SQL> desc omschact
    Name Null? Type
    KNR NOT NULL NUMBER(8)
    PROJNR NOT NULL NUMBER(8)
    ACTNR NOT NULL NUMBER(8)
    REGELNR NOT NULL NUMBER(3)
    REGEL CHAR(60)
    first methode:
    SQL> create index oma_key_001(knr,projnr,actnr,regelnr);
    Index created.
    SQL> select /*+ index_asc(omschact oma_key_001) */ * from omschact where
    2 (knr > 100 or
    3 (knr = 100 and projnr > 30) or
    4 (knr = 100 and projnr = 30 and actnr > 100000) or
    5 (knr = 100 and projnr = 30 and actnr = 100000 and regelnr >= 0));
    Execution Plan
    Plan hash value: 1117430516
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 11M| 822M| 192K (1)| 00:38:26 |
    | 1 | TABLE ACCESS BY INDEX ROWID| OMSCHACT | 11M| 822M| 192K (1)| 00:38:26 |
    |* 2 | INDEX FULL SCAN | OMA_KEY_001 | 11M| | 34030 (1)| 00:06:49 |
    Predicate Information (identified by operation id):
    2 - filter("KNR">100 OR "KNR"=100 AND "PROJNR">30 OR "KNR"=100 AND "PROJNR"=30
    AND "ACTNR">100000 OR "ACTNR"=100000 AND "KNR"=100 AND "PROJNR"=30 AND
    "REGELNR">=0)
    second method (same index):
    SQL> select * from (
    2 select /*+ index_asc(omschact oma_key_001) */ * from omschact where knr > 100
    3 union all
    4 select /*+ index_asc(omschact oma_key_001) */ * from omschact where knr = 100 and projnr > 30
    5 union all
    6 select /*+ index_asc(omschact oma_key_001) */ * from omschact where knr = 100 and projnr = 30 and actnr > 100000
    7 union all
    8 select /*+ index_asc(omschact oma_key_001) */ * from omschact where knr = 100 and projnr = 30 and actnr = 100000 and regelnr > 0)
    9 order by knr, projnr, actnr, regelnr;
    Execution Plan
    Plan hash value: 292918786
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 11M| 1203M| | 477K (1)| 01:35:31 |
    | 1 | SORT ORDER BY | | 11M| 1203M| 2745M| 477K (1)| 01:35:31 |
    | 2 | VIEW | | 11M| 1203M| | 192K (1)| 00:38:29 |
    | 3 | UNION-ALL | | | | | | |
    | 4 | TABLE ACCESS BY INDEX ROWID| OMSCHACT | 11M| 822M| | 192K (1)| 00:38:26 |
    |* 5 | INDEX RANGE SCAN | OMA_KEY_001 | 11M| | | 33966 (1)| 00:06:48 |
    | 6 | TABLE ACCESS BY INDEX ROWID| OMSCHACT | 16705 | 1272K| | 294 (1)| 00:00:04 |
    |* 7 | INDEX RANGE SCAN | OMA_KEY_001 | 16705 | | | 54 (0)| 00:00:01 |
    | 8 | TABLE ACCESS BY INDEX ROWID| OMSCHACT | 47 | 3666 | | 4 (0)| 00:00:01 |
    |* 9 | INDEX RANGE SCAN | OMA_KEY_001 | 47 | | | 3 (0)| 00:00:01 |
    | 10 | TABLE ACCESS BY INDEX ROWID| OMSCHACT | 1 | 78 | | 4 (0)| 00:00:01 |
    |* 11 | INDEX RANGE SCAN | OMA_KEY_001 | 1 | | | 3 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    5 - access("KNR">100)
    7 - access("KNR"=100 AND "PROJNR">30)
    9 - access("KNR"=100 AND "PROJNR"=30 AND "ACTNR">100000)
    11 - access("KNR"=100 AND "PROJNR"=30 AND "ACTNR"=100000 AND "REGELNR">0)
    third method:
    SQL> create index oma_test(to_char(knr,'00000000')||to_char(projnr,'00000000')||to_char(actnr,'00000000')||to_char(regelnr,'000'));
    Index created.
    SQL> select /*+ index_asc(omschact oma_test) */ * from omschact where
    2 (to_char(knr,'00000000')||to_char(projnr,'00000000')||
    3 to_char(actnr,'00000000')||to_char(regelnr,'000')) >=
    4 (to_char(100,'00000000')||to_char(30,'00000000')||
    5* to_char(100000,'00000000')||to_char(0,'000'))
    Execution Plan
    Plan hash value: 424961364
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 553K| 55M| 1712 (1)| 00:00:21 |
    | 1 | TABLE ACCESS BY INDEX ROWID| OMSCHACT | 553K| 55M| 1712 (1)| 00:00:21 |
    |* 2 | INDEX RANGE SCAN | OMA_TEST | 99543 | | 605 (1)| 00:00:08 |
    Predicate Information (identified by operation id):
    2 - access(TO_CHAR("KNR",'00000000')||TO_CHAR("PROJNR",'00000000')||TO_CHAR("
    ACTNR",'00000000')||TO_CHAR("REGELNR",'000')>=TO_CHAR(100,'00000000')||TO_CHAR(3
    0,'00000000')||TO_CHAR(100000,'00000000')||TO_CHAR(0,'000'))

  • Trouble with OR in where clause

    Hello,
    I'm having trouble with execution speed. The problem seems to be with using OR in my where clause.
    Here's the meat of the function where i_pledge_number is an input parm:
    BEGIN
    SELECT /*+ INDEX (pp) */ SUM(pp.prim_pledge_amount)
    INTO return_amount
    FROM
    primary_pledge pp
    WHERE
    -- Get total if multiple allocations
    pp.prim_pledge_number IN
    (SELECT pc.pledge_number
    FROM pledge_codes pc
    WHERE pc.pledge_code_type = 'M'
    AND pc.pledge_code = 'AC'
    AND lpad(pc.pledge_comment,10,'0') = i_pledge_number)
    -- Get total if single allocation
    OR pp.prim_pledge_number = i_pledge_number;
    RETURN return_amount;
    END;
    If I comment out either half of the OR statement (either the subquery or the pp.prim_pledge_number = i_pledge_number half) the function returns a value in .02 seconds. If I leave the OR in, it takes 2.764 seconds to execute?? Can someone please show me a better way (faster) to do this? I tried using nvl() around the subquery but couldn't get it to compile.
    Thanks

    These things are difficult to diagnose remotely, but here is something you can try....
    SELECT */ SUM(pp.prim_pledge_amount)
    INTO return_amount
    FROM   primary_pledge pp
    WHERE  pp.prim_pledge_number IN (SELECT pc.pledge_number
                                     FROM pledge_codes pc
                                     WHERE pc.pledge_code_type = 'M'
                                     AND pc.pledge_code = 'AC'
                                     AND lpad(pc.pledge_comment,10,'0') = i_pledge_number
    UNION ALL
    SELECT i_pledge_number FROM dual)
       RETURN return_amount;
    END;If that doesn't do anything (and it might well not) there are a large number of different ways we can recast this query. To save us further guessing please give us more details: execution plans, database version number, volumetrics.
    Cheers, APC

  • Problem with SYS_CONTEXT in WHERE clause in 10g

    I am running the following SELECT statement in 9i and 10g
    SELECT COUNT(*)
    FROM mapinfo.mapinfo_mapcatalog
    WHERE tablename IN ('ESU_GRAPHICS', 'STREETS', 'ASD_STREETS', 'NSG_ARCHIVE_ESU_GRAPHICS')
    AND ownername = sys_context('USERENV','CURRENT_SCHEMA');
    When running in 9i it returns 4, the correct answer, but in 10g it always returns 0. I have tried populating a variable with the result from sys_context('USERENV','CURRENT_SCHEMA') such as:
    SELECT sys_context('USERENV','CURRENT_SCHEMA')
    INTO currentschema
    FROM dual;
    I have checked the variable and it is giving me the correct result in 10g, but I still get 0 returned from the select statement.
    What am I missing to get this working in 10g?
    Cheers
    Sean

    - Does the value for CURRENT_SCHEMA actually match
    the ownername column for the tables in your IN
    clause? Yes
    >
    - Is there anything different between 9i and 10g?
    E.g. did you have any fine grained access control?Not that I know of, but I am not a DBA so I could not say for sure.
    Were you setting CURRENT_SCHEMA with an ALTER SESSION
    statement in 9i that you have missed in your 10g
    environment?No we do not use any ALTER SESSION statements.
    >
    - What do you get if you run the following?
    select user from dual;
    select sys_context('USERENV','CURRENT_SCHEMA') from
    dual;
    Exactly the same result
    >
    - What do you get if you run the following?
    SELECT tablename, ownername FROM
    mapinfo.mapinfo_mapcatalog
    WHERE tablename IN ('ESU_GRAPHICS', 'STREETS',
    'ASD_STREETS', 'NSG_ARCHIVE_ESU_GRAPHICS');
    380 rows of data including the 4 that I am interested in
    - Can you also show the value of your variable when
    you use a SELECT INTO in PL/SQL... Were you using
    uppercase for USERENV and CURRENT_SCHEMA in PL/SQL
    (there was an incorrect results bug when using
    lowercase attributes in PL/SQL SYS_CONTEXT calls)?I am showing the value of the variable and it is holding the correct value, and yes I am using uppercase USERENV and CURRENT_SCHEMA.
    After more investigation it looks like it is not SYS_CONTEXT, it is using a variable in the WHERE clause. If I set the variable to a hard coded value I still get the same result. If I replace the variable for a hard-coded string in the WHERE clause I get the correct result.

  • Group by with and without where clause

    Do I need to use these two inner views to show results by group by as one line? Can I achieve the same result without typing the same select statement two times since these two SELECT statements differ only in where clause. This query is a simulation. My actual query is longer. My expectation is to make this query shorter (without inner views).
    with tmp as (
    select 'COMPLETE' status, 'GERMANY' country, 0 substatus FROM dual UNION ALL
    select 'COMPLETE' status, 'GERMANY' country, 1 substatus FROM dual UNION ALL
    select 'COMPLETE' status, 'GERMANY' country, 0 substatus FROM dual)
    select v1.status, v1.country, v1.cnt01, v2.cntIncluding0 from
    (select status, country, count(*) cnt01 from tmp tmp1 group by status, country) v1
    JOIN
    (select status, country, count(*) cntIncluding0 from tmp tmp2 where substatus=0 group by status, country) v2
    on v1.status=v2.status and v1.country=v2.country;

    totalnewby wrote:
    Do I need to use these two inner views to show results by group by as one line? Can I achieve the same result without typing the same select statement two times since these two SELECT statements differ only in where clause. This query is a simulation. My actual query is longer. My expectation is to make this query shorter (without inner views).
    with tmp as (
    select 'COMPLETE' status, 'GERMANY' country, 0 substatus FROM dual UNION ALL
    select 'COMPLETE' status, 'GERMANY' country, 1 substatus FROM dual UNION ALL
    select 'COMPLETE' status, 'GERMANY' country, 0 substatus FROM dual)
    select v1.status, v1.country, v1.cnt01, v2.cntIncluding0 from
    (select status, country, count(*) cnt01 from tmp tmp1 group by status, country) v1
    JOIN
    (select status, country, count(*) cntIncluding0 from tmp tmp2 where substatus=0 group by status, country) v2
    on v1.status=v2.status and v1.country=v2.country;
    SQL> with tmp as
      2  (
      3  select 'COMPLETE' status, 'GERMANY' country, 0 substatus FROM dual UNION ALL
      4  select 'COMPLETE' status, 'GERMANY' country, 1 substatus FROM dual UNION ALL
      5  select 'COMPLETE' status, 'GERMANY' country, 0 substatus FROM dual
      6  )
      7  select status,
      8         country,
      9         count(substatus) cnt01,
    10         sum(decode(substatus, 0, 1, 0)) cntincluding0
    11    from tmp
    12   group by status, country
    13  ;
    STATUS   COUNTRY      CNT01 CNTINCLUDING0
    COMPLETE GERMANY          3             2

  • Pagination after executequery with a dynamic where clause

    Hi all,
    I have a problem with pagination after setting a where clause dynamically and performing an executequery in ViewObjectImpl.java.
    As a result of this, the amount of records are decreased returned by the viewobject, however the pagination is not changed. It still reflects the previous amount. It changes only if you have selected the last range of the changed recordset
    Does anybody know how to get the pagination to refect the correct amount of the updated recordset of the viewobject?
    Jdeveloper version 10.1.3.4 / Jheadstart 10.1.3.3.81
    Thanks in advance, Erwin

    Hi,
    I would not add this to the VO query. Instead I would create a View Criteria that uses a bind variable. Then in the Application Module Data Model, you select the VO instance and choose edit (button on top) to permanently associate the view criteria)
    Advantages of this approach
    - The VO definition can be used elsewhere without the restriction
    - the bind variable is not mandatory and yu can set it such that if no value is provided a full query is executed
    Frank

Maybe you are looking for

  • Net receivable problem in sales order.

    Dear gurus I have a requirement where client wishes to show the net receivable from the price only. For example right now as is it seems net value is grabbing the value from the total value. qty                       Net Value 1,010 Example: Pr00 is

  • Match Records Error

    Hi Sdners, I am facing some problem in the match records process in the import manager. After I map the fields when I add the display fields in the matching fields as a combination , the process continous for a particular time period after which it s

  • Oracle9i Personal Edition for Microsoft Windows 98 cd pack

    Hello to everybody, would you be so kind to write me , how I can obtain ' Oracle9i Personal Edition for Microsoft Windows 98' on CDs for learning purpose ? Thanks and regards

  • PlugIn - status pending

    Deployed a custom built Plug-In.. It seems to be collecting the data correctly and displays the data, but its showing "Status Pending" in OEM. Any reason when is this message displayed..and how to troubleshoot... Thank you

  • What is the best format/codec to save a video edited in FCP7 for a DVD??

    I am trying to make a DVD from a video I've edited in FCP7. I am not using the correct codec and, I think, making the file too big. The details of my set up are in these two screen shots. This has happend in the past but I do not know what it is I am