Why rownum 5 return no rows selected

hi
i want to know why rownum >5 .. is give no rows selected
eg
select * from emp where rownum>5;
.....

Because Oracle assigns a row number after it's actually been selected for outputting. In other words after the where condition has been satisfied.
So, it looks at the first row and then sees if it's rownum (1) is greater than 5 - it isn't
It looks at the next row (whose rownum is still 1 as we haven't selected anything for output yet). It still isn't greater than 5.
...and so on.
But rownum < 5 will work. It will get you 4 rows.
Note that sorting taking place after all this so
select *
from emp
where rownum < 5
order by emp_no;Will NOT get you the first 4 rows ordered by emp_no. Rather it will get you 4 arbitrary rows and then sort them by emp_no.
So, back to your problem. It is probably best to use row_number rather than rownum:
select *
from (
  select e.*, row_number() over (order by empno) rnum  from emp e
where rnum > 5;

Similar Messages

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

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

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

  • Return first row entered based on date column

    I'm trying to select the first entered row in a table, as judged by the datetime column. If more than one row has the same date and time, then only one row should be returned (any row having that datetime is fine). Some processing will occur on that row and then it will be deleted. The select statement is used thereafter to select the next (first) entered row in the table, etc. This way, the rows are processed first-in first-out (FIFO) style. Here's my example table:
    create table my_table
    datetime date,
    firstname varchar2(50)
    insert into my_table(datetime, firstname) values(to_date('2012-04-02 11:00:00', 'YYYY-MM-DD HH24:MI:SS'),'ken');
    insert into my_table(datetime, firstname) values(to_date('2012-04-02 11:00:00', 'YYYY-MM-DD HH24:MI:SS'),'john');
    insert into my_table(datetime, firstname) values(to_date('2012-04-02 11:00:00', 'YYYY-MM-DD HH24:MI:SS'),'sue');
    commit;
    Here's my example select statement, which returns simply one row of the above, since all are the same date and time:
    SELECT *
    FROM my_table
    WHERE datetime = ( select min(datetime) from my_table )
    AND rownum = 1;
    My question is, if I use the following
    SELECT *
    FROM my_table
    WHERE datetime = ( select min(datetime) from my_table );
    It returns all 3 rows:
    DATETIME FIRSTNAME
    02-APR-12 11:00:00 ken
    02-APR-12 11:00:00 john
    02-APR-12 11:00:00 sue
    So, wouldn't setting rownum = 2 return john, and rownum = 3 return sue? For example,
    SELECT *
    FROM my_table
    WHERE datetime = ( select min(datetime) from my_table )
    AND rownum = 2;
    return no rows. I just want to make sure I'm understanding how the select statement above works. It seems to work fine for returning one row having the minimum date and time. If this is always the case, then everything is fine. But I wouldn't have expected it not to return one of the other rows when rownum is 2 or 3, which makes me question why? Maybe I can learn something here. Any comments much appreciated.
    Edited by: tem on Apr 2, 2012 2:06 PM

    Hi,
    tem wrote:
    ... So, wouldn't setting rownum = 2 return john, and rownum = 3 return sue? For example,, ROWNUM
    SELECT *
    FROM my_table
    WHERE datetime = ( select min(datetime) from my_table )
    AND rownum = 2;
    return no rows. I just want to make sure I'm understanding how the select statement above works. It seems to work fine for returning one row having the minimum date and time. If this is always the case, then everything is fine. But I wouldn't have expected it not to return one of the other rows when rownum is 2 or 3, which makes me question why? Maybe I can learn something here. Any comments much appreciated.ROWNUM is assigned as rows are fetched and considered for inclusion in the result set. If the row is not chosen for any reason, the same ROWNUM will be reused with the next row fetched. ROWNUM=2 will not be assigned until a row with ROWNUM=1 has been included in hte result set.
    So, in your example:
    SELECT  *
    FROM    my_table
    WHERE   datetime = ( select min(datetime) from my_table )
    AND     rownum = 2;Say the first row that happens to be fetched has firstname='ken'. It is assigned ROWNUM=1, and fails the WHERE clause condition "WHERE rownum = 2".
    Say the next row fetched has firstname='john'. ROWNUM=1 hasn't been used yet, so this row is also assigned ROWNUM=1, and it fails the WHERE clause for the same reason. Likewise with the next row; it also is assigned ROWNUM=1, and it also fails.
    When using ROWNUM in a WHERE clause, you almost always want to say "ROWNUM = 1" or "ROWNUM <= n".
    You could also use the analytic ROW_NUMBER function:
    WITH     got_r_num     AS
         SELECT     datetime, firstname
         ,     ROW_NUMBER () OVER (ORDER BY  datetime)     AS r_num
         FROM     my_table
    SELECT     datetime, firstname
    FROM     got_r_num
    WHERE     r_num     = 1
    ;Here, all values of r_num are available, so it would make sense to say things like "WHERE r_num = 2" or "WHERE r_num >= 2".
    Edited by: Frank Kulash on Apr 2, 2012 5:31 PM
    Added to explanation.

  • SQL Query (PL/SQL Function Body returning SQL query) doesn't return any row

    I have a region with the following type:
    SQL Query (PL/SQL Function Body returning SQL query).
    In a search screen the users can enter different numbers, separated by an ENTER.
    I want to check these numbers by replacing the ENTER, which is CHR(13) || CHR(10) I believe, with commas. And then I can use it like this: POD IN (<<text>>).
    It's something like this:
    If (:P30_POD Is Not Null) Then
    v_where := v_where || v_condition || 'POD IN (''''''''||REPLACE(''' || :P30_POD || ''', CHR(13) || CHR(10), '','')||'''''''''')';
    v_condition := ' AND ';
    End If;
    But the query doesn't return any rows.
    I tried to reproduce it in Toad:
    select * from asx_worklistitem
    where
    POD IN (''''||REPLACE('541449200000171813'||CHR(13) || CHR(10)||'541449206006341366', CHR(13) || CHR(10), ''',''')||'''')
    ==> This is the query that does't return any rows
    select (''''||REPLACE('541449200000171813'||CHR(13) || CHR(10)||'541449206006341366', CHR(13) || CHR(10), ''',''')||'''')
    from dual;
    ==> This returns '541449200000171813','541449206006341366'
    select * from asx_worklistitem
    where pod in ('541449200000171813','541449206006341366');
    ==> and when I copy/paste this in the above query, it does return my rows.
    So why does my first query doesn't work?
    Doe anyone have any idea?
    Kind regards,
    Geert
    Message was edited by:
    Zorry

    Thanks for the help.
    I made it work, but via the following code:
    If (:P30_POD Is Not Null) Then
    v_pods := REPLACE(:P30_POD, CHR(13) || CHR(10));
    v_where := v_where || v_condition || 'POD IN (';
    v_counter := 1;
    WHILE (v_counter < LENGTH(v_pods)) LOOP
    v_pod := SUBSTR(v_pods, v_counter, 18);
    IF (v_counter <> 1) THEN
    v_where := v_where || ',';
    END IF;
    v_where := v_where || '''' || v_pod || '''';
    v_counter := v_counter + 18;
    END LOOP;
    v_where := v_where || ')';
    v_condition := ' AND ';
    End If;But now I want to make an update of all the records that correspond to this search criteria. I can give in a status via a dropdownlist and that I want to update all the records that correspond to one of these POD's with that status.
    For a region you can build an SQL query via PL/SQL, but for a process you only have a PL/SQL block. Is the only way to update all these records by making a loop and make an update for every POD that is specified.
    Because I think this will have a lot of overhead.
    I would like to make something like a multi row update in an updateable report, but I want to specify the status from somewhere else. Is this possible?

  • How to handle the ref cursor which is returning "no rows"

    I have written a function which is returning the REF CURSOR. But in one situation the REF CURSOR returns "no rows selected". To handle this situation an exception is raised "when no data found". But i dont know in this situation how should NULL cursor be returned through this function. Since I want to call this function in another procedure so something should be returned through this function by means of ref cursor. But since i am not able to handle this "no rows selected" situation i am not able move further.
    Thanks in advance........

    I agree.
    You would simply process the returned ref cursor irrespective of any rows actually returned in the cursor or not. You would be able to do at least one FETCH from the cursor (even if it does not actually contain any rows) and then determine the %NOTFOUND status to do the rest of the processing.
    SQL> variable cur refcursor
    SQL> exec open :cur for select * from scott.emp where rownum = 1 ;
    PL/SQL procedure successfully completed.
    SQL> print cur
         EMPNO ENAME      JOB              MGR HIREDATE           SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 17-DEC-1980        800                    20
    1 row selected.
    SQL>
    SQL> exec open :cur for select * from scott.emp where 1 = 2 ;
    PL/SQL procedure successfully completed.
    SQL> print cur
    no rows selected
    SQL>
    SQL> SET SERVEROUTPUT ON
    SQL> DECLARE
      2      rec scott.emp%ROWTYPE;
      3      bol BOOLEAN;
      4      cur sys_refcursor;
      5  BEGIN
      6      OPEN cur FOR
      7          SELECT * FROM scott.emp WHERE 1 = 2; /* assume this is your function call returning a ref cursor */
      8      bol := FALSE;
      9      LOOP
    10          FETCH cur
    11              INTO rec;
    12          EXIT WHEN cur%NOTFOUND;
    13          --
    14          -- process the data here
    15          --
    16          bol := TRUE;
    17      END LOOP;
    18      CLOSE cur;
    19      IF (bol)
    20      THEN
    21          dbms_output.put_line('At least one row was found');
    22      ELSE
    23          dbms_output.put_line('No rows were selected');
    24      END IF;
    25  END;
    26  /
    No rows were selected
    PL/SQL procedure successfully completed.
    SQL>

  • Pl/sql block returning multiple rows

    Hi,
    I've created a plsql block which obtains an id from a name and then uses this id in another sql statement. The select statement to get the id works fine and the correct id is placed into the variable awardID.
    when i try to use this variable in another select statement it returns multiple rows. but when i just use the id in the select statement it works fine.
    select AwardID into awardID
    from award_objtabA
    where Name = awardName;
    this returns the correct id '5999'
    select Points into award_points
    from award_objtabA
    where AwardID = awardID;
    this returns multiple rows
    select Points into award_points
    from award_objtabA
    where AwardID = 5999;
    this works fine
    can anybody help with this confusing error?
    Cheers

    select AwardID
      into awardID               <= the same column
      from award_objtabA
    where Name = awardName;
    this returns the correct id '5999'
    select Points
      into award_points
      from award_objtabA
    where AwardID = awardID;    <= the same column
    this returns multiple rows
    to solve use different name not exactly the same as that of the column name
    select AwardID
      into vAwardID        
      from award_objtabA
    where Name = awardName;
    select Points
      into award_points
      from award_objtabA
    where AwardID = vAwardID;as Alex and Kamal have suggested use different name for your variable.

  • SQL Query returning no rows, please help!!

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

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

  • Oracle view return more rows than its base query

    O/S : AIX
    Database : 11g R (11.1.0.6.0)
    Query in questioon :
    select A.CompanyCode, A.Code ElementCode, A.ItemTypeCode ElementItemTypeCode, A.SubcodeKey ElementSubcodeKey,
    D.DecoSubcode01 SubCode01, D.DecoSubcode02 SubCode02, D.DecoSubcode03 SubCode03, D.DecoSubcode04 SubCode04,
    D.DecoSubcode05 SubCode05, D.DecoSubcode06 SubCode06, D.DecoSubcode07 SubCode07, D.DecoSubcode08 SubCode08,
    D.DecoSubcode09 SubCode09, D.DecoSubcode10 SubCode10, C.ItemTypeBCode, C.SubCode01B, C.SubCode02B, C.SubCode03B,
    C.SubCode04B, C.SubCode05B, C.SubCode06B, C.SubCode07B, C.SubCode08B, C.SubCode09B, C.SubCode10B,
    B1.ValueString SlipNo, B2.ValueString EmployeeCode, B3.ValueString SetNo, B4.ValueString SalesOrderCounterCode,
    B5.ValueString SalesOrderCode, B6.ValueString Remarks, B7.ValueDecimal SumTareWeight, B8.ValueString PackingUMCode,
    B9.ValueString PrimaryUMCode, B10.ValueString PlantCode, B11.ValueDecimal PackingFormCode, D.LogicalWarehouseCode FromWarehouseCode,
    D.TemplateCode FromTemplateCode, D.PhysicalWarehouseCode FromPhysicalWarehouseCode, D.WHSLOCATIONWAREHOUSEZONECODE FromZoneCode,
    D.WarehouseLocationCode FromLocationCode, E.LogicalWarehouseCode ToWarehouseCode, E.TemplateCode ToTemplateCode, E.PhysicalWarehouseCode ToPhysicalWarehouseCode,
    E.WHSLOCATIONWAREHOUSEZONECODE ToZoneCode, E.WarehouseLocationCode ToLocationCode, D.TransactionDate, D.ItemTypeCode, E.WeightGross SumGrossWeight, E.WeightNet SumNetWeight
    FROM Elements A, ADStorage B1, ADStorage B2, ADStorage B3, ADStorage B4, ADStorage B5, ADStorage B6, ADStorage B7,
    ADStorage B8, ADStorage B9, ADStorage B10, ADStorage B11, GoodCutAndFentDetail C, StockTransaction D, StockTransaction E
    where A.ABSUNIQUEID=B1.UNIQUEID and B1.NameEntityName='Elements' and B1.FieldName ='GoodCutAndFentSlipNo'
    and A.ABSUNIQUEID=B2.UNIQUEID and B2.NameEntityName='Elements' and B2.FieldName ='GoodCutAndFentEmployee'
    and A.ABSUNIQUEID=B3.UNIQUEID and B3.NameEntityName='Elements' and B3.FieldName ='GoodCutAndFentSetNo'
    and A.ABSUNIQUEID=B4.UNIQUEID and B4.NameEntityName='Elements' and B4.FieldName ='GoodCutAndFentSOCounterCode'
    and A.ABSUNIQUEID=B5.UNIQUEID and B5.NameEntityName='Elements' and B5.FieldName ='GoodCutAndFentSOCode'
    and A.ABSUNIQUEID=B6.UNIQUEID and B6.NameEntityName='Elements' and B6.FieldName ='GoodCutAndFentRemarks'
    and A.ABSUNIQUEID=B7.UNIQUEID and B7.NameEntityName='Elements' and B7.FieldName ='GoodCutAndFentTareWeight'
    and A.ABSUNIQUEID=B8.UNIQUEID and B8.NameEntityName='Elements' and B8.FieldName ='GoodCutAndFentPackingUM'
    and A.ABSUNIQUEID=B9.UNIQUEID and B9.NameEntityName='Elements' and B9.FieldName ='GoodCutAndFentPrimaryUM'
    and A.ABSUNIQUEID=B10.UNIQUEID and B10.NameEntityName='Elements' and B10.FieldName ='GoodCutAndFentPlant'
    and A.ABSUNIQUEID=B11.UNIQUEID and B11.NameEntityName='Elements' and B11.FieldName ='GoodCutAndFentPackingForm'
    and A.CompanyCode=C.CompanyCode and SlipNo=C.SlipNo and C.SeqNo=1 and A.ItemTypeCode=C.ElementItemTypeCode
    and A.SubcodeKey=C.ElementSubcodeKey and A.Code=C.ElementCode and A.CompanyCode=D.CompanyCode
    and C.FromSTTransactionNumber=D.TransactionNumber and C.FromSTTransactionDetailNumber=D.TransactionDetailNumber
    and A.CompanyCode=E.CompanyCode and C.ToSTTransactionNumber=E.TransactionNumber
    and C.ToSTTransactionDetailNumber=E.TransactionDetailNumber
    and SLIPNO='57575763636'
    This query return 1 row.
    Then i created a view on this query except condition SLIPNO='57575763636'
    Now when i use the view as shown below return two rows.
    select * from ViewGoodCutAndFent WHERE SLIPNO = '57575763636'
    I am not able to determine where is problem area is. Thanks & Regards

    In the query SLIPNO is probably C.SlipNo
    In the view SLIPNO is probably B1.ValueString

  • Xmltable returning no rows

    I have the following XML
    <?xml version = '1.0' encoding = 'UTF-8'?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:sawsoap="urn://oracle.bi.webservices/v6">
       <soap:Body>
          <sawsoap:getGroupsResult>
             <sawsoap:account xsi:type="sawsoap:Account">
                <sawsoap:name>Presentation Server Administrators</sawsoap:name>
                <sawsoap:accountType>1</sawsoap:accountType>
                <sawsoap:guid>bipse53c4188a730640cc6c0a242</sawsoap:guid>
             </sawsoap:account>
             <sawsoap:account xsi:type="sawsoap:Account">
                <sawsoap:name>AuthenticatedUser</sawsoap:name>
                <sawsoap:accountType>4</sawsoap:accountType>
                <sawsoap:guid>AuthenticatedUser</sawsoap:guid>
             </sawsoap:account>
             <sawsoap:account xsi:type="sawsoap:Account">
                <sawsoap:name>BIConsumer</sawsoap:name>
                <sawsoap:accountType>4</sawsoap:accountType>
                <sawsoap:guid>BIConsumer</sawsoap:guid>
             </sawsoap:account>
          </sawsoap:getGroupsResult>
       </soap:Body>
    </soap:Envelope>I am trying to generate the list of account types, which in this case would just be
    Presentation Server Administrators
    AuthenticatedUser
    BIConsumer
    I am using the following SQL statement in my attempt, but it is returning zero rows.
    select x.*
    from tony, xmltable ('/account'
    passing extract(x,'//sawsoap:getGroupsResult','xmlns:sawsoap="urn://oracle.bi.webservices/v6"')
    columns
    group_name varchar2(255) path '/name'
    ) x;I have tried different combinations of XPaths, including the sawsoap:account and sawsoap:name,but other continue to return no records. I have the sense that I am close and would appreciate a second set of eyes that could point out the mistake.
    Tony

    Welcome to the forums. When posting, always include your version as shown by
    select * from v$version
    It makes a difference. For your issue, you are mixing some pre 10.2 syntax (extract) with 10.2 and later syntax (XMLTable).
    What you are looking for is something like
    WITH tony AS
    (SELECT XMLTYPE('<?xml version = ''1.0'' encoding = ''UTF-8''?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:sawsoap="urn://oracle.bi.webservices/v6">
       <soap:Body>
          <sawsoap:getGroupsResult>
             <sawsoap:account xsi:type="sawsoap:Account">
                <sawsoap:name>Presentation Server Administrators</sawsoap:name>
                <sawsoap:accountType>1</sawsoap:accountType>
                <sawsoap:guid>bipse53c4188a730640cc6c0a242</sawsoap:guid>
             </sawsoap:account>
             <sawsoap:account xsi:type="sawsoap:Account">
                <sawsoap:name>AuthenticatedUser</sawsoap:name>
                <sawsoap:accountType>4</sawsoap:accountType>
                <sawsoap:guid>AuthenticatedUser</sawsoap:guid>
             </sawsoap:account>
             <sawsoap:account xsi:type="sawsoap:Account">
                <sawsoap:name>BIConsumer</sawsoap:name>
                <sawsoap:accountType>4</sawsoap:accountType>
                <sawsoap:guid>BIConsumer</sawsoap:guid>
             </sawsoap:account>
          </sawsoap:getGroupsResult>
       </soap:Body>
    </soap:Envelope>') x
       FROM dual)
    -- The above WITH simulates your table.  You only care about the below  
    SELECT x.*
      FROM tony,
           XMLTable(XMLNamespaces('http://schemas.xmlsoap.org/soap/envelope/' AS "soap",
                                  'urn://oracle.bi.webservices/v6' AS "sawsoap"),
                    '/soap:Envelope/soap:Body/sawsoap:getGroupsResult/sawsoap:account'
                    PASSING tony.x
                    COLUMNS
                    group_name   VARCHAR2(40) PATH 'sawsoap:name'
                   ) x;
    GROUP_NAME
    Presentation Server Administrators
    AuthenticatedUser
    BIConsumer

  • How can I limit the number of rows returned by a select stat

    How can I limit the number of rows returned by a select
    statement. I have a query where I return the number of stores
    that are located in a given area.. I only want to return the
    first twenty-five stores. In some instances there may be over
    200 stores in a given location.
    I know is SQL 7 that I can set the pagesize to be 25....
    Anything similiar in Oracle 8i?
    null

    Debbie (guest) wrote:
    : Chad Nale (guest) wrote:
    : : How can I limit the number of rows returned by a select
    : : statement. I have a query where I return the number of
    : stores
    : : that are located in a given area.. I only want to return the
    : : first twenty-five stores. In some instances there may be
    : over
    : : 200 stores in a given location.
    : : I know is SQL 7 that I can set the pagesize to be 25....
    : : Anything similiar in Oracle 8i?
    : If you are in Sql*Plus, you could add the statement
    : WHERE rownum <= 25
    : Used together with an appropriate ORDER BY you
    : could get the first 25 stores.
    Watch out. ROWNUM is run before ORDER BY so this would only
    order the 25 selected
    null

  • Can I limit the number of rows returned on a Select?

    Can I limit the number of rows returned on a Select statement? I would be using JDBC in a Java program.

    Use Java prepared statements with the equivalent of this SQL*plus script:
    VARIABLE n number
    EXEC :n := 3;
    SELECT rownum FROM all_objects WHERE rownum <= :n;
        ROWNUM
             1
             2
             3
    EXEC :n := 5;
    SELECT rownum FROM all_objects WHERE rownum <= :n;
        ROWNUM
             1
             2
             3
             4
             5

  • Query with subquery containing group clause doesn't return any rows - WHY ?

    Hi,
    My query doesn't return any values :
    select g1.NTRX from gtrx g1
    where exists
    (SELECT b.cfunctrx, b.cpro1trx, b.nmsgitrx, b.nmrc, b.ncrd, b.namtstrx,
    b.dltimtrx, b.nrtrftrx,count(*)
    FROM gtrxacq a, gtrx b
    WHERE a.ntrx = b.ntrx AND a.acq_bus_date = (SELECT curr_bus_date -1
    FROM gmbr
    WHERE nmbr = 0)
    and g1.NTRX=b.NTRX
    GROUP BY b.cfunctrx,
    b.cpro1trx,
    b.nmsgitrx,
    b.nmrc,
    b.ncrd,
    b.namtstrx,
    b.dltimtrx,
    b.nrtrftrx
    HAVING COUNT (*) > 1);
    but such query returns some number of rows :
    SELECT b.cfunctrx, b.cpro1trx, b.nmsgitrx, b.nmrc, b.ncrd, b.namtstrx,
    b.dltimtrx, b.nrtrftrx,count(*)
    FROM gtrxacq a, gtrx b
    WHERE a.ntrx = b.ntrx AND a.acq_bus_date = (SELECT curr_bus_date -1
    FROM gmbr
    WHERE nmbr = 0)
    /*and g1.NTRX=b.NTRX*/
    GROUP BY b.cfunctrx,
    b.cpro1trx,
    b.nmsgitrx,
    b.nmrc,
    b.ncrd,
    b.namtstrx,
    b.dltimtrx,
    b.nrtrftrx
    HAVING COUNT (*) > 1
    AND when i put results from query above into query :
    select g1.NTRX from gtrx g1
    where
    g1.CFUNCTRX= 200 and g1.CPRO1TRX= 000 and g1.NMSGITRX= 1240 and
    g1.NMRC= '000000000000675' and g1.NCRD= 405671**********
    and g1.NAMTSTRX=14.26 and g1.DLTIMTRX=to_date('07/08/2008 15:07:02','MM/DD/YYYY HH24:MI:SS')
    and g1.NRTRFTRX= '000414598393';
    it returns values.
    what is wrong ?
    Best Regards Arkadiusz Masny

    but such query returns some number of rows :
    /*and g1.NTRX=b.NTRX*/Add b.NTRX into group by and recheck.

  • 'select count(*) from x' returns 5460 rows and 'Select * from x' returns 0 rows

    As you can see in the next lines something is wrong in my Oracle (8.0.6 on Win NT 4.0 sp 6a) :
    Oracle8 Enterprise Edition Release 8.0.6.0.0 - Production
    With the Partitioning option
    PL/SQL Release 8.0.6.0.0 - Production
    SQLWKS> SELECT * FROM V_TERRA_TE;
    PERIOD_DATE PERIOD_TIME TERRARCV TERRASND TERCV TESND
    0 rows selected.
    SQLWKS> SELECT COUNT(*) FROM V_TERRA_TE;
    COUNT(*)
    5460
    1 row selected.
    V_TERRA_TE is a complex join of 5 Tables :
    CREATE OR REPLACE VIEW "ACTUATE".V_TERRA_TE AS Select to_date(to_char(p1.period_date,'YYYYMMDD'),'YYYYMMDD') "PERIOD_DATE",
    to_date(to_char(p1.period_time,'HH24:MI'),'HH24:MI') "PERIOD_TIME",
    to_number(p1.caudalrcv + ((p3.caudalrcv + p4.caudalrcv)*(confterrate.conexadslterra/confterrate.conexadsltotal))) "TERRARCV",
    to_number(p1.caudalsnd + ((p3.caudalsnd + p4.caudalsnd)*(confterrate.conexadslterra/confterrate.conexadsltotal))) "TERRASND",
    to_number((p2.caudalrcv * confterrate.pctinfonegocio) + ((p3.caudalrcv + p4.caudalrcv)*(confterrate.conexadslte/confterrate.conexadsltotal)))"TERCV",
    to_number((p2.caudalsnd * confterrate.pctinfonegocio) + ((p3.caudalsnd + p4.caudalsnd)*(confterrate.conexadslte/confterrate.conexadsltotal)))"TESND"
    from p1,p2,p3,p4,confterrate
    where (p1.period_date=p2.period_date)and
    (p1.period_date=p3.period_date)and
    (p1.period_date=p4.period_date)and
    (p1.period_time=p3.period_time)and
    (p1.period_time=p4.period_time)and
    (p1.period_time=p2.period_time)and
    to_char(p1.period_date,'MMYYYY')=to_char(confterrate.period_datetime,'MMYYYY');
    I think that some not reported error happens in the select * with some temporary space or similar but only the message '0 rows selected' is displayed (instead the real error)
    Could somebody help me ?
    Thanks in advance
    Francisco

    Forcing the Join/sort to be made on Disk (not on memory) the problem not happens. This demostrate that ORACLE has a VERY IMPORTANT BUG : It returns 0 rows wich is false.
    To force it to work on disk i use this parameters :
    alter session set sort_area_size=0
    alter session set hash_join_enabled=false
    Note : probably is not the best combination or use of parameters, but using it the query works as espected.

  • Table- Why first row Selected from itself

    Hi,
    i have a jspx that have some fields and a button ,
    the user should fill this fields with data then click the button
    the button pass those values to a function that call a Stored Proceudre in the DB
    then the last code in that button is to refresh a table (by execute param) that read the inserted data
    why everytime the table refreshed give me the data with the first row SELECTED!!!!!!!!
    i am using ADFBC + JSF
    thanks in advance

    Hi,
    hope you handled the case where a user hits submit - or performs some other action that is performed on the current row - because you are now in an unpredictable state. Ideally you disable all related command buttons until a user selects a row
    Frank

  • Select for update that doesn't return any rows

    Are there any odd side-effects that may occur if a select for update that returns no results is never committed? I wouldn't think there are, but I'm not sure if there would be some kind of overhead or unforeseen consequences. This isn't a terribly important question, but it's come up in some coding I've done and I've not been able to find any documentation addressing it.

    A select for update only locks rows that meet the predicate specified in the where clause. So, if the query returns no rows, no rows are locked.
    session1> SELECT * FROM t;
            ID DESCR
             1 Un
             5 One
             2 THIS IS WA
    session1> SELECT * FROM t
      2  WHERE id = 11 FOR UPDATE;
    no rows selectedA second session can update rows in the table
    session2> UPDATE t
      2  SET descr = 'One'
      3  WHERE id = 1;
    1 row updated.John
    Edited by: John Spencer on Jan 7, 2009 1:36 PM
    I just realized that, although you can do updates on the table after the select fo update that returns no rows, you cannot do DDL operations liike a truncate. Unless the session that does the select for update either ends the transaction (i.e. commit or rollback) or ends the session DDL operations will fail.

Maybe you are looking for

  • Keyboard keys not registering when typing quickly or lightly on a new HP2000 laptop

    Hello, I have the HP2000 laptop and my key compresses frequently d not register unless pressed alot harder than normal. This pc is only a few months od and I feel this is not usual. Is there a quick fix or adjustment or am I stuck learning how to typ

  • HT4436 can't delete name in icloud

    Message: Couldn't delete (NAME) Dialog.Error.Text.Contact.DESTRROY.NOT_FOUND

  • HT1688 how can i figure out a passcode on my cellphone?

    how can i figure out a passcode that was put on my phone, person locked me out of my phone

  • How to remove virus from words with friends?

    Recently when I play words with friends the app opens up my safari browser to the following address but it is blank. "Cdn3.doubleverify.com".  I downloaded all my apps from the App Store and I thought they were supposed to be "virus free". Can anyone

  • Class help needed.

    i have declared 3 variables in a class, x and y are coordiantres public class Robot private double x; private double y; private double Orientation; public Robot()      x = 0;      y = 0;      Orientation = 0; public (double px, double py, double pOri