Query with rownum

Here's a tricky one that has stumped me. I have two queries below :
The first query should list me records ordered by apxl_log_id field desc(first 50).
The second query should list me records ordered by apxl_log_id field desc(first 100). The only difference is in the number of records retrieved.
In other words, all 50 records in the first query should be there in the second query results as well !! because i am ordering it in descending order of apxl_log_id field.
However, The first query gives me starting with 2268 whereas the other one starts with 2283. My questions is, where are the records in the second query with apxl_log_id from 2268 to 2282 ? (there are 15 of them missing) ?
What could be the reason ?
SELECT apxl_log_id,apxl_srvr_nm FROM apxl_appl_xcptn_log WHERE ROWNUM <= nvl(50,(select count(*) from apxl_appl_xcptn_log))
ORDER BY apxl_log_id desc
Gives me, 2283
2268     NOT SPECIFIED
2267     NOT SPECIFIED
2266     NOT SPECIFIED
2265     NOT SPECIFIED
2264     NOT SPECIFIED
2263     NOT SPECIFIED
2262     NOT SPECIFIED
2261     NOT SPECIFIED
2260     NOT SPECIFIED
2259     NOT SPECIFIED
2190     NOT SPECIFIED
2113     NOT SPECIFIED
2112     NOT SPECIFIED
2111     NOT SPECIFIED
2110     NOT SPECIFIED
2109     NOT SPECIFIED
2108     NOT SPECIFIED
2107     NOT SPECIFIED
2081     NOT SPECIFIED
1925     NOT SPECIFIED
1917     NOT SPECIFIED
1916     NOT SPECIFIED
1915     NOT SPECIFIED
1914     NOT SPECIFIED
1913     NOT SPECIFIED
1912     NOT SPECIFIED
1911     NOT SPECIFIED
1910     NOT SPECIFIED
1885     NOT SPECIFIED
1876     NOT SPECIFIED
1874     NOT SPECIFIED
1872     NOT SPECIFIED
1871     NOT SPECIFIED
1870     NOT SPECIFIED
1869     NOT SPECIFIED
1865     NOT SPECIFIED
1864     NOT SPECIFIED
1863     NOT SPECIFIED
1848     NOT SPECIFIED
1847     NOT SPECIFIED
1846     NOT SPECIFIED
1839     NOT SPECIFIED
1837     NOT SPECIFIED
1831     NOT SPECIFIED
1830     NOT SPECIFIED
1829     NOT SPECIFIED
1828     NOT SPECIFIED
1827     NOT SPECIFIED
1822     NOT SPECIFIED
1819     NOT SPECIFIED
SELECT apxl_log_id,apxl_srvr_nm FROM apxl_appl_xcptn_log WHERE ROWNUM <= nvl(100,(select count(*) from apxl_appl_xcptn_log))
ORDER BY apxl_log_id desc
2283     NOT SPECIFIED
2282     NOT SPECIFIED
2281     NOT SPECIFIED
2278     NOT SPECIFIED
2277     NOT SPECIFIED
2276     NOT SPECIFIED
2275     NOT SPECIFIED
2274     NOT SPECIFIED
2273     NOT SPECIFIED
2272     NOT SPECIFIED
2268     NOT SPECIFIED
2267     NOT SPECIFIED
2266     NOT SPECIFIED
2265     NOT SPECIFIED
2264     NOT SPECIFIED
2263     NOT SPECIFIED
2262     NOT SPECIFIED
2261     NOT SPECIFIED
2260     NOT SPECIFIED
2259     NOT SPECIFIED
2237     NOT SPECIFIED
2236     NOT SPECIFIED
2235     NOT SPECIFIED
2234     NOT SPECIFIED
2233     NOT SPECIFIED
2232     NOT SPECIFIED
2190     NOT SPECIFIED
2138     NOT SPECIFIED
2137     NOT SPECIFIED
2133     NOT SPECIFIED
2132     NOT SPECIFIED
2131     NOT SPECIFIED
2130     NOT SPECIFIED
2129     NOT SPECIFIED
2128     NOT SPECIFIED
2127     NOT SPECIFIED
2126     NOT SPECIFIED
2125     NOT SPECIFIED
2124     NOT SPECIFIED
2123     NOT SPECIFIED
2122     NOT SPECIFIED
2121     NOT SPECIFIED
2120     NOT SPECIFIED
2119     NOT SPECIFIED
2118     NOT SPECIFIED
2117     NOT SPECIFIED
2116     NOT SPECIFIED
2113     NOT SPECIFIED
2112     NOT SPECIFIED
2111     NOT SPECIFIED
2110     NOT SPECIFIED
2109     NOT SPECIFIED
2108     NOT SPECIFIED
2107     NOT SPECIFIED
2106     NOT SPECIFIED
2105     NOT SPECIFIED
2104     NOT SPECIFIED
2103     NOT SPECIFIED
2102     NOT SPECIFIED
2081     NOT SPECIFIED
2017     test
1925     NOT SPECIFIED
1923     NOT SPECIFIED
1922     NOT SPECIFIED
1921     NOT SPECIFIED
1920     NOT SPECIFIED
1919     NOT SPECIFIED
1918     NOT SPECIFIED
1917     NOT SPECIFIED
1916     NOT SPECIFIED
1915     NOT SPECIFIED
1914     NOT SPECIFIED
1913     NOT SPECIFIED
1912     NOT SPECIFIED
1911     NOT SPECIFIED
1910     NOT SPECIFIED
1886     test
1885     NOT SPECIFIED
1876     NOT SPECIFIED
1874     NOT SPECIFIED
1872     NOT SPECIFIED
1871     NOT SPECIFIED
1870     NOT SPECIFIED
1869     NOT SPECIFIED
1865     NOT SPECIFIED
1864     NOT SPECIFIED
1863     NOT SPECIFIED
1848     NOT SPECIFIED
1847     NOT SPECIFIED
1846     NOT SPECIFIED
1839     NOT SPECIFIED
1837     NOT SPECIFIED
1832     NOT SPECIFIED
1831     NOT SPECIFIED
1830     NOT SPECIFIED
1829     NOT SPECIFIED
1828     NOT SPECIFIED
1827     NOT SPECIFIED
1822     NOT SPECIFIED
1819     NOT SPECIFIED

