Numbering query results with a line number in SQL*Plus

Doesn't it stand to reason that in SQL*Plus there would be a way to number each query results sequentially with line numbers starting at 1 to n -- something option like from a SET command? I'm not talking about linesize.

There's a column rownum the engine adds into the result sets, just add it to the select list. Can use it to limit the result set (with some limitations) i.e.:
select rownum, ... from ... where rownum <= 100
Can't use ">=", that condition will never be met but a subset could be used:
select * from ( select rownum as linenr, tab1.* from ... ) where linenr between 10 and 20

Similar Messages

  • Script for Save Options- Save Query Results with document

    Hi,
    Is there any javascript for Save query results with document in save options? If so where can i find that?
    Thanks
    Kalai

    hi guys,
    I found the answer.The following example shows you how to save the results with the query
    section named “SalesQuery”.
    ActiveDocument.Sections["SalesQuery"].SaveResults=true

  • Line Order No doesnt match with Invoice line number

    At the line level , the line order no doesnt match with the invocie line number
    ie. say for example in a sales order we have 3 lines
    1. A
    2. B
    3. C
    where as in transaction at AR level the line no is different
    1. B
    2. A
    3. C
    the customer wants in AR also the line no should be same as sales order line nos
    Please help us what is the setup where we define the line level numbering in AR.
    I have checked the line ordering rules but i am not clearly understanding, if anyone can explain with an example how this no generates witht he setup details it would be great

    This can be done in XSL OR in procedure on the DB side. Performance wise better to do in procedure as mentioned by other use. You can choose to go with DB or XSL approach depending on number of orders you are expecting in a single message. If it is going to be 100s or few thousand messages then keeping it in XSL is not a problem. But if you are planning tens or hundreds of thousands of orders in the same request then better do it in stored procedure.
    How do you do in XSL?
    1. Put a for each on every unique order no. You can use xsl:Key or xslt:distinct-values() for this.
    2. Within for each unique value of order no, use position() function to pass line/order no as 1,2,3... etc. As soon as the loop moves to second iteration for the next unique order no, count will automatically start again from 1,2,3... and so on.
    Apart from slightly slower processing time, another drawback from this approach is that the data in the XML you send to DB procedure will be sorted by order numbers. All orders with same number will appear together.
    Another problem with this approach is that this will work only within one request, i.e. if the next request contains an order with same no which was already sent in a previous request, for this order the count will again start from 1. So if you want to keep the sequencing maintained across multiple requests, the easiest way to do is in the DB procedure where you can lookup in the table before inserting a new row and insert with next sequence of that order no.

  • Incorrect query results with conformResultsInUnitOfWork

    Hi,
    has anybody experienced this:
    Take two classes User and Group
    Group has a 1:n Mapping to User (attribute users)
    User has a 1:1 Mapping to User (attribute partner).
    Following query returns too many objects
    User user1 = someUserObject;
    ReadAllQuery readAllQuery = new ReadAllQuery(Group.class);
    Expression e = builder.anyOf("users").get("partner").equal(user1);
    readAllQuery.setSelectionCriteria(e);
    readAllQuery.conformResultsInUnitOfWork();
    Vector vector = (Vector) unitOfWork.executeQuery(readAllQuery);
    It returns
    - the correct Group object as determined from the sql query +
    - any other objects of the same class that are fully instantiated (users is instantiated and for each user, partner is instantiated), even if they don't conform to the expression.
    The same query works properly ;
    - without conformResults
    - or if the other objects are not fully instantiated

    Hi,
    we need an workaround badly and the support is moving at exactly the rate I feared it would.
    So I thought, since we only hit this bug with existing objects and we use conformResultsInUnitOfWork because we want to find the newly created objects, is there a way to get
    - the SQL Query results
    + any new objects that conform to the query
    We still might get new objects that don't conform to the query (this is the bug) but I'll worry about that later if it happens.
    My first attempt at a solution looks like this:
    1. turn off conformResults
    2. manually add all new objects that conform to the query
    I had to guess a little for 2, since I don't know what exactly toplink does to select the "conform" objects.
    private static List findConformNewObjects(UnitOfWork unitOfWork, ReadAllQuery query) {
    List result = new ArrayList();
    Class resultClass = query.getReferenceClass();
    Expression selectionCriteria = query.getSelectionCriteria();
    Enumeration enumeration;
    IdentityHashtable newObjectsCloneToOriginal = unitOfWork.getNewObjectsCloneToOriginal();
    if (newObjectsCloneToOriginal != null && newObjectsCloneToOriginal.size() > 0)
    enumeration = newObjectsCloneToOriginal.keys();
    while (enumeration.hasMoreElements())
    Object o = enumeration.nextElement();
    if (resultClass.isInstance(o))
    if (selectionCriteria != null && selectionCriteria.doesConform(o, unitOfWork, null, query.getInMemoryQueryIndirectionPolicy()))
    result.add(o);
    return result;
    Does this look OK to you? Is there a better way to do it?
    Ana

  • Copy BW query results with formatting

    When copying a query's results to another workbook, the formatting (namely coloring) changes.  Is there any way to copy the query results to a new workbook and keep the exact same formatting as in original query?

    One way to do this would be to copy the worksheet with the results to the other workbook, as follows:
    Edit --> Move or copy sheet... --> change "To book:" to the 2nd workbook --> check "Create a copy" option --> OK
    After doing that, you can cut & paste from the copied worksheet to other worksheets in the workbook, if necessary, and the formatting will be maintained.
    Hope this helps...
    Bob

  • Query Results not coming for SELECT * in sql developer 3.1.07

    VERY FRUSTRATING to use sql developer.
    In SQL DEVELOPER 3.1.07:
    WHAT WORKS: select sequence# from v$archived_log
    WHAT DOESN'T WORK : select * from v$archived_log
    You've got to be kidding me.
    I wish I can show a screenshot, but can't in this forum. Here's my description:
    When I run the query, in the bottom frame for Query Results, it just says: Executing: select * from v$archived_log in 0 seconds.
    Then there's no result grid.
    WOw

    >
    This was when connected to a standby db that's in mount state
    >
    Is this a 'manual' standby db? Are you using Data Guard?
    Post the results for what Gary ask of running the queries in sql*plus. If those queries give the same result then this is NOT a sql developer issue.
    Review the following thread and post back with what information in it applies to your use case.
    Re: V$ARCHIVED_LOG returns no rows on manual standby
    If you are using Data Guard you may want to cross-post in that forum.

  • How can I architect my data layer to yield query result pages to the application as SQL Server prepares them?

    I tried to make the question as explicit as possible.
    Refer to Sql Server Management Studio's Results view.  Depending upon the structure of the execution plan, the Results pane may begin displaying results while the query is still executing.  Can someone point me in a direction for architecting a
    data layer (I am tech and framework agnostic for this task. Any solution will suffice) that will begin receiving pages of the set before SQL Server has completed the entire query?
    The call from the data layer to SQL Server will obviously have to be asynchronous, but is there any additional ceremony that I need to be aware of when issuing OPTION (FAST x) to the query optimizer?

    Thanks for the reply. (I actually meant to put this in the SQL Data Access forum, not the T-SQL forum)
    "Generally the last step is ORDER BY in a
    query, so nothing can start before that executes."
    I would imagine you cannot ORDER BY and yield results as they are fetched because of the execution plan that would be generated.  For the purposes of this post, please assume that sorting will be done purely client side
    "Can you post your query?"
     For purposes of discussion, let's assume that the query is
    select *
    from information_schema.columns
    and also assume that you have "lots" of columns to display.
    This was an exploratory question to see what would be necessary to replicate the behavior of Management Studio's Query Result view in a custom application. 
    I would imagine that there's going to be a lot of analysis of the execution plans that get generated in order for the OPTION (FAST x) optimizer hint to do any good, but apart from general tuning concerns that would allow SQL SERVER to yield a page of data
    "fast", I was wondering if there was anything else required of the calling client to force it to yield return its first page.
    After thinking about this (and phrasing it the way I did in the last sentence) perhaps this is the incorrect forum for this question.  I imagine that my concerns are better addressed in forums dedicated to the technology of the calling client (which
    would be a .NET assembly)
    Be that as it may, if there is any ceremony that SQL Server imposes on clients in order to yield return, I would expect that my question would be in the scope of SQL Server discussions (even though I intended this to be in a different SQL Server forum)

  • A query runs in under 1 minute is sql plus, but takes 15 in Discoverer

    I have a query that runs in under 1 minute is sql plus, but takes 15+mins in Discoverer. I use 3 parameters in discoverer which i specify as conditions in sql plus query. Any ideas on how to make it run faster??? BTW the query returns 10,000+ records. There is no formatting or sorting involved. Any ideas??? Seems the query execution plan is wrong...

    Hi,
    I agree with Michael to check your preference settings. Particulary since Plus/Viewer reads the pref.txt on the middle-tier and Desktop reads each individual PC registry.
    I would start with checking Query Prediction setttings.
    Try turning off Query Prediction. If it is not setup properly it can cause a delay. This is one difference between Discoverer and SQL*PLUS
    See forum post:
    Re: 20 mins and still predicting!!
    Re: Different Performance between Desktop-Query and SQL-Plus
    Hope that helps,
    Steve.

  • Error creating view with CASE -- WHEN statement in SQL*Plus

    I am using Oracle 8i 8.1.7
    I have an Oracle view which uses CASE...WHEN statements.
    The view compiles fine in DBA studio.
    Using TOAD I saved the view as an *.sql file.
    However, when I try to create the view in SQL*Plus I get the following error:
    SP2-0734: unknown command beginning "CASE WHEN ..." - rest of line ignored.
    According to the documentation CASE -- WHEN has been implemented since since Oracle 8i rel. 2 (8.1.6)

    Well I'm using 8.1.6.3 and CASE and DECODE both work for me:
    SQL> create or replace view v_accs as select account_name, txn,
    2 decode(credit, 0, 'DB', 'CR') t_type
    3 from accs;
    View created.
    SQL> select * from v_accs;
    ACCOUNT_NA TXN T_
    APC 1 DB
    ABC 2 DB
    HJJ 3 DB
    HJH 4 CR
    HJK 5 CR
    APC 6 DB
    APC 7 DB
    ABC 8 DB
    ABC 9 DB
    HJJ 10 DB
    HJJ 11 DB
    HJH 12 DB
    HJH 13 DB
    HJK 14 DB
    HJK 15 CR
    15 rows selected.
    SQL> create or replace view v_accs as select account_name, txn,
    2 case when credit = 0 then 'DB' else 'CR'end as t_type
    3* from accs
    View created.
    SQL> select * from v_accs;
    ACCOUNT_NA TXN T_
    APC 1 DB
    ABC 2 DB
    HJJ 3 DB
    HJH 4 CR
    HJK 5 CR
    APC 6 DB
    APC 7 DB
    ABC 8 DB
    ABC 9 DB
    HJJ 10 DB
    HJJ 11 DB
    HJH 12 DB
    HJH 13 DB
    HJK 14 DB
    HJK 15 CR
    15 rows selected.
    SQL>
    rgds, APC

  • Incorrect query result with Top N condition and two structures

    Hi,
    I have created a query on a FI-GL infocube with the characteristic 0BUS_AREA in rows and two structures in columns. The first structure has two items / selections (each item is a selection of several GL accounts). The second structure has two items (the first one contains the key figure 0BALANCE for the current period and the second item is a formula that calculates the absolute value of the first item. The first item is hidden). The (simplified) result looks like this (sorry, not very pretty!):
    Business Area Clients Clients fae
    Business Area1 10 15
    Business Area2 20 7
    Business Area 3 15 8
    Overall result 45 30
    I then added one condition using the Top N operator. The condition is defined for all the elements of the structures. When I execute the query, I sometimes obtained an incorrect number of Top N records selected. The problem seems to occur when N is greater than the number of available Business Areas for an element of the structure.
    For example, if N = 8 and data only exists for 5 Business Areas for the structure element Clients, I may end up with 10 Business Areas for the second structure element Clients fae when I only expect 9 (i.e. the top 8 Clients fae + 1 of the Top 8 Clients for which there is no data under Clients fae).
    Has anybody encoutered that kind of problem ?
    Many thanks.
    François.

    Pascal,this is a known behavior with conditions.When you apply condition it just hide the extra rows and it does not impact the result row.So your result row actually shows the value irrespective of the condition you apply.
    Now with the help of local functions like calculate result as summation you can show the correct sum after applying the condition but when you try to use that result in some calculation then it takes the original value thereby discarding the calculated value.
    Same is happening in your case as well.Its taking the original value i.e 350 and not the calculated sum after condition i.e 270.
    Hope this helps.
    Regards,
    AL

  • Question about different query results with wildcard

    Hi, I'm working with a third party app on SQL Server 2000, and from what I can gather, programmed in C# & VisualFoxPro.
    When we search with
        Note contains 94949
    we get 571 results, when we search with
        Note contains 94949*
    we get 575 results.
    There should be at least a hundred different entries that start with "94949-1" so I expected the query with the wildcard to return something like 680 results, not an additional four rows.
    Searching with
        Note contains 94949-1*
    got 483 results
        Note contains 94949-10*
    got 0 results
    Could someone explain or point me to more documentation on the difference results we get?
    Thanks

    Hi Arnie, thanks for your response.
    My situation is more basic than what appears in your example. Unfortunately, I am working solely through this application so I do not have access to the SQL to test out what you supplied, so my question is more of a need for an explanation of the search results. I do find lots of references to LIKE, Wildcards and pattern matching, but I don't find a way to explain to the users the best and most complete way to search. They mostly need a "this will always get us the results without missing anything" search technique and then to be able to select from a smaller group. I guess I need a basic course in understanding search results: how to get different ones and what they mean.
    Using 
            Note contains 94949-'%'
    returned one more result than when using an asterisk. I don't understand this difference.
            Note contains 94949-'%1'   or
            Note contains 94949-'1%'
    brings nothing nor does not using quotes. But there are hundreds of records which have the string starting with 94949-1 and a varying number of characters after that.
    ?Does the dash read not as a character in the string but as an expression?
    When I use WITHIN 3 characters, I get too few results (eight). If I use AND, I get text unrelated to the account number I am looking for.
    Again when I tried to narrow the search by adding one digit to the string to be matched, I did not get any results, but 500 results from the more general search is too much to scan by opening individual records.
    Thanks for pondering this with me.

  • SQL Query Result with Random Sorting

    Hi Experts,
    My Oracle Version : Oracle9i
    I have three tables which are given below,
    Table Name:     check_team
    team_id      team_code
    100          A
    101          B
    102          C
    103          D
    Table Name:     check_product
    product_id     product_code
    1          XXX
    2          XYZ
    Table Name:     check_team_products
    tprod_id     tprod_team_id     tprod_product_id
    1          100          1
    2          100          2
    3          101          1
    4          101          2
    5          102          1
    6          102          2
    7          103          1
    8          103          2
    Required Output First Time:
    team_id   team_code   product_id   product_code
    100       A           1             XXX
    101       B           2             XYZ
    102       A           1             XXX
    103       B           2             XYZ
    Required Output Second Time:
    team_id   team_code   product_id   product_code
    100       B           2             XYZ
    101       A           1             XXX
    102       B           2             XYZ
    103       A           1             XXXI need the result as Required Output specified above and also the result has to be random too.. Can someone help me in writing a SQL Query to get results as that?
    Added Oracle Version

    So, is it something like this you want?
    SQL> ed
    Wrote file afiedt.buf
      1  with check_team as (select 100 as team_id, 'A' as team_code from dual union all
      2                      select 101, 'B' from dual union all
      3                      select 102, 'C' from dual union all
      4                      select 103, 'D' from dual)
      5      ,check_product as (select 1 as product_id, 'XXX' as product_code from dual union all
      6                         select 2, 'XYZ' from dual)
      7      ,check_team_products as (select 1 as tprod_id, 100 as tprod_team_id, 1 as tprod_product_id from dual union all
      8                               select 2, 100, 2 from dual union all
      9                               select 3, 101, 1 from dual union all
    10                               select 4, 101, 2 from dual union all
    11                               select 5, 102, 1 from dual union all
    12                               select 6, 102, 2 from dual union all
    13                               select 7, 103, 1 from dual union all
    14                               select 8, 103, 2 from dual)
    15  --
    16  -- end of test data
    17  --
    18  select team_id, team_code, product_id, product_code
    19  from (
    20        select t.team_id, t.team_code, p.product_id, p.product_code
    21              ,row_number() over (partition by team_id order by dbms_random.random()) as rn
    22        from check_team t join check_team_products tp on (tp.tprod_team_id = t.team_id)
    23                          join check_product p on (p.product_id = tp.tprod_product_id)
    24       )
    25* where rn = 1
    SQL> /
       TEAM_ID T PRODUCT_ID PRO
           100 A          2 XYZ
           101 B          1 XXX
           102 C          2 XYZ
           103 D          1 XXX
    SQL> /
       TEAM_ID T PRODUCT_ID PRO
           100 A          2 XYZ
           101 B          1 XXX
           102 C          2 XYZ
           103 D          1 XXX
    SQL> /
       TEAM_ID T PRODUCT_ID PRO
           100 A          1 XXX
           101 B          2 XYZ
           102 C          1 XXX
           103 D          1 XXX

  • Bug: query results sometimes lose line formatting

    Steps:
    1. Run a query on "arraycollection adobe flex null pointer"
    Result: the 2nd search result "Flex 3 - Using the HitData object" from http://livedocs.adobe.com/flex/3/html/charts_eventsandeffects_03.html has all the line-ends removed (see 1st screenshot). When I go to the URL, the code looks OK (see 2nd screenshot), so it seems likely that Blueprint is somehow mangling the file.

    Thanks for you feedback! We have filed a bug to address code formatting problems. Stay tuned for the next release.
    Mira Dontcheva
    Research Scientist
    Adobe Systems

  • Problems in query result with infoset and timedep infoobject

    Hi,
    I have the following situation:
    infoobject ZEMPLOYEE timedep
    Infocube 0C0_CCA_C11 (standard cost center/cost element postings)
    -> infoset with infoobject and infocube linked with outer join
    My query should show all active employees in one month without any posting in the infocube.
    My testdata looks like this:
    pernr date from    date to         cost center
    4711  01.01.1000 31.12.2002
    4711  01.01.2003 31.01.2009   400000
    4711  01.02.2009 31.12.9999
    That means the employee is only active between 01.01.2003 and 31.01.2009.
    I expect the following result in the query with key-date 31.01.2009:
    4711  01.01.2003 31.01.2009   400000
    I expect the following result in the query with key-date 01.02.2009:
    no result
    -> because the employee is not active anymore, I don't want to see him in the query.
    My query delivers the following result:
    4711  01.02.2009 31.12.9999
    The first and the last entry in master data is automatically created by the system.
    I tried to exclude the not active employees by selection over cost center in the filter (like cost center between 1 and 9999999, or exclude cost center #). But unfortunately the filter selection does not work, because obviously the attributes are not filled in the last entry.
    Is there anyone who can tell me how I can exclude the last entry in the master data in the query?
    Any help is much appreciated! Points will be assigned!
    best regards
    Chris

    HI,
    problem is that I can't use employe status in this case, beacuse for any reason the people don't use it.
    I have also tried with exceptions and conditions, but the attributes ar enot filled, so it seems that nothing works.
    Do you have any other suggestions?
    Thanks!
    best tregards
    Chris

  • Combine two Query Results with Rank

    Dear All,
    I am business analyst working DB for first time:
    I have two queries:
    1)
    select * from (select "CAFNo","ActionDate","ActionDetail", rank() over (partition by "CAFNo" order by "ActionDate") rnk,
    from "ABC"
    where "ActionDetail"
    like 'CRF successfully submitted and routed to Fulfillment Team%')
    where rnk=1
    Results in
    CAFNo","ActionDate1","ActionDetail"
    2)
    select * from (select "CAFNo","ActionDate","ActionDetail", rank() over (partition by "CAFNo" order by "ActionDate") rnk
    from "ABC"
    where "ActionDetail"
    like '%Customer ID%')
    where rnk=1
    Results in
    CAFNo","ActionDate2","ActionDetail"
    I would like to combine results of two as:
    CAF no, Actiondate1, actiondate2,ActionDetail
    I tried full outer join and other options but with no success. Please help
    Please share concept of joining the two results not the actual query.

    Actually, my query is not equivalent to original. I missed ActionDetail can be something like:
    'CRF successfully submitted and routed to Fulfillment Team A by Customer ID X'Then it fits both LIKE conditions. If such case of ActionDetail is possible then:
    with t as (
                select  *
                  from  (
                         select  1 weight,
                                 "CAFNo",
                                 "ActionDate",
                                 "ActionDetail",
                                 rank() over (partition by "CAFNo" order by "ActionDate") rnk
                           from  "ABC"
                           where "ActionDetail" like 'CRF successfully submitted and routed to Fulfillment Team%'
                  where rnk=1
               union all
                select  *
                  from  (
                         select  2 weight,
                                 "CAFNo",
                                 "ActionDate",
                                 "ActionDetail",
                                 rank() over(partition by "CAFNo" order by "ActionDate") rnk
                           from  "ABC"
                           where "ActionDetail" like '%Customer ID%'
                  where rnk=1
    select  "CAFNo",
            max(
                case weight
                  when 1 then "ActionDate"
                end
               ) "ActionDate1",
            max(
                case weight
                  when 2 then "ActionDate"
                end
               ) "ActionDate2",
            max(
                case weight
                  when 1 then "ActionDetail"
                end
               ) "ActionDetail1",
            max(
                case weight
                  when 2 then "ActionDetail"
                end
               ) "ActionDetail2"
      from  t
      group by "CAFNo"
    /SY.

Maybe you are looking for

  • "you do not have permission to open the application Dictionary"

    I get the above message when I try to open Dictionary from the Dock or the Finder. However if I access Dictionary from Spotlight it opens. I have repaired permissions and trashed the preference file to no effect. Don't use the application much but it

  • How do i get my nokia n8 to print to my officejet pro 8500a?

    Hello Can anyone tell me how to get my Nokia N8 mobile phone to print a photo using HP Officejet Pro 8500A? I have got the wireless connection enabled, but when I select the photo on the phone and click on Print, via Bluetooth connection, the Printer

  • How to read records from Database view

    Hi folks, well...let me know, y im getting error as : V_T52EL is not defined in the ABAP dictionary as Table , Projection view or Database view. But actually here this View Type is : Maitenance View.   SELECT  KOART     from   V_T52EL     where ENDDA

  • JAR using another JAR

    Hi, I have created in Eclipse simple class Blah.class: public class Blah {      public Blah() {           System.out.println("Inside blah"); Then I made a JAR file: C:\Blah.jar Then I made in Eclipse another project with a simple class BlahBlah.class

  • Publishing reports to Crystal server

    This is our firsts year with Crystal  server and the training is forthcoming. In the meantime, I have done the following: