Order by, cursor, rownum

i want to select 10 database entires
from an 8i database with the selector variable and sort the entries by a date
column.
but the problem is that my sql statement
(see below) selects first the entries
and then the entries get ordered.
what i need is first the entries ordered
and then the select. otherwise it is possible
that i get on the next page with the next
10 entries that this entries may be with a date that should be on the prev. page.
has anyone an idea?
thx
SELECT *
FROM (SELECT col1,
col2
FROM table
WHERE ROWNUM < (selector + 10)
MINUS
SELECT col1,
col2
FROM table
WHERE ROWNUM < selector)
ORDER BY TO_DATE (col2, 'DD.MM.YYYY HH24:MI');

In Oracle 8i, the general format for this sort of "top-n" analysis is:
SELECT column1, column2, ROWNUM
FROM (SELECT column1, column2
FROM table_name
ORDER BY top_n_column DESC)
WHERE ROWNUM <= number_of_rows;
Applying that to this situation, the query would be something like:
SELECT col1, col2, ROWNUM
FROM (SELECT col1, col2
FROM table
ORDER BY TO_DATE(col2, 'DD.MM.YYYY HH24:MI') DESC)
WHERE ROWNUM <= 10;
When you put the ORDER BY clause in a sub-query as above, the ORDER BY is applied before the numbering of the rows, so the pseudo-column ROWNUM has some meaning and usefulness.
However, for those of us who are still using versions prior to Oracle 8i, we can't have an ORDER BY clause in a sub-query; It will generate a somewhat confusing error about a missing parenthesis. Therefore, the pseudo-column ROWNUM has no meaning or usefulness. So, prior to Oracle 8i, for "top-n" analysis, the general format is something like this (It will also still work in 8i):
SELECT outer.column1, outer.column2
FROM table_name outer
WHERE number_of_rows >=
(SELECT COUNT (*) + 1
FROM table_name inner
WHERE inner.top_n_column > outer.top_n_column)
ORDER BY outer.top_n_column DESC;
Applying that to this situation, the query would be something like:
SELECT outer.col1, outer.col2
FROM table outer
WHERE 10 >=
(SELECT COUNT (*) + 1
FROM table inner
WHERE TO_DATE(inner.col2,'DD.MM.YYYY HH24:MI') > TO_DATE(outer..col2,'DD.MM.YYYY HH24:MI'))
ORDER BY TO_DATE(outer.col2,'DD.MM.YYYY HH24:MI') DESC;
A lot of people keep asking for queries to select the first few or last few rows entered in a table, without ordering by a specific column (for what purpose I am not sure). It is a common mistake to attempt to use ROWNUM for this purpose. However, ROWID is assigned an incremental value upon input, not upon ordering or retrieval, like ROWNUM. Therefore, the pseudo-column ROWID can be used as a comparison column for the same sort of "top-n" analysis like this:
For the first n rows:
SELECT outer.column1, outer.column2, ROWID
FROM table_name outer
WHERE n >=
(SELECT COUNT (*) + 1
FROM table_name inner
WHERE inner.ROWID < outer.ROWID)
ORDER BY ROWID;
For the last n rows:
SELECT outer.column1, outer.column2, ROWID
FROM table_name outer
WHERE n >=
(SELECT COUNT (*) + 1
FROM table_name inner
WHERE inner.ROWID > outer.ROWID)
ORDER BY ROWID DESC;
If you are only attempting to retrieve one row, with or without a comparison column, then you can use things like MIN, MAX, NOT IN, NOT EXISTS, and set operators to find that one row.
I have seen a lot of confusion on this topic and I hope this explanation was thorough enough to help clarify it for some.
null