Order by is applied after the where clause, so you query returns the first 50 or 100 random rows and then orders them.
You need to use an in line view like this
select * from
  SELECT apxl_log_id,apxl_srvr_nm
  FROM apxl_appl_xcptn_log
  ORDER BY apxl_log_id desc
WHERE ROWNUM <= nvl(50,(select count(*) from apxl_appl_xcptn_log))

Similar Messages

  • Query with ROWNUM - does it scan the entire table? or returns once the limit is reached?

    Suppose I have a table with 50k records.
    I am running a query like the one below
    select *
    from sometable
    where ROWNUM < 10 AND AnotherCondition='y'
    In the above query, I can think of two possible ways to come up with the answer
    1. Scan and apply filter condition on ALL the rows, and return the first 10
    2. Do the things mentioned in option (1) but stop scanning once the record limit of 10 is reached. Don't scan the rest since it is not required.
    I would like to know which of the following approaches does Oracle follow?  Or, does it follow any other strategy that is not mentioned above?
    Has anyone done any tests to find out the answer for the above question?  If so, could you please share the findings?
    Thanks in advance.
    Regards,
    Vivek Ganesan

    Thanks! But where would I run the sql statement. When anyone launches the application it creates the database files in their user directory. How would I connect to the database after that to execute the statement?
    I see the create table statements in the files I have pulled into NetBeans in both the source folder and the distribution folder. Could I add the statement there before the table is created in the jar file in the distribution folder and then re-compile it for distribution? OR would I need to add it to the file in source directory and recompile those to create a new distribution?
    Thanks!

  • Query with parameter as Array (UDT) very slow

    Hi.
    I have following Problem. I try to use Oracle Instant Client 11 and ODP.NET to pass Arrays in SELECT statements as Bind Parameters. I did it, but it runs very-very slow. Example:
    - Inittial Query:
    SELECT tbl1.field1, tbl1.field2, tbl2.field1, tbl2.field2 ... FROM tbl1
    LEFT JOIN tbl2 ON tbl1.field11=tbl2.field0
    LEFT JOIN tbl3 ON tbl2.field11=tbl3.field0 AND tbll1.field5=tbl3.field1
    ...and another LEFT JOINS
    WHERE
    tbl1.field0 IN ('id01', 'id02', 'id03'...)
    this query with 100 elements in "IN" on my database takes 3 seconds.
    - Query with Array bind:
    in Oracle I did UDT: create or replace type myschema.mytype as table of varchar2(1000)
    than, as described in Oracle Example I did few classes (Factory and implementing IOracleCustomType) and use it in Query,
    instead of IN ('id01', 'id02', 'id03'...) I have tbl1.field0 IN (select column_value from table(:prmTable)), and :prmTable is bound array.
    this query takes 190 seconds!!! Why? I works, but the HDD of Oracle server works very hard, and it takes too long.
    Oracle server we habe 10g.
    PS: I tried to use only 5 elements in array - the same result, it takes also 190 seconds...
    Please help!

    I did (some time ago and it was a packaged procedure) something like
    Procedure p(p_one in datatype,p_two in datatype,p_dataset out sys_refcursor) is
      the_sql varchar2(32000);
      the_cursor sys_refcursor;
    begin
      the_sql = 'WITH NOTIFICACAO AS( ' ||
                '      SELECT ' ||
                '       t1.cd_consultora, ' ||
                '                               where       t1.dt_notificacao_cn >= to_date(''01/09/2006'',''dd/mm/yyyy'') ' ||  -- note the ''
                '           where rownum <= :W_TO_REC) ' ||   -- parameter 1
                '         where r_linha >= :W_FROM_REC ';     -- parameter 2
      open the_cursor for the_sql using p_one,p_two;  -- just by the book
    end p;if I remember correctly
    Regards
    Etbin

  • Query with order by & View/procedure

    1)I have a query its getting joined with few tables and the base table contains 12 billion rows . my issue is when I execute the query with necessary parameter am getting the result in few seconds . but when I add an order by for any column am not getting the result even after 15 minuts.
    The sort column is an indexed column and I have even tried with the primary column of the base table but no change .. is there any way to make it faster with order by ??
    2)I have got a view which also getting joined with few high volume tables . when I call the view with required parameter am not getting the result even after 15 minutes.. but when I took out the query of the view and hardcode the value am getting the result in 3 seconds . so I just made it to a procedure that returns a cursor . now its working fine .. could you please explain me the reason for this ….??
    Please help …

    select * from
    (select Rownum RowNO,Qr.* from
    (select T1.c1,T2.C2,T3.c3 from TI,T2,T3
    where < all required joins>
    order by Ti.c)Qr
    where RowNum <20 )
    where RowNO >10 ;As said before:
    Your view very likely prevented predicate pushing and by manually adding the predicate inside the query, you changed the semantics of the query.
    Your view contains a rownum column. This prevents predicate pushing because the semantics of the query changes. An example to clarify:
    SQL> explain plan
      2  for
      3  select *
      4    from ( select empno
      5                , ename
      6                , sal
      7             from emp
      8         )
      9   where empno = 7839
    10  /
    Uitleg is gegeven.
    SQL> select * from table(dbms_xplan.display)
      2  /
    PLAN_TABLE_OUTPUT
    Plan hash value: 4024650034
    | Id  | Operation                   | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |        |     1 |    14 |     1   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| EMP    |     1 |    14 |     1   (0)| 00:00:01 |
    |*  2 |   INDEX UNIQUE SCAN         | EMP_PK |     1 |       |     0   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("EMPNO"=7839)
    14 rijen zijn geselecteerd.
    SQL> exec dbms_lock.sleep(1)
    PL/SQL-procedure is geslaagd.
    SQL> explain plan
      2  for
      3  select *
      4    from ( select empno
      5                , ename
      6                , sal
      7             from emp
      8            where empno = 7839
      9         )
    10  /
    Uitleg is gegeven.
    SQL> select * from table(dbms_xplan.display)
      2  /
    PLAN_TABLE_OUTPUT
    Plan hash value: 4024650034
    | Id  | Operation                   | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |        |     1 |    14 |     1   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| EMP    |     1 |    14 |     1   (0)| 00:00:01 |
    |*  2 |   INDEX UNIQUE SCAN         | EMP_PK |     1 |       |     0   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("EMPNO"=7839)
    14 rijen zijn geselecteerd.The previous two queries show that in this case the predicate "empno = 7839" can be pushed inside the view. Both queries are semantically the same.
    However, when you add a rownum to your view definition, like you did, the predicates cannot be pushed inside the view:
    SQL> exec dbms_lock.sleep(1)
    PL/SQL-procedure is geslaagd.
    SQL> explain plan
      2  for
      3  select *
      4    from ( select empno
      5                , ename
      6                , sal
      7                , rownum rowno
      8             from emp
      9         )
    10   where empno = 7839
    11  /
    Uitleg is gegeven.
    SQL> select * from table(dbms_xplan.display)
      2  /
    PLAN_TABLE_OUTPUT
    Plan hash value: 2077119879
    | Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT    |      |    14 |   644 |     3   (0)| 00:00:01 |
    |*  1 |  VIEW               |      |    14 |   644 |     3   (0)| 00:00:01 |
    |   2 |   COUNT             |      |       |       |            |          |
    |   3 |    TABLE ACCESS FULL| EMP  |    14 |   196 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter("EMPNO"=7839)
    15 rijen zijn geselecteerd.
    SQL> exec dbms_lock.sleep(1)
    PL/SQL-procedure is geslaagd.
    SQL> explain plan
      2  for
      3  select *
      4    from ( select empno
      5                , ename
      6                , sal
      7                , rownum rowno
      8             from emp
      9            where empno = 7839
    10         )
    11  /
    Uitleg is gegeven.
    SQL> select * from table(dbms_xplan.display)
      2  /
    PLAN_TABLE_OUTPUT
    Plan hash value: 1054641936
    | Id  | Operation                     | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT              |        |     1 |    46 |     1   (0)| 00:00:01 |
    |   1 |  VIEW                         |        |     1 |    46 |     1   (0)| 00:00:01 |
    |   2 |   COUNT                       |        |       |       |            |          |
    |   3 |    TABLE ACCESS BY INDEX ROWID| EMP    |     1 |    14 |     1   (0)| 00:00:01 |
    |*  4 |     INDEX UNIQUE SCAN         | EMP_PK |     1 |       |     0   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       4 - access("EMPNO"=7839)
    16 rijen zijn geselecteerd.Now the two queries are not the same anymore. If you wonder why, please look carefully at the query results of both:
    SQL> select *
      2    from ( select empno
      3                , ename
      4                , sal
      5                , rownum rowno
      6             from emp
      7         )
      8   where empno = 7839
      9  /
         EMPNO ENAME             SAL      ROWNO
          7839 KING             5000          9
    1 rij is geselecteerd.
    SQL> select *
      2    from ( select empno
      3                , ename
      4                , sal
      5                , rownum rowno
      6             from emp
      7            where empno = 7839
      8         )
      9  /
         EMPNO ENAME             SAL      ROWNO
          7839 KING             5000          1
    1 rij is geselecteerd.Regards,
    Rob.

  • Query regarding rownum

    hi,
    why can't we use > operator in rownum?
    why we always have to use < or = ?
    is there any particular reason for this....why the following query wont work?
    select b.* from brnd b where rownum in (select rownum from brnd b where rownum <=3);

    Hi Solomon,
    Please see the below execution plan for both the queries ("=" and IN ) and their filter predicate. Same thing is happening when IN claused is used. Query with "IN" clause needs the result set (which is not yet ready as ROWNUM is not assigned) hence no rows. Query with = clause is being treated differently by the optimizer.
    SQL> select * from employees where rownum = (select rownum from employees b wher
    e rownum =1);
    Execution Plan
    Plan hash value: 3173700791
    | Id  | Operation           | Name         | Rows  | Bytes | Cost (%CPU)| Time
       |
    |   0 | SELECT STATEMENT    |              |   107 |  7383 |     4   (0)| 00:00:01 |
    |   1 |  COUNT              |              |       |       |            |   |
    |*  2 |   FILTER            |              |       |       |            |   |
    |   3 |    TABLE ACCESS FULL| EMPLOYEES    |   107 |  7383 |     3   (0)| 00:00:01 |
    |*  4 |    COUNT STOPKEY    |              |       |       |            |   |
    |   5 |     INDEX FULL SCAN | EMP_EMAIL_UK |     1 |       |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - filter( (SELECT ROWNUM FROM "EMPLOYEES" "B" WHERE ROWNUM=1)=ROWNUM)
       4 - filter(ROWNUM=1)
    SQL> ed
    Wrote file afiedt.buf
      1* select * from employees where rownum IN (select rownum from employees b whe
    re rownum =1)
    SQL> /
    Execution Plan
    Plan hash value: 1158694625
    | Id  | Operation           | Name         | Rows  | Bytes | Cost (%CPU)| Time
       |
    |   0 | SELECT STATEMENT    |              |   107 |  7383 |     4   (0)| 00:00:01 |
    |   1 |  COUNT              |              |       |       |            |   |
    |*  2 |   FILTER            |              |       |       |            |   |
    |   3 |    TABLE ACCESS FULL| EMPLOYEES    |   107 |  7383 |     3   (0)| 00:00:01 |
    |*  4 |    FILTER           |              |       |       |            |   |
    |*  5 |     COUNT STOPKEY   |              |       |       |            |   |
    |   6 |      INDEX FULL SCAN| EMP_EMAIL_UK |     1 |       |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - filter( EXISTS (<not feasible>)
       4 - filter(ROWNUM=ROWNUM)
       5 - filter(ROWNUM=1)

  • Strange problem with rownum

    Hi,
    In the query below, I am using rownum to use as a field to join the output to another query.
    It works fine and give the desired output. But after I made some updates to the undelying table (total_table), the query does not return anything. When I remove the rownum field it works fine but if I use with the rownum it does not return anyting. I tried to run the inner query with the rownum and it runs fine.
    Finally I dropped and recreated the table and the query runs fine. After a day I again had to make some updates to the table after which it seemed to work fine for some time (after the updates). But this morning it behaved similarly. I dropped and recreated again and it is fine now.
    Any insight?
    select rownum r2, ab, total_1,
    from (select substr(file_name, 2,12) ab , total_1 from total_table where month_value = (select to_char(add_months(sysdate, 1), 'MON YYYY') from dual) order by 1,2)
    Thanks,

    rownum are allowed in the outer or main query.
    SQL> select rownum, e.*
      2    from (select empno, ename, job, sal
      3            from emp
      4          order by sal desc) e
        ROWNUM EMPNO ENAME      JOB             SAL
             1  7839 KING       PRESIDENT   5000.00
             2  7902 FORD       ANALYST     3000.00
             3  7788 SCOTT      ANALYST     3000.00
             4  7566 JONES      MANAGER     2975.00
             5  7698 BLAKE      MANAGER     2850.00
             6  7782 CLARK      MANAGER     2450.00
             7  7950 TINA       SALESMAN    1850.00
             8  7945 CINDY      SALESMAN    1800.00
             9  7499 ALLEN      SALESMAN    1600.00
            10  7844 TURNER     SALESMAN    1500.00
            11  7934 MILLER     CLERK       1300.00
            12  7521 WARD       SALESMAN    1250.00
            13  7654 MARTIN     SALESMAN    1250.00
            14  7876 ADAMS      CLERK       1100.00
            15  7900 JAMES      CLERK        950.00
            16  7369 SMITH      CLERK        800.00
    16 rows selected
    SQL> can you try to post some sample update statements that you have used. so we can try to reproduce the issue based on the sample data you have posted.

  • Query with additional condition

    select * from (select  b.account, f.company from account a, company f
                                where f.company=b.company
                                 and f.company_type='BIZ') where rownum<=10
    So, these are two tables I am drawing data from. I also need to pull the data from the account table where there is no company information attached to it. In that case, b.company would be null and subsequently there would be no f.company or f.company_type. Any help mucho appreciated!!!!

    You need to do a outer join. Like this
    select a.account
         , f.company
      from account a
      left
      join company f
        on f.company= a.company
       and f.company_type = 'BIZ';
    The query you have posted is incorrect. You have used an alias b in your select column but there is no such alias. Also whats the deal with ROWNUM filter?

  • How to create an ABAP Query with OR logical expression in the select-where

    Hi,
    In trying to create an ABAP query with parameters. So it will select data where fields are equal to the parameters entered. The default logical expression is SELECT.. WHERE... AND.. However I want to have an OR logical expression instead of AND.. how can I attain this??
    Please help me on this.. Points will be rewarded.
    Thanks a lot.
    Regards,
    Question Man

    Hi Bhupal, Shanthi, and Saipriya,
    Thanks for your replies. But that didn't answer my question.
    Bhupal,
    You cannot just replace AND with OR in an ABAP QUERY. ABAP QUERY is a self generated SAP code. You'll just declare the tables, input parameters and output fields to be displayed and it will create a SAP standard code. If you'll try to change the code and replace the AND with OR in the SAP standard code, the system will require you to enter access key/object key for that particular query.
    Shanthi,
    Yes, that is exactly what need to have. I need to retireve DATA whenever one of the conditions was satisfied.
    Saipriya,
    Like what I have said, this is a standard SAP code so we can't do your suggestion.
    I have already tried to insert a code in the ABAP query (there's a part there wherein you can have extra code) but that didn't work. Can anybody help me on this.
    Thanks a lot.
    Points will be rewarded.
    Regards,
    Question Man

  • Error while trying to Execute the Query with Customer Exit

    Hi Experts,
           I am having a Query with Customer Exit, it is working fine for all the Employess, except for one. When i try to remove the Customer Exit it is working for her too. Below is the error i am getting.
    system error in program SAPLLRK0 and form RSRDR; CHECK_NAV_INIT_BACK
    Thanks,
    Kris.

    Hello Kris,
    Are you working with multiprovider? Please check if OSS notes 813454,840080 or 578948 are applicable in your case.
    Regards,
    Praveen

  • Report on BEx query with 2 structures (one in rows and one in columns)

    Hi, experts! I have to make Crystall report on BEx query with 2 structures, one in columns (with KF's), and one in rows. Is it possible to create such report? Because when I create such report, I cant see fields in structures, only characteristics fields.
    Ok, I found samr problem in another thread. Sorry.
    Edited by: Mikhail Sychev on Dec 5, 2009 9:53 PM

    Hey Flora,
    Happy to hear that its working now.
    Answering your question, again its upto the connection and report format you are using. Based on your question i hope you your report output should be like this.
    You cannot map to two labels for the series, again this report format is possible only in cross tab through Webi. I would suggest you to concatenate the material and month in a dimension in webi like below.
    I have done the concatenation in excel level, i would suggest you to do that in webi. Try to reduce the formula as much in excel.
    or
    If you are using Query browser connection, then i would suggest you to create a separate report which will display the actual vs plan material wise, here you need to pass the material as a prompt.
    Hope this helps in clear, please revert me for any clarification.

  • Query with bind variable, how can use it in managed bean ?

    Hi
    I create query with bind variable (BindControlTextValue), this query return description of value that i set in BindControlTextValue variable, how can i use this query in managed bean? I need to set this value in String parameter in managed bean.
    Thanks

    Put the query in a VO and execute it the usual way.
    If you need to, you can write a parameterized method in VOImpl that executes the VO query with the parameter and then call that method from the UI (as a methodAction binding) either through the managed bean or via a direct button click on the page.

  • Report query with bind variable

    Trying to create a report query for xsl-fo print. For output format I pick "derive from item" then pick the item name from the list, on the next screen, I paste the query with the bind variable. on the next step test query, I always get "data not found" regardless what value I type in. This is the same query that I ran under sql commands without any issues.
    Does anyone run into the same issue as I have when attempted to create a query with bind var ? There is no problem creating a query without bind varibles. . thanks.
    Munshar

    Hi, please did you get any solution to this issue? I am having similar challenge right now.
    select     EMP.DEPTNO as DEPTNO,
         DEPT.DNAME as DNAME,
         EMP.EMPNO as EMPNO,
         EMP.ENAME as ENAME,
         EMP.JOB as JOB,
         EMP.MGR as MGR,
         EMP.HIREDATE as HIREDATE,
         EMP.SAL as SAL
    from     SCOTT.DEPT DEPT,
         SCOTT.EMP EMP
    where EMP.DEPTNO=DEPT.DEPTNO
    and      DEPT.DNAME =upper(:dname)
    This run perfectly in sql developer, toad, and even inside publisher if I login directly to publisher to create report.
    Generating this same query in shared component query builder and testing it returns no data found. If I remove the last line, it works. but with the last line, it return no data found. It seems no one has been able to provide solution to this issue

  • SQL query with Bind variable with slower execution plan

    I have a 'normal' sql select-insert statement (not using bind variable) and it yields the following execution plan:-
    Execution Plan
    0 INSERT STATEMENT Optimizer=CHOOSE (Cost=7 Card=1 Bytes=148)
    1 0 HASH JOIN (Cost=7 Card=1 Bytes=148)
    2 1 TABLE ACCESS (BY INDEX ROWID) OF 'TABLEA' (Cost=4 Card=1 Bytes=100)
    3 2 INDEX (RANGE SCAN) OF 'TABLEA_IDX_2' (NON-UNIQUE) (Cost=3 Card=1)
    4 1 INDEX (FAST FULL SCAN) OF 'TABLEB_IDX_003' (NON-UNIQUE)
    (Cost=2 Card=135 Bytes=6480)
    Statistics
    0 recursive calls
    18 db block gets
    15558 consistent gets
    47 physical reads
    9896 redo size
    423 bytes sent via SQL*Net to client
    1095 bytes received via SQL*Net from client
    3 SQL*Net roundtrips to/from client
    1 sorts (memory)
    0 sorts (disk)
    55 rows processed
    I have the same query but instead running using bind variable (I test it with both oracle form and SQL*plus), it takes considerably longer with a different execution plan:-
    Execution Plan
    0 INSERT STATEMENT Optimizer=CHOOSE (Cost=407 Card=1 Bytes=148)
    1 0 TABLE ACCESS (BY INDEX ROWID) OF 'TABLEA' (Cost=3 Card=1 Bytes=100)
    2 1 NESTED LOOPS (Cost=407 Card=1 Bytes=148)
    3 2 INDEX (FAST FULL SCAN) OF TABLEB_IDX_003' (NON-UNIQUE) (Cost=2 Card=135 Bytes=6480)
    4 2 INDEX (RANGE SCAN) OF 'TABLEA_IDX_2' (NON-UNIQUE) (Cost=2 Card=1)
    Statistics
    0 recursive calls
    12 db block gets
    3003199 consistent gets
    54 physical reads
    9448 redo size
    423 bytes sent via SQL*Net to client
    1258 bytes received via SQL*Net from client
    3 SQL*Net roundtrips to/from client
    1 sorts (memory)
    0 sorts (disk)
    55 rows processed
    TABLEA has around 3million record while TABLEB has 300 records. Is there anyway I can improve the speed of the sql query with bind variable? I have DBA Access to the database
    Regards
    Ivan

    Many thanks for your reply.
    I have run the statistic already for the both tableA and tableB as well all the indexes associated with both table (using dbms_stats, I am on 9i db ) but not the indexed columns.
    for table I use:-
    begin
    dbms_stats.gather_table_stats(ownname=> 'IVAN', tabname=> 'TABLEA', partname=> NULL);
    end;
    for index I use:-
    begin
    dbms_stats.gather_index_stats(ownname=> 'IVAN', indname=> 'TABLEB_IDX_003', partname=> NULL);
    end;
    Is it possible to show me a sample of how to collect statisc for INDEX columns stats?
    regards
    Ivan

  • Query with tables VEPVG, VBAK, VBAP AND KONV

    hi all,
    I have a requirement, that is Open Sale Orders which is having Special Discount. I am trying to write a Query, But KONV table is not coming into the joins. my execution plans is bellow
    VEPVG  -->  VBAK         vbak-knumv = konv-knumv and konv-kschl = Special Discount
                        VBAP
    Please explain me, how to design the query with conditions.
    Thanks & Regards,
    Srinivas

    Hi,
    Have you referred this help document.
    http://help.sap.com/printdocu/core/Print46c/EN/data/pdf/BCSRVQUE/BCSRVQUE.pdf
    Regards - Shree

  • SQL Report query with condition (multiple parameters) in apex item?

    Hello all,
    I have a little problem and can't find a solution.
    I need to create reports based on a SQL query or I.R. Nothing hard there.
    Then I need to add the WHERE clause dynamically with javascript from an Apex item.
    Again not very hard. I defined an Apex item, set my query like this "SELECT * FROM MYTAB WHERE COL1 = :P1_SEARCH" and then I call the page setting the P1_SEARCH value. For instance COL1 is rowid. It works fine.
    But here is my problem. Let's consider that P1_SEARCH will contain several rowids and that I don't know the number of those values,
    (no I won't create a lot of items and build a query with so many OR!), I would like sotheming like "SELECT * FROM MYTAB WHERE ROWID IN (:P1_SEARCH) with something like : ROWID1,ROWID2 in P1_SEARCH.
    I also tried : 'ROWID1,ROWID2' and 'ROWID1','ROWID2'
    but I can't get anything else than filter error. It works with IN with one value but as soon as there are two values or more, it seems than Apex can't read the string.
    How could I do that, please?
    Thanks for your help.
    Max

    mnoscars wrote:
    But here is my problem. Let's consider that P1_SEARCH will contain several rowids and that I don't know the number of those values,
    (no I won't create a lot of items and build a query with so many OR!), I would like sotheming like "SELECT * FROM MYTAB WHERE ROWID IN (:P1_SEARCH) with something like : ROWID1,ROWID2 in P1_SEARCH.
    I also tried : 'ROWID1,ROWID2' and 'ROWID1','ROWID2'
    but I can't get anything else than filter error. It works with IN with one value but as soon as there are two values or more, it seems than Apex can't read the string.For a standard report, see +{message:id=9609120}+
    For an IR&mdash;and improved security avoiding the risk of SQL Injection&mdash;use a <a href="http://download.oracle.com/docs/cd/E17556_01/doc/apirefs.40/e15519/apex_collection.htm#CACFAICJ">collection</a> containing the values in a column instead of a CSV list:
    {code}
    SELECT * FROM MYTAB WHERE ROWID IN (SELECT c001 FROM apex_collections WHERE collection_name = 'P1_SEARCH')
    {code}
    (Please close duplicate threads spawned by your original question.)

Maybe you are looking for

  • What cause this error: java.util.zip.ZipException: invalid literal/lengths?

    Hi all, Our application produces this error in the logs: (our JDEV is 11.1.1.4.0, WLS 10.3) org.apache.myfaces.trinidadinternal.renderkit.core.CoreResponseStateManager _restoreSerializedView SEVERE: java.util.zip.ZipException: invalid literal/lengths

  • Silent recall on MacBook Pro batteries

    http://blogs.zdnet.com/Apple/?p=189 "If it wasn't bad enough that to have processor and CPU whine, poor Airport reception and solar ambient temperatures, it appears that some early MacBook Pro batteries are now failing. Christopher Price from PCSInte

  • RV042 email & time

    I am trying to set up a new RV-042. I have three questions: 1. I want to enable email notification of logs but my SMTP server requires authentication (as most do these days). I can't find anywhere to enter the authentication information into the rout

  • GTX 580 TWIN FROZR 2 OC UEFI GOP BIOS

    I wanted to ask if there is any UEFI GOP compatible VBIOS available for the MSI GTX 580 TWIN FROZR 2 OC? Thanks

  • Definitive answer to Safari logging out of Facebook?

    I've been logged out of Facebook every time my computer goes to sleep. I check the "remember me" option in Safari each time. Any working solutions? I read that this is a feature that was worked in by Apple apparently? If so, then I'm going to Chrome.