Similar Messages

  • Using order by and rownum in massive tables

    Hi,
    I need to retreive paginated and ordered data from a big table.
    I know some different tips using rownum or the RANK() function and subqueries, these tips work well for small amount of data, but I need to get the data from a table with 200.000 entries (not under my control), and with all those methods is necessary to order first the data and then select your range, so performance is extremely poor.
    Anybody knows a better solution? it doesn't matter if is plain SQL(better) or PL/SQL.
    Thanks in advance

    but I was looking for something like the LIMIT in MySQL or TOP in msSQL where all the sorting is made internally and it's really fast If the data needs sorting, I do not think Oracle would take any longer to do that than the others mentioned, unless the other DBs mentioned, only sort the rows that are actually being returned.
    As for the LIMIT clause, Oracle already has that clause available when FETCHing from a CURSOR:
    SQL> DECLARE
      2      CURSOR emp_cur IS
      3          SELECT * FROM scott.emp;
      4      TYPE emp_rec_table IS TABLE OF emp_cur%ROWTYPE INDEX BY BINARY_INTEGER;
      5      emp_tbl emp_rec_table;
      6  BEGIN
      7      OPEN emp_cur;
      8      LOOP
      9          emp_tbl.DELETE;
    10          FETCH emp_cur BULK COLLECT
    11              INTO emp_tbl LIMIT 5;
    12          EXIT WHEN emp_tbl.COUNT <= 0;
    13          dbms_output.put_line(emp_tbl.COUNT || ' rows fetched using LIMIT clause.');
    14      END LOOP;
    15      CLOSE emp_cur;
    16  END;
    17  /
    5 rows fetched using LIMIT clause.
    5 rows fetched using LIMIT clause.
    4 rows fetched using LIMIT clause.
    PL/SQL procedure successfully completed.
    SQL> disconnect
    Disconnected from Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.3.0 - Production
    SQL>

  • Order by AND rownum in a function?

    I have a table with articles sorted by an id. In the table is also a date field to tell when the article is written.
    I want a query that returns the 20 latest articles, and this is what i have come up with:
    SELECT * FROM (
    SELECT articleid,writtendate
    FROM articles
    ORDER BY writtendate desc)
    WHERE ROWNUM < 21;
    This works alright, BUT I want it in a function! There it doesnt compile!!! Anyone got any suggestions?
    I have tried to separate the stuff, like first sorting the records in a view and then selecting the top 20 after that. I could try a cursor and fetching out of that, but havent suceeded with that either.
    Bye!

    ok, the sql statement works perfectly in an sql editor, but wont compile in a function.
    FUNCTION fnc_getLatest20 (
    cur IN OUT pkg_cursor.refcur
    )RETURN pkg_exception.return_type IS
    BEGIN
    OPEN cur FOR
    SELECT * FROM (
    SELECT articleid,writtendate
    FROM articles
    ORDER BY writtendate DESC)
    WHERE ROWNUM < 21;
    RETURN pkg_exception.err_none;
    END;
    The best I have is that either the rows returned in the cursor is all rows, ordered correctly or the top twenty in some other order.
    I most be on the wrong track here, there has to be some easier way of doing this...
    BTW, thanks for the help so far.

  • Order BY with ROWNUM in Select List

    Hi,
    I have query like bellow for Oracle 11g:
    create table em_c (vl_s_ec int,id_em_em int,id_empcre_ecr int, id_em_ec int);
    create table em (id_em_em int)
    Select e.id_em_em
    , NVL(
    (SELECT * FROM(SELECT a.vl_s_ec FROM em_c a WHERE a.id_em_em = ec.id_em_em
    AND a.id_empcre_ecr < ec.id_em_ec order by a.id_em_ec DESC) WHERE ROWNUM <= 1) ,0) AS col2
    FROM em_c ec
    INNER JOIN em e on ec.id_em_em = e.id_em_em
    WHERE 1 = 1;
    But inner subselect doesn't see table "em_c ec" from outer FROM clause. That's why following error occurs:
    SQL Error: ORA-00904: "EC"."ID_EM_EC": invalid identifier
    Please help me to make it work.
    Edited by: user11290901 on Dec 17, 2010 2:11 AM

    Correlation names only go one level deep. It's a bit tough to decipher your query so if you want a better response please post the following:
    1. Oracle version (SELECT * FROM V$VERSION)
    2. Sample data in the form of CREATE / INSERT statements.
    3. Expected output
    4. Explanation of expected output (A.K.A. "business logic")
    5. Use \ tags for #2 and #3. See FAQ (Link on top right side) for details.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Order by before rownum

    I am trying to select top 200 records from a really complex select query with order by. But Oracle does top 200 first then order by if I put rownum and order by in one select query, which will give me top 200 records redomly every time. I know a way to work around is doing following
    select * from (select................ order by ......) where rownum<=200
    but this will really take long time since the inner select query is big one. it joins 15 some tables to get all informations. I know in MS SQL, you can have select top(200)...... ordery by ...., it will do order by then top 200. This is making query running really fast.
    Is there other ways to make this run faster in Oracle. Possiblely puting oder by and rownum<200 in one select query?
    Thanks!
    Edited by: user4916474 on Jan 14, 2011 8:24 AM

    Hi,
    See these threads for the information you need to post when you have a performace issue:
    When your query takes too long ...
    HOW TO: Post a SQL statement tuning request - template posting
    If you have a complicated query involving 15 tables, the solution is likely to be complicated, too. For example, you might need to find the top 200 rows before joining all the tables, so just looking for an alternative to ROWNUM probably won't help all by itself, though it may be part of the overall solution.
    One alternative to ROWNUM is the analytic ROW_NUMBER function:
    SELECT  *
    FROM     (
             SELECT  ...
             ,         ROW_NUMBER () OVER (ORDER BY ...)     AS r_num
             FROM    ...
    WHERE     r_num     <= 200
    ;It might not be faster than ROWNUM, but it's probably not slower, either, and it can be adapted to other requirements (e.g., the top 200 for each department).

  • Order By Vs. RowNum

    Hello,
    My query has an Order By statement (order by tblA.Name) .
    When the query runs this is the order the records come out:
    1) All records that have a space in the first byte of their Name field.
    2) All records whos name begins with a special character like: #1 Italian Restuarant.
    3) All records whos name begins with a numeric like: 21 Club
    4) and finally all Alpha records....A - Z.
    Now if I only want to select the first 300 rows, (still using the same Order By). In my Where clause I put (oracle):
    and RowNum < 300.
    When the query runs I get this order:
    1st) Alpha records....A - Z.
    Can anyone explain what to do about this?
    Thanks for your time!

    Hi,
    In any single query, ROWNUM is assigned before ORDER BY is applied.
    If you want just the opposite, do the ORDER BY in a sub-query and the ROWNUM in its super-query:
    WITH  ordered_rows  AS
        SELECT    *     -- or whatever
        FROM      tbla
        ORDER BY  name
    SELECT  *
    FROM    ordered_rows
    WHERE   ROWNUM  <= 300;

  • Production order, put cursor on field in Assignment Tab

    Hi,
    I work on an enhancement for production order...
    When a user created a production order, if the "Profit Center" (in "Assignment" tab) is empty at saving, a popup is displayed to inform the user that he could filled this field. If he doesn't want to do this, he clicks on "Continue" button, elseif he wants to fill "Profit Center" field, he clicks on "Modify".
    My problem is when the user clicks on "Modify" button, I would like that the "Assignment" screen appears and the cursor is located on the "Profit Center" field. I take a look on technical information and the only info that I can use is the screen 0115. But I can't indicate the position to the cursor !
    Can anyone help me?
    Thanks in advance.
    Best Regards.

    Hello,
    You can try with 'Implicit Enhancement' in PBO of that screen 0115 and use 'SET CURSOR FIELD..statement' by checking user command..
    Thanks

  • Question about order by and rownum and subqueries.

    Can you explain why test 4 below results as it results- with returning no rows?
    Identificator "PKG_INTRA_CUSTOMER_SEARCH.NAME" is a package function, which returns value from a variable declared in package body, the function returns value 'e%'.
    Please note that tests 1-3 all returned data, but test 4 didn't. Why? My porpouse is that test 4 would also return data.
    1. Query without "rownum" and with "Order by" returns 2 records:
    select q.*--, rownum
                ,PKG_INTRA_CUSTOMER_SEARCH.NAME
             from
                select c.ID,
                   c.NAME,
                   c.CODE     
                from V_CUSTOMER c  
                where 1=1 and  lower(c.NAME) like PKG_INTRA_CUSTOMER_SEARCH.NAME 
                order by c.NAME, c.ID
                ) q
    10020     Ees Nimi     37810010237     e%
    10040     ewewrwe werwerwer          e%2. Query with "rownum" and without "Order by" returns 2 records:
    select q.*, rownum
                ,PKG_INTRA_CUSTOMER_SEARCH.NAME
             from
                select c.ID,
                   c.NAME,
                   c.CODE     
                from V_CUSTOMER c  
                where 1=1 and  lower(c.NAME) like PKG_INTRA_CUSTOMER_SEARCH.NAME 
                --order by c.NAME, c.ID
                ) q
    10020     Ees Nimi     37810010237     e%
    10040     ewewrwe werwerwer          e%3.Query without "rownum" and with "Order by" returns 2 records:
    select q.*--, rownum
                ,PKG_INTRA_CUSTOMER_SEARCH.NAME
             from
                select c.ID,
                   c.NAME,
                   c.CODE     
                from V_CUSTOMER c  
                where 1=1 and  lower(c.NAME) like PKG_INTRA_CUSTOMER_SEARCH.NAME 
                order by c.NAME, c.ID
                ) q
    10020     Ees Nimi     37810010237     e%
    10040     ewewrwe werwerwer          e% 4. Query with "rownum" and with "Order by" returns 0 records:
    select q.*, rownum
                ,PKG_INTRA_CUSTOMER_SEARCH.NAME
             from
                select c.ID,
                   c.NAME,
                   c.CODE     
                from V_CUSTOMER c  
                where 1=1 and  lower(c.NAME) like PKG_INTRA_CUSTOMER_SEARCH.NAME 
                order by c.NAME, c.ID
                ) q

    Hi,
    please reproduce the question in your test database with script below.
    My general question is that wht Test5 below returns only 1 row, but Test5 returns 3 rows.
    The difference between those two tests is only that one has "order by" clause, the other doesn't have.
    I need the "order by" clause to stay, but seems like it is not allowed.
    CREATE OR REPLACE
    PACKAGE PACKAGE1 AS
    function NAME return varchar2;
    END PACKAGE1;
    CREATE OR REPLACE
    PACKAGE body PACKAGE1 AS
    function NAME return varchar2
    is
    begin
       return 'e%';
    end NAME;
    END PACKAGE1;
    select PACKAGE1.name from dual--e%
    create table Tbl AS
       (SELECT 'e2b' Col1, 'A' Col2, 'AA' Col3 FROM dual
       UNION
       SELECT 'e3b', 'B','BB' FROM dual
    --Test5:  
    select q.*, rownum pos, PACKAGE1.name f         
             from
                select c.col1,
                   c.col2,
                   c.col3     
                from Tbl c  
                where 1=1 and  lower(c.col1) like PACKAGE1.name                      
                order by c.col2, c.col1
                ) q                               
                union all
             select '111' , '111' , '111' , 0 pos, PACKAGE1.name f from dual   --return 1 row
    --Test6
    select q.*, rownum pos, PACKAGE1.name f         
             from
                select c.col1,
                   c.col2,
                   c.col3     
                from Tbl c  
                where 1=1 and  lower(c.col1) like PACKAGE1.name                      
                --order by c.col2, c.col1
                ) q                               
                union all
             select '111' , '111' , '111' , 0 pos, PACKAGE1.name f from dual   --return 3 rowsEdited by: CharlesRoos on Feb 17, 2010 5:30 AM

  • Cursor selection does not follow chapter order on sub-menu

    I used iMovieHD6 to add chapter markers to my large DVD project. They "shared" very nicely into iDVD8 and the Chapter Selection sub-menus were created nicely.
    The problem is that when I use the cursor arrows on the DVD remote (real or virtual, in or out of iDVD), the highlight jumps around the sub-menu items rather than moving in a logical order. For example, I have 4 sub-menus with 6 chapters in each. Let's use numbers for them starting with the upper left they are 1,2,3 and then at the lower left they begin 4,5,6. I am using the Reflection White theme. When I press the right remote cursor button it will move from 1 to 2 to 5 to 6 to 3 to 4 and back to 1. Note that this order is not the same for each sub-menu, but none of them go 1,2,3,4,5,6.
    I don't know what might be wrong or how to correct it, but I have a really big project that is otherwise perfect and I'd really like to get it out, please help!
    Thanks.

    I just wanted to add this before closing this topic.
    After poking around with the Reflection theme I better understood what Len was talking about. It appears that there are no modifiable parameters in the theme itself that control the order of cursor's motion through the buttons. That I assume is hard-coded into iDVD and follows a pre-programmed logic.
    The point of failure is the position and orientation of the buttons in the Reflection theme's sub-menus when added automatically. They are made to look to the viewer as though they are set on an angled surface and viewed at an angle from above. While our brains can process this effect nicely, iDVD's cursor logic doesn't fare as well.
    The work-around is fairly simple: Realizing that iDVD treats all chapter buttons as though they are two-dimensional objects on a flat surface, you must re-arrange them so that from top-left to bottom-right they follow a logical order, with the first buttons higher and farther left than the later-selected buttons. You don't have to move them very far to get the desired result and it doesn't have to affect the overall appearance of the menu in a noticeable way.
    A slight rearrangement in my case left the overall look of the chapter menu the same but yielded a zig-zag flow through the buttons as follows:
    [1] [3] [5]
    [2] [4] [6]
    Pressing the right cursor key jumps from top left to bottom left to top center then bottom center then top right and finally bottom right before going back to the start. Granted this is not quite "right" in that if iDVD could "see" the menu the way my brain does it would go left to right across the upper row of buttons rather than zig-zagging, but I figure that as long as the user can understand how to get to the button they want it'll be fine.
    If you really need your menu selection to move linearly left to right with those arrows and with the up/down arrow used to move it vertically, then you have to arrange the buttons on the menu in a rectangular pattern with the top of each row of buttons all in a nice horizontal line. Note that's not the same as the alignment line that Reflection provides for you, it's a true horizontal line in relation to the monitor screen.
    I'd much prefer that iDVD revisit the logic of the cursor control code, perhaps adding the choice of allowing the numerical sequence of the chapters to dictate the order of the cursor's motion rather than their relative position on the screen, but since they don't call me for advice, the above will likely have to do.

  • TIPS(46) : ROWNUM(ORDERING 순으로 NUMBERING, RANGE SELECT)

    제품 : SQL*PLUS
    작성날짜 : 2003-07-30
    TIPS(46) : ROWNUM(ORDERING 순으로 NUMBERING, RANGE SELECT)
    =========================================================
    PURPOSE
    Explanation
    SQL*PLUS에서 ORDERING 순으로 NUMBERING하기를 원하는 경우가 많으나,
    ORDERING이 되기 전에 RANDOM ACCESS 시
    ROWNUM이 ASSIGN되기 때문에, 다음과 같은 결과가 나타날 것이다.
    SQL> select ename, rownum from emp;
    ENAME ROWNUM
    ALLEN 1
    JONES 2
    BLAKE 3
    CLARK 4
    KING 5
    ADAMS 6
    JAMES 7
    FORD 8
    SQL> select ename, rownum from emp order by ename;
    ENAME ROWNUM
    ADAMS 6
    ALLEN 1
    BLAKE 3
    CLARK 4
    FORD 8
    JAMES 7
    JONES 2
    KING 5
    Example
    다음의 몇 가지 방법을 이용하여 ORDERING 순으로 NUMBERING을 나타내어 보자.
    1) RECORD를 COUNT하는 방법 (DATA가 많은 경우 부적절)
    SQL> select A.ename, count(*) position
    2 from emp A, emp B
    3 where A.ename > B.ename
    4 or A.ename = B.ename and A.empno >= B.empno
    5 group by A.empno, A.ename
    6 order by A.ename, A.empno;
    ENAME POSITION
    ADAMS 1
    ALLEN 2
    BLAKE 3
    CLARK 4
    FORD 5
    JAMES 6
    JONES 7
    KING 8
    2) INDEX를 이용하는 방법
    SQL> create index sort_ix on emp (ename);
    Index created.
    SQL> select ename, rownum from emp where ename > ' ';
    ENAME ROWNUM
    ADAMS 1
    ALLEN 2
    BLAKE 3
    CLARK 4
    FORD 5
    JAMES 6
    JONES 7
    KING 8
    cf) descending인 경우 아래처럼 hint 사용 바람
    select /*+ index_desc(emp ename_ix) */
    ename, rownum from emp
    where ename > ' ' and rownum < 4;
    3) OPTIMIZER를 이용하는 방법
    SQL> select rownum, ename
    2 from emp , dual
    3 where emp.ename = dual.dummy (+);
    ROWNUM ENAME
    1 ADAMS
    2 ALLEN
    3 BLAKE
    4 CLARK
    5 FORD
    6 JAMES
    7 JONES
    8 KING
    위에서 언급한 내용에 더해서 rownum을 where 절에 사용함에 있어서는
    rownum 1을 포함하는 range(예 : 'where rownum <= 100')에 대해서만
    정상적인 조회가 가능하다.
    만약 rownum 1을 포함하지 않는 range(예 : 'where rownum between 50 and 100')
    에 대한 자료 조회를 원한다면 다음과 같이 in-line view를 이용하는 방법을
    사용할 수 있다.
    select rn, ename
    from ( select rownum rn, ename
    from emp)
    where rn between 3 and 5 ;
    RN ENAME
    3 BLAKE
    4 CLARK
    5 KING
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE
    1 0 VIEW
    2 1 COUNT
    3 2 TABLE ACCESS (FULL) OF 'EMP'
    * 이 때 in-line view의 rownum에는 반드시 alias를 이용해야 한다.
    in-line view에 의해서 선택되어지는 data가 많다면 performance가
    떨어질 수 있다.
    Reference Documents
    -------------------

    제품 : SQL*PLUS
    작성날짜 : 2003-07-30
    TIPS(46) : ROWNUM(ORDERING 순으로 NUMBERING, RANGE SELECT)
    =========================================================
    PURPOSE
    Explanation
    SQL*PLUS에서 ORDERING 순으로 NUMBERING하기를 원하는 경우가 많으나,
    ORDERING이 되기 전에 RANDOM ACCESS 시
    ROWNUM이 ASSIGN되기 때문에, 다음과 같은 결과가 나타날 것이다.
    SQL> select ename, rownum from emp;
    ENAME ROWNUM
    ALLEN 1
    JONES 2
    BLAKE 3
    CLARK 4
    KING 5
    ADAMS 6
    JAMES 7
    FORD 8
    SQL> select ename, rownum from emp order by ename;
    ENAME ROWNUM
    ADAMS 6
    ALLEN 1
    BLAKE 3
    CLARK 4
    FORD 8
    JAMES 7
    JONES 2
    KING 5
    Example
    다음의 몇 가지 방법을 이용하여 ORDERING 순으로 NUMBERING을 나타내어 보자.
    1) RECORD를 COUNT하는 방법 (DATA가 많은 경우 부적절)
    SQL> select A.ename, count(*) position
    2 from emp A, emp B
    3 where A.ename > B.ename
    4 or A.ename = B.ename and A.empno >= B.empno
    5 group by A.empno, A.ename
    6 order by A.ename, A.empno;
    ENAME POSITION
    ADAMS 1
    ALLEN 2
    BLAKE 3
    CLARK 4
    FORD 5
    JAMES 6
    JONES 7
    KING 8
    2) INDEX를 이용하는 방법
    SQL> create index sort_ix on emp (ename);
    Index created.
    SQL> select ename, rownum from emp where ename > ' ';
    ENAME ROWNUM
    ADAMS 1
    ALLEN 2
    BLAKE 3
    CLARK 4
    FORD 5
    JAMES 6
    JONES 7
    KING 8
    cf) descending인 경우 아래처럼 hint 사용 바람
    select /*+ index_desc(emp ename_ix) */
    ename, rownum from emp
    where ename > ' ' and rownum < 4;
    3) OPTIMIZER를 이용하는 방법
    SQL> select rownum, ename
    2 from emp , dual
    3 where emp.ename = dual.dummy (+);
    ROWNUM ENAME
    1 ADAMS
    2 ALLEN
    3 BLAKE
    4 CLARK
    5 FORD
    6 JAMES
    7 JONES
    8 KING
    위에서 언급한 내용에 더해서 rownum을 where 절에 사용함에 있어서는
    rownum 1을 포함하는 range(예 : 'where rownum <= 100')에 대해서만
    정상적인 조회가 가능하다.
    만약 rownum 1을 포함하지 않는 range(예 : 'where rownum between 50 and 100')
    에 대한 자료 조회를 원한다면 다음과 같이 in-line view를 이용하는 방법을
    사용할 수 있다.
    select rn, ename
    from ( select rownum rn, ename
    from emp)
    where rn between 3 and 5 ;
    RN ENAME
    3 BLAKE
    4 CLARK
    5 KING
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE
    1 0 VIEW
    2 1 COUNT
    3 2 TABLE ACCESS (FULL) OF 'EMP'
    * 이 때 in-line view의 rownum에는 반드시 alias를 이용해야 한다.
    in-line view에 의해서 선택되어지는 data가 많다면 performance가
    떨어질 수 있다.
    Reference Documents
    -------------------

  • Different order in the results

    I have a problem with order consistency in the data set on the screen vs. the sequence of records being selected one by one behind the screen.
    Say, in the first form I select certain "where clause" and several "order by". I pass parameters to the second form, compile query in runtime and start bringing records into the form for update, one by one. That's when the original first screen order is being messed up.
    Say, we have a group of records sorted by type, received_date. The set on the screen (user can only 2,3 and 4th columns) and in SQL*Plus would display:
    Rownum     Unique # Type     Date
    11     100 E     10/10/2005
    13     103 E     10/10/2005
    12     102 E     10/10/2005
    14     104 E     10/10/2005
    15     105 E     10/10/2005
    Records retrieved by the second screen via cursor, one by one, would appear in the following order:
    Rownum     Unique # Type     Date
    11     100 E     10/10/2005
    12     102 E     10/10/2005
    13     103 E     10/10/2005
    14     104 E     10/10/2005
    15     105 E     10/10/2005
    Basically, Oracle adds rownum as a last Order by to the customized Order By. Has anyone run into the similar problem and what did you do to fix it?

    And Rownum is an internal number that is applied AFTER the rows are sorted, so no matter how you order your records, Rownum will always start with 1.
    Does my result have something to do with subquery?
    SELECT rownum, unique#, report_type, received_date
    FROM table x
    WHERE condition blah-blah-blah
    AND unique# IN (subquery from table y)
    ORDER BY report_type ASC, received_date DESC
    My query above gives the result as follows:
    rownum unique# report_type received_date
    1     4630093     E     4/8/2005
    2     4630095     E     4/8/2005
    3     4630096     E     4/8/2005
    11     4629916     E     4/8/2005
    4     4630099     E     4/8/2005
    62     4631257     E     4/8/2005
    64     4631286     E     4/8/2005
    66     4631288     E     4/8/2005
    68     4631290     E     4/8/2005
    218     4630693     E     4/8/2005
    196     4630163     E     4/8/2005
    195     4630599     E     4/8/2005
    194     4630580     E     4/8/2005
    193     4631309     E     4/8/2005
    192     4631308     E     4/8/2005
    191     4631307     E     4/8/2005
    167     4630012     E     4/8/2005
    166     4630011     E     4/8/2005
    165     4629997     E     4/8/2005
    164     4629996     E     4/8/2005
    163     4629989     E     4/8/2005
    162     4630574     E     4/8/2005
    67     4631289     E     4/8/2005
    65     4631287     E     4/8/2005
    63     4631259     E     4/8/2005
    And then when retrieving one by one sorts by rownum (or unique #)

  • Sales Order (VA01)- Addtional Data Tab B Request

    Hi All,,
    This is sales order(VA01) relevant and I have added the new "ZZFIELD" field in the "Additional data B" which i kept screen painter attributes check box chosen "Input Field" and Input "required".
    When i am creating sales order(VA01), the moment click on "addtional data B"  ZZfield become mandatory input field able to save sales order sucessfully after keying data. But user want's, after enter line item data which is material & qty , then cursor required to go additional data B which is mandatory field ZZFIELD. Right now, user enters line item material , qty and he is able to save it Sales order  and cursor is not going or waiting at ZZFIELD in addtional data B Tab(unless and unitl he press Additional data B Tab) .
    Is there any solution after user enter material and qty after clicking enter cursor should go "Additional data B" wait at "ZZFIELD"(as this mandatory field before sales order save) ? 
    If we dont go the Additional data B and save the document , it's not giving the message "Make an Entry required fields and it is directly saving the document.?
    Any help is highly approciate ....
    Below code written already:
    Program:SAPMV45A screen :8459 put PBO code as per below:
    Loop at Screen.
    If screen-name = 'VBAP-ZZFIELD'.
      if SY-TCODE = 'VA01' AND ORDERTYPE = 'ZSS'
        SCREEN-INPUT = 1.
       MODIFY SCREEN.
      ENDIF.
    ENDIF.
    Best Regards
    Kushal

    Hi   Abdul ,
    You dont have to do ny extra coding for the scroll bar once the no of fields increase with respect to the tsb screen area it will automatically have a scroll bar in it .
    Hope it helps
    Regards
    Swapnil

  • Strange problem with results ordering

    Hi!
    I select some varchar2 data and order them:
    SELECT rownum, xyz FROM analitika where xyz <= 'ABC' order by xyz
    This is pretty straightforward, no problems expected here, right? However, the results, when read as they pour in, are not ordered. I get something like
    3 abc
    1 aaa
    2 abb
    Rownums are assigned correctly, but the data has not been sent in correct order. I feel this has something to do with connection settings, that it is set to return any results as quickly as possible.
    The database is 10g XE on fedora core 4.

    Ok, here is the actual data from the database (copy/paste from helpdb). I have removed rownum from the query because it seems to cause confusion.
    Please notice these things:
    A.A.M.-MIHALINEC kd
    A&B doo
    A.B.A. D.O.O.
    The sequence of rows beginning with "A." should not have been interrupted by the row beginning with "A&". There are more examples. BTW, shouldn't numbers come before letters?
    After I have looked closer, it seems that oracle has disregarded any non-alphanumeric characters when sorting.
    SELECT naziv from analitika where naziv <= 'ABC' order by naziv
    NAZIV
    A & B d.o.o.
    A CETIRI INFO d.o.o.
    A KAJ
    A KONZALTING
    A S I
    A&A
    AAG DIZAJN CENTAR d.o.o. ZAGREB
    AAG DIZAJN CENTAR d.o.o. ZAGREB
    A.A.M.-MIHALINEC K.D.
    A.A.M.-MIHALINEC k.d.
    A.A.M.-MIHALINEC kd
    AAP ELEKTRONIK
    AAR
    AARIS
    AB AUTOMATIKA
    AB COLOR d.o.o.
    AB COMERCE D.O.O.
    AB DIZAJN - VL. MIRA BILIC
    A&B doo
    AB GRADNJA OBRT
    AB INTELCOM
    AB PETROL PROMET
    AB SITOTISAK
    A.B.A. D.O.O.
    A.B.A. DOO
    ABA VELA
    ABACUS
    ABACUS - OBRT
    ABACUS d.o.o. VRBOVEC
    ABAK INŽENJERING
    ABAKUS
    ABAK-US DOO
    ABAKUS RACUNALA
    ABATON
    ABATON D.O.O.
    ABATOURS
    ABB d.o.o. KARLOVAC
    ABB d.o.o. ZAGREB
    ABB d.o.o. ZAGREB
    ABBA D.O.O.
    ABBOTT LABORATORIES S.A. Diagnostics
    A.B.I.G
    A.C.N. D.O.O.
    A/D ELECTRONIC D.O.O.
    A/D ELECTRONIC d.o.o.
    A.D. VIŠNJAN
    A.D.C. d.o.o.
    A-DESIGN
    A!DESIGN OBRT
    A.D.INFORMATICKI SUSTAVI d.o.o.
    A.D.-PROMET d.o.o.
    A.D.Z.SARŠON
    A.H. - ZAGREB d.o.o.
    A.H.TRGOVINA d.o.o.
    A.K.S. d.o.o.
    A-KUD
    A.M. ELEKTRONIK - OBRT, VL. ANIC M.
    A-MAR d.o.o.
    A.M.E.C.
    A.M.E.C. d.o.o.
    A.M.H. d.o.o.
    A.M.-HIDRAULIKA
    A.M.-HIDRAULIKA
    A.M.I. LOVREKOVIC d.o.o.
    A.M.S. CONTO D.O.O.
    A.M.T. PETRAVIC
    A.N.A.B.A.R. TOURS
    A.P. FRIGO
    A-PROMA
    A.R.M.A.C.O.M. d.o.o.
    A.R.Z.
    A.S. REVIZOR D.O.O.
    A.S.B.
    A.S.D.
    A.S.I. d.o.o.
    A.S.TEKS D.O.O.
    A.S.T.-PROM d.o.o.
    A.Š. HAJDUK
    A.Š.-GAZELA D.O.O.
    A-TEL
    A.T.O.S. ELECTRONIC d.o.o.
    A.V.V.I.S.
    A.Z. PROMET
    A.Z.I.L.
    A1 CENTAR D.O.O.
    /popuniti sa drugim kupcem
    007 MILETIC k.d.
    2. A.M. D.O.O.
    2 A.M. doo
    2. GARDIJSKA BRIGADA MORH
    2 I d.o.o.
    2 N
    2D IMPULS d.o.o.
    2M COMPUTERS d.o.o. BLOKADA!
    2M D.O.O.
    3 C CONING
    3 DK d.o.o.
    3 Ka
    3 M
    3 M ŠPORT
    3. MAJ BRODOGRADILIŠTE d.d.
    3. MAJ MOTORI I DIZALICE d.d.
    3. MAJ OEK
    3. MAJ TIBO d.d.
    3 P-T
    3 R
    3 V
    3 Z
    3D STUDIO LEON
    3K d.o.o.
    3M DOO
    3T.CABLE d.o.o.
    312 ARHIT. RADIONICA
    32 BITA d.o.o.
    36 d.o.o.
    4 - MATE D.O.O.
    4 D
    4 IPO SOBE
    40-BOX
    5 F
    5. KRUNA
    5 M
    5 M d.o.o.
    5DO12 d.o.o.
    5DO12 d.o.o.
    5V-LAB
    7 INVENT
    128 rows returned in 0.01 seconds

  • Issue in Transact Move order while updating serial number

    Hi All,
    We need to perform sales order issue of items present in particular subinventory.
    I am successful in creating sales order having one item .
    I did the pick release of the order using the api ,wsh_picking_batches_pub.create_batch and wsh_picking_batches_pkg.submit_release_request to release the batch.
    A move order got created , now I need to allocate the serial number for processing the move order,I used the below script to update the line record with incoming start and end serial number.
    But the api is throwing error .
    DECLARE
    -- Common Declarations
       l_api_version      NUMBER                                 := 1.0;
       l_init_msg_list    VARCHAR2 (2)                          := fnd_api.g_true    ;
       l_return_values    VARCHAR2 (2)                         := fnd_api.g_false;
       l_commit           VARCHAR2 (2)                         := fnd_api.g_false;
       x_return_status    VARCHAR2 (2);
       x_msg_count        NUMBER                                 := 0;
       x_msg_data         VARCHAR2 (255);
       -- WHO columns
       l_user_id          NUMBER                                 := -1;
       l_resp_id          NUMBER                                 := -1;
       l_application_id   NUMBER                                 := -1;
       l_row_cnt          NUMBER                                 := 1;
       l_user_name        VARCHAR2 (30)                          := 'OPERATIONS';
       l_resp_name        VARCHAR2 (30)          := 'MFG_AND_DIST_SUPER_USER_APS';
       -- API specific declarations
       l_header_id        NUMBER                                 := 0;
       l_trohdr_rec       inv_move_order_pub.trohdr_rec_type;
       l_trohdr_val_rec   inv_move_order_pub.trohdr_val_rec_type;
       l_trolin_tbl       inv_move_order_pub.trolin_tbl_type;
       l_trolin_val_tbl   inv_move_order_pub.trolin_val_tbl_type;
       x_trolin_tbl       inv_move_order_pub.trolin_tbl_type;
       x_trolin_val_tbl   inv_move_order_pub.trolin_val_tbl_type;
       x_trohdr_rec       inv_move_order_pub.trohdr_rec_type;
       x_trohdr_val_rec   inv_move_order_pub.trohdr_val_rec_type;
    -- Cursor to load Move Order Headers
    -- CURSOR c_mo_hdrs IS
    -- SELECT * FROM my_custom_move_order_hdrs ;
    BEGIN
       fnd_global.apps_initialize (5939, 50625, 20003);
       mo_global.init ('INV');
       -- call API to create move order header
       DBMS_OUTPUT.put_line
                       ('=======================================================');
       DBMS_OUTPUT.put_line ('Calling INV_MOVE_ORDER_PUB.Get_Move_Order API');
       inv_move_order_pub.get_move_order (p_api_version_number      => l_api_version,
                                          p_init_msg_list           => l_init_msg_list,
                                          p_return_values           => l_return_values,
                                          x_return_status           => x_return_status,
                                          x_msg_count               => x_msg_count,
                                          x_msg_data                => x_msg_data,
                                          p_header_id               => 7360068,
                                          p_header                  => NULL,
                                          x_trohdr_rec              => l_trohdr_rec,
                                          x_trohdr_val_rec          => l_trohdr_val_rec,
                                          x_trolin_tbl              => l_trolin_tbl,
                                          x_trolin_val_tbl          => l_trolin_val_tbl
       DBMS_OUTPUT.ENABLE ();
       DBMS_OUTPUT.put_line
                        ('=======================================================');
       DBMS_OUTPUT.put_line ('Return Status: ' || x_return_status);
       IF (x_return_status <> fnd_api.g_ret_sts_success)
       THEN
          DBMS_OUTPUT.put_line ('Error Message :' || x_msg_data);
       END IF;
       -- Print the Move Order Header/Lines to be processed
       IF (x_return_status = fnd_api.g_ret_sts_success)
       THEN
          DBMS_OUTPUT.put_line (   'Header :'
                                || l_trohdr_rec.header_id
                                || ' '
                                || l_trohdr_rec.request_number
                                || ' '
                                || l_trohdr_rec.date_required
                                || ' '
                                || l_trohdr_rec.from_subinventory_code
                                || ' '
                                || l_trohdr_rec.header_status
                                || ' '
                                || l_trohdr_rec.organization_id
                                || ' '
                                || l_trohdr_rec.status_date
                                || ' '
                                || l_trohdr_rec.to_subinventory_code
                                || ' '
                                || l_trohdr_rec.transaction_type_id
                                || ' '
                                || l_trohdr_rec.move_order_type
                                || ' '
                                || l_trohdr_rec.operation
          l_trohdr_rec.from_subinventory_code := 'CustRet';
          --l_trohdr_rec.to_subinventory_code := 'Staging';
          l_trohdr_rec.operation := inv_globals.g_opr_update;
          DBMS_OUTPUT.put_line (   'Header Update :'
                                || l_trohdr_rec.header_id
                                || ' '
                                || l_trohdr_rec.from_subinventory_code
                                || ' '
                                || l_trohdr_rec.to_subinventory_code
                                || ' '
                                || l_trohdr_rec.operation
          FOR i IN 1 .. l_trolin_tbl.COUNT
          LOOP
             DBMS_OUTPUT.put_line (   'Line '
                                   || i
                                   || ': '
                                   || l_trolin_tbl (i).line_id
                                   || ' '
                                   || l_trolin_tbl (i).line_number
                                   || ' '
                                   || l_trolin_tbl (i).line_status
                                   || ' '
                                   || l_trolin_tbl (i).organization_id
                                   || ' '
                                   || l_trolin_tbl (i).inventory_item_id
                                   || ' '
                                   || l_trolin_tbl (i).from_subinventory_code
                                   || ' '
                                   || l_trolin_tbl (i).to_subinventory_code
                                   || ' '
                                   || l_trolin_tbl (i).quantity
                                   || ' '
                                   || l_trolin_tbl (i).status_date
                                   || ' '
                                   || l_trolin_tbl (i).uom_code
                                   || ' '
                                   || l_trolin_tbl (i).operation
             l_trolin_tbl (i).from_subinventory_code := 'CustRet';
             --l_trolin_tbl (i).to_subinventory_code := 'Staging';
             --l_trolin_tbl (i).inventory_item_id := 19128;
             l_trolin_tbl (i).serial_number_start := '356030032497361';
             l_trolin_tbl (i).serial_number_end := '356030032497361';
             --l_trolin_tbl(i).quantity       := l_trolin_tbl(i).quantity
             l_trolin_tbl (i).operation := inv_globals.g_opr_update;
             DBMS_OUTPUT.put_line (   'Line Updated'
                                   || i
                                   || ': '
                                   || l_trolin_tbl (i).line_id
                                   || ' '
                                   || l_trolin_tbl (i).from_subinventory_code
                                   || ' '
                                   || l_trolin_tbl (i).to_subinventory_code
                                   || ' '
                                   || l_trolin_tbl (i).serial_number_start
                                   || ' '
                                   || l_trolin_tbl (i).serial_number_end
                                   || ' '
                                   || l_trolin_tbl (i).operation
          END LOOP;
       END IF;
       DBMS_OUTPUT.put_line
                        ('=======================================================');
       -- call API to create move order header
       DBMS_OUTPUT.put_line
                        ('=======================================================');
       DBMS_OUTPUT.put_line ('Calling INV_MOVE_ORDER_PUB.Process_Move_Order API');
       inv_move_order_pub.process_move_order
                                           (p_api_version_number      => l_api_version,
                                            p_init_msg_list           => l_init_msg_list,
                                            p_return_values           => l_return_values,
                                            p_commit                  => l_commit,
                                            x_return_status           => x_return_status,
                                            x_msg_count               => x_msg_count,
                                            x_msg_data                => x_msg_data,
                                            p_trohdr_rec              => l_trohdr_rec,
                                            p_trohdr_val_rec          => l_trohdr_val_rec,
                                            p_trolin_tbl              => l_trolin_tbl,
                                            p_trolin_val_tbl          => l_trolin_val_tbl,
                                            x_trohdr_rec              => x_trohdr_rec,
                                            x_trohdr_val_rec          => x_trohdr_val_rec,
                                            x_trolin_tbl              => x_trolin_tbl,
                                            x_trolin_val_tbl          => x_trolin_val_tbl
       DBMS_OUTPUT.put_line
                        ('=======================================================');
       DBMS_OUTPUT.put_line ('Return Status: ' || x_return_status);
       IF (x_return_status <> fnd_api.g_ret_sts_success)
       THEN
          DBMS_OUTPUT.put_line ('Error Message :' || x_msg_data);
          ROLLBACK;
         ELSE
         COMMIT;
       END IF;
       DBMS_OUTPUT.put_line
                        ('=======================================================');
    -- END LOOP;
    EXCEPTION
       WHEN OTHERS
       THEN
          DBMS_OUTPUT.put_line ('Exception Occured :');
          DBMS_OUTPUT.put_line (SQLCODE || ':' || SQLERRM);
          DBMS_OUTPUT.put_line
                       ('=======================================================');
    END;
    Error Log
    =======================================================
    Calling INV_MOVE_ORDER_PUB.Get_Move_Order API
    =======================================================
    Return Status: S
    Header :7360068 7360067 15-JUL-13  7 281 15-JUL-13   3
    Header Update :7360068 CustRet  UPDATE
    Line 1: 6730069 1 7 281 19119  Staging 1 15-JUL-13 UN
    Line Updated1: 6730069 CustRet Staging 356030032497361 356030032497361 UPDATE
    =======================================================
    =======================================================
    Calling INV_MOVE_ORDER_PUB.Process_Move_Order API
    Inv Item Id19119
    Old Inv Item Id19119
    Inv Item Id-356030032497361
    Item Id
    Org Id281
    Serial Number356030032497361
    =======================================================
    Return Status: E
    Error Message :INV_INV_INVALID_ATTRIBUTE_N_ATTRIBUTE_Start serial number
    Please help to solve the issue.
    Thanks,
    Shruti K. Nayak

    Hello Ganesh,
    Hope you have passes this issue.
    I am in the same boat, I need to find out the APIs to update the serial numbers on order at the time of allocation/transact move order step.
    Could you please help me with the process/steps/sample code involved in this.
    Thanks in advance!
    Raj

  • BLANKET SALES ORDER의 DATA가 ORDER의 DEFAULT 값으로 되지 않는 이유?

    제품 : MFG_OM
    작성날짜 : 2004-10-12
    BLANKET SALES ORDER의 DATA가 ORDER의 DEFAULT 값으로 되지 않는 이유?
    ===================================================================
    PURPOSE
    Blanket Sales Agreement form에서 Create Release button을 선택하면
    Blanket Sales Agreement의 정보들이 Sales Order form의 default 값으로
    입력되어 보여야 하나 현재는 Sales Order form은 open 되지만 header나
    line에 blanket의 data가 populated 되지 않는다.
    이 note에서는 그 원인과 해결책을 알아본다.
    Explanation
    Change(s)
    =========
    Blanket Sales Agreement는 정의 되어 있고, Customer 정보는 Header에 입력
    되어 있다. 또한 Line item은 특정 products을 위해 정의되어 있다.
    Blanket agreement는 blanket order type과 연관되어 있다.
    원인
    ====
    보통 Agreements에 대한 Orders/Releases를 신청하는 Customers는 먼저
    folder를 만들어야만 한다. 이 folder는 order header에 blanket number
    field는 가지며 default folder로 저장되야 한다.
    Blanket Sales Agreement form에서 Create Release button을 click 하면
    Sales Order form이 열리고 cursor는 blanket agreement field로 이동할
    것이다.
    User가 다른 field로 tab을 하면 customer data는 blanket에서 release
    order로 default 조회된다.
    만약 Customer data가 아닌 다른 data를 blanket agreement에서 release
    order로 default 하길 원한다면, 먼저 그 영향을 주는 defaulting rule을
    생성해야 한다.
    Fix
    =====
    Blanket으로부터 data를 default로 받길 원하면 Sales order header와
    line에 있는 모든 field에 대한 defaulting rules은 정의되어져 있어야 한다.
    Defaulting rule에서 defaulting source로 'Blanket'을 이용하여 가능하다.
    Example
    Price List는 blanket agreement의 값을 default로 해야 하는 business rule
    이 있다면, Price List의 defaulting rules을 아래와 같이 변경한다.
    Price List First Default
    =========================
    Source Type : Related Record
    Default Source : Blanket Agreement
    위와 같은 rules은 blanket header를 sales order header default로 하거나
    blanket line을 sales order line의 default로 하려면 먼저 생성되어져야
    한다.
    Reference Documents
    Note 253150.1

Maybe you are looking for

  • During Excise invoice capturing, BED and other duties not coming

    Hi experts, During Excise capturing with j1iex_c t-code for scheduling w.r.t. scheduling agreement, BED and other excise duties are not coming automatically. But in case of other scheduling agreements all the duties are coming l...what could be the r

  • Default reversal period in GL

    Hi, i have a doubt. I need to have a default period when i create a reversal batch. I know in release 11i there is an automatic method to submit reversal journal by category, but the user want to select a batch to reverse and the new reversal journal

  • AsyncOS 5.5.1-014 for Email is now available

    UPDATE: 2008-2-26 5.5.1-014 releases: This release includes a number of fixes: * Fixed: Appliances Are Not Generating SNMP Traps * Fixed: Leftover Files Are Deposited in scanning_temp_files Directory * Fixed: DNS-Related Memory Issues Delay Acceptanc

  • Aperture won't allow update vault

    since update to 10.8 I've been having problems with aperture like vault wont update(will freez up), dodge&burn tools not working right, overall performance slow. I trashed the app and reloaded seems somewhat better but my computer still freezes when

  • Change existing stock items from Non-Batch to Batch Management Method

    Hi, Any prerequisites before changing the existing stock items from Non-Batch to Batch Management method which have On hand stock qty? Please advise. Thanks & Regards, Priscilla