Convert "select top 5 ..." in Oracle8i

-- We are in the process of migrating application from SQLserver7 to Oracle8i,
-- and trying to convert a procedure to return top 5
-- rows given a search string.
-- In SQLserver7, "select top 5 ... "
-- The Oracle8i Application Developer's Guide - Fundamentals
-- recommends to use rownum, the query runs OK in SQL*Plus,
-- but gets error when used in a procedure with returned cursor.
-- Is there any solution for it?
-- Following is the sample query and procedure (in a package)
-- Query returns top 5 rows
select t.rank, t.productid, t.productname
from (
Select score(0) as rank, productid, productname
from Product
where status = 'A'
and contains(productname, 'Frog', 0) > 0
order by rank desc, productid
) t
where rownum < 6;
-- Proc Name: Pr_Test
-- Purpose: Retrieve product data for a specified search string
CREATE OR REPLACE PACKAGE pkg_test
IS
TYPE RT1 IS RECORD (
Rank NUMBER(10),
ProductID Product.ProductID%TYPE,
ProductName Product.ProductName%TYPE
TYPE RCT1 IS REF CURSOR RETURN RT1;
PROCEDURE pr_test
(i_searchstring IN VARCHAR2 ,
io_prdcursor IN OUT RCT1);
END pkg_test;
CREATE OR REPLACE PACKAGE BODY pkg_test
AS
PROCEDURE pr_test
(i_searchstring IN VARCHAR2 ,
io_prdcursor IN OUT RCT1)
IS
BEGIN
OPEN io_prdcursor FOR
select t.rank, t.productid, t.productname
from (
Select score(0) as rank, productid, productname
from Product
where status = 'A'
and contains(productname, i_searchstring, 0) > 0
order by rank desc, productid
) t
where rownum < 6;
END pr_test;
END pkg_test;
-- Following is the error message when compiling the package body:
Warning: Package Body created with compilation errors.
SQL> show error
Errors for PACKAGE BODY PKG_TEST:
LINE/COL ERROR
19/7 PLS-00103: Encountered the symbol "ORDER" when expecting one of
the following:
) * & - + / mod rem with an exponent (**) and or group having
intersect minus start union where connect &#0124; &#0124;
The symbol ")" was substituted for "ORDER" to continue.
20/11 PLS-00103: Encountered the symbol ")" when expecting one of the
following:
. ( , * @ % & - + ; / for mod rem an exponent (**) asc desc
&#0124; &#0124;
-- Run the procedure and get the results
declare
i number := 0;
v_string varchar2(50) := 'CAT';
-- v_string varchar2(50) := 'FROG%';
v_RC1 pkg_test.RCT1;
v_Score NUMBER(10);
v_ProductID Product.ProductID%TYPE;
v_ProductName Product.ProductName%TYPE;
begin
pkg_test.pr_test (v_string, v_RC1);
LOOP
FETCH v_RC1 INTO v_Score,v_ProductID,v_ProductName;
EXIT WHEN (v_RC1%NOTFOUND);
DBMS_OUTPUT.put_line(substr('Score='&#0124; &#0124;v_score&#0124; &#0124;', ProdID='&#0124; &#0124;v_ProductID ,1,255));
i := i + 1;
END LOOP;
DBMS_OUTPUT.put_line('Total '&#0124; &#0124;i&#0124; &#0124;' records retrieved.');
end;
null

http://www.orafaq.org/faqsql.htm#TOP
This may be of use, the plsql cursor declaration syntax may not have all the facilities of runnning the query from sqlplus:
How does one select the TOP N rows from a table?
Form Oracle8i one can have an inner-query with an ORDER BY clause. Look at this example:
SELECT *
FROM (SELECT * FROM my_table ORDER BY col_name_1 DESC)
WHERE ROWNUM < 10;
Use this workaround with prior releases:
SELECT *
FROM my_table a
WHERE 10 >= (SELECT COUNT(DISTINCT maxcol)
FROM my_table b
WHERE b.maxcol >= a.maxcol)
ORDER BY maxcol DESC;
Turloch

Similar Messages

  • ALTERNATIVE FOR 'SELECT TOP STATEMENT

    HI FRIENDS
    IF ANY ONE KNOWS HOW TO CONVERT THE SQL STATEMENT GIVEN BELOW PLEASE HELP ME
    SELECT TOP 1 CardID FROM EasyRechargeMaster WHERE CardGroup = EasyRecharge.CardGroup
    THANKS & REGARDS

    Check this query. It should give you desired results....Are you sure about that? Does TOP 1 mean "whatever happens to be the first row fetched"?

  • "select * from table" and "select top 14260 from table" get nothing but select top 14259 get result successful

    select * from tablename                   ------always running,but get nothing
    select top 1 *  from tablename         -------get result quickly
    select top 2 *  from tablename         -------get result quickly
    select top 14259 * from tablename  --------get result quickly
    select top 14260 * from tablename  --------always running,but get nothing
    the thread is:
    java.net.SocketInputStream.socketRead0(Native Method)
    java.net.SocketInputStream.read(SocketInputStream.java:150)
    java.net.SocketInputStream.read(SocketInputStream.java:121)
    com.microsoft.sqlserver.jdbc.TDSChannel.read(IOBuffer.java:1782)
    com.microsoft.sqlserver.jdbc.TDSReader.readPacket(IOBuffer.java:4838)
       - 已锁定com.microsoft.sqlserver.jdbc.TDSReader@54269910
    com.microsoft.sqlserver.jdbc.TDSCommand.startResponse(IOBuffer.java:6150)
    com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:402)
    com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:350)
    com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
    com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
       - 已锁定java.lang.Object@320b1499
    com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:180)
    com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:155)
    com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(SQLServerPreparedStatement.java:332)

    when I run the below sql of Uri Dimant,I get many rows,I think you are right!
    Do you have some method to handle this problem?
    Or do you have some information for me to Learn?
    Thanks a lot.
    SELECT
    owt.session_id AS waiting_session_id,
        owt.blocking_session_id,
    DB_NAME(tls.resource_database_id) AS database_name,
        (SELECT SUBSTRING(est.[text], ers.statement_start_offset/2
    + 1,
    (CASE WHEN ers.statement_end_offset = -1
    THEN LEN(CONVERT(nvarchar(max), est.[text])) * 2
    ELSE ers.statement_end_offset
    END
    - ers.statement_start_offset
    ) / 2)
    FROM sys.dm_exec_sql_text(ers.[sql_handle]) AS est) AS waiting_query_text,
    CASE WHEN owt.blocking_session_id > 0 
    THEN (
    SELECT
    est.[text] FROM sys.sysprocesses AS sp
    CROSS APPLY sys.dm_exec_sql_text(sp.[sql_handle]) as est
    WHERE sp.spid = owt.blocking_session_id)
    ELSE
    NULL
    END AS blocking_query_text,
        (CASE tls.resource_type
    WHEN 'OBJECT' THEN OBJECT_NAME(tls.resource_associated_entity_id, tls.resource_database_id)
    WHEN 'DATABASE' THEN DB_NAME(tls.resource_database_id)
    ELSE (SELECT  OBJECT_NAME(pat.[object_id], tls.resource_database_id)
    FROM sys.partitions pat WHERE pat.hobt_id = tls.resource_associated_entity_id)
    END
    ) AS object_name,
    owt.wait_duration_ms,
    owt.waiting_task_address,
    owt.wait_type,
    tls.resource_associated_entity_id,
    tls.resource_description AS local_resource_description,
    tls.resource_type,
    tls.request_mode,
    tls.request_type,
    tls.request_session_id,
    owt.resource_description AS blocking_resource_description,
    qp.query_plan AS waiting_query_plan
    FROM sys.dm_tran_locks AS tls
    INNER JOIN sys.dm_os_waiting_tasks owt ON tls.lock_owner_address = owt.resource_address
    INNER JOIN sys.dm_exec_requests ers ON tls.request_request_id = ers.request_id
    AND owt.session_id = ers.session_id
    OUTER APPLY sys.dm_exec_query_plan(ers.[plan_handle]) AS qp
    GO

  • Can SELECT TOP have argument?

    Newbie’s question, I believe.
    I wanted to make a stored procedure to returns last several rows or last several hundred rows depending on the situation, so I started writing queries in order to copy/paste them into procedure. There are two queries, first works, but
    second one shows syntax error in select statement. Can anyone tell me why, and how to go around this?
    SELECT TOP 5 * FROM Table1 ORDER BY ID DESC
    DECLARE @Counter as int
    SET @ Counter = 5
    SELECT TOP @ Counter FROM Table1 ORDER BY ID DESC

    This works. But I still don?t realize what was wrong with my syntax. Do those () will convert what?s inside parameter to string so parser could read it correctly? What actually is going on here?
    It's just the way it is. Originally there was only SELECT TOP n, where the value after TOP had to be a constant. Then they added the ability to have expression, but then they added the parens. This is so that you can say things like:
    SELECT TOP (SELECT ... FROM ...) ... FROM
    if you feel like.
    The old syntax is deprecated but remains for compatibility reasons.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Oracle 10g Select Top 100 Percent

    Hello
    How to convert MS sql 2008 select top 100 query Oracle PL/SQL ? MY sample MSSQL select query
    SELECT TOP (100) PERCENT dbo.Operations.OpID, dbo.CompanyInfo.Name AS CompanyName, dbo.CustomerInfo.SubscriberNo, dbo.CustomerInfo.FirstName,
    dbo.CustomerInfo.LastName, dbo.Operations.OpDate, dbo.Operations.BillCount, dbo.Operations.TotalAcceptedCash, dbo.Operations.KioskID,
    dbo.Operations.ReceiptNo, dbo.Operations.KioskOpID, dbo.KioskInfo.Name AS KioskName, dbo.Operations.TotalBill, dbo.Operations.TotalPayBack,
    dbo.CompanyInfo.CompanyID, dbo.Operations.ConfirmedRecord, dbo.PayMethod.ACK AS PayMethod
    FROM dbo.Operations INNER JOIN
    dbo.CustomerInfo ON dbo.Operations.SubscriberNo = dbo.CustomerInfo.SubscriberNo INNER JOIN
    dbo.CompanyInfo ON dbo.Operations.CompanyID = dbo.CompanyInfo.CompanyID INNER JOIN
    dbo.KioskInfo ON dbo.Operations.KioskID = dbo.KioskInfo.KioskID INNER JOIN
    dbo.PayMethod ON dbo.Operations.PayMethodID = dbo.PayMethod.PayMethodID
    ORDER BY dbo.Operations.OpDate DESC

    Hi,
    Please read SQL and PL/SQL FAQ
    Additionally when you put some code please enclose it between two lines starting with {noformat}{noformat}
    i.e.:
    {noformat}{noformat}
    SELECT ...
    {noformat}{noformat}
    From what I have found on MS SQL documentation it seems that TOP keyword limits the output to a specified percentage of total number of rows. In your case, having specified 100, you are returning 100% of rows.
    So you can simply remove *TOP (100) PERCENT*
    Regards.
    Al                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Convert selection to AAC (iTunes 5)

    After inserting a CD and then trying to covert selection to AAC I get the message "Could not convert the selected songs. The songs may be write-protected or of the wrong type" and then "Eror occured while converting the file. An unknown error occured (-48).
    This never happened in previous version and yes I've tried various CDs - all give the above message?

    You don't select the songs on a CD and then convert selection to AAC. You click on the Import button in the top right corner of the winder.

  • 'Convert Selection' Doesn't Work - Over Quickly

    Hi.
    I put a CD in the drive, i go in iTunes, highlight the tracks, right-click then 'convert selection to...'; It converts the tracks, yes - but in about half a second per track, and then the tracks don't actually work. It's a mystery and incredibly frustrating.
    Does anybody have any idea what's going on?
    I would be very grateful for your help.
    Danke.

    If you go along the top of the screen in iTunes go to Edit>Preferences>Advanced>Importing, check to see if 'Use error correction when reading Audio CD's' is checked.
    If it is checked, try unchecking it, and then re-importing the CD to see if that helps.

  • Converting selections to MP3 option in iTunes

    When using convert selection to MP3 in iTunes is there any options that need to be configured or are they set to default?
    Thanks.

    The conversion settings default from whatever you have set in your import settings. The default setting for iTunes is AAC so if you want to convert songs to MP3 then you have to change your import settings to MP3. If you are using iTunes 8 go to Edit>Preferences>General and click on Import Settings, change your option to MP3 for example. Go back to your library and highlight the songs you want to convert and go to the Advanced menu at the top of your iTunes window and choose "Create MP3 version": iTunes: How to convert a song to a different file format

  • Adobe Acrobat 9 supposedly allows you to convert selected areas of a web page to PDF from within Int

    Software: Adobe Acrobat 9 Standard
    Issue: Using the ‘Adobe PDF toolbar’ from within Internet Explorer
    Problem #1:
    Can’t convert selected areas of a web page to PDF
    When you click ‘select’ on the adobe pdf toolbar, a red dotted line is supposed to appear around parts of the web page as you move the cursor
    In my case, that’s not happening
    Similarly, when you click on a part of the page, the part is supposed to be highlighted in blue
    In my case, that’s not happening
    Problem #2:
    Can’t convert part of a web page to PDF
    You’re supposed to use the cursor to select text and images on a page, then right-click and convert them to a PDF
    In my case, nothing happens when I right-click
    Any advice??

    You can not do that using Adobe Acrobat 9. Adobe never made a create PDF add-on for Firefox for use with Adobe Acrobat 9. They created a Firefox add-on for use with Acrobat X, but currently that one does not work with Firefox 4 though Adobe are working on an update.

  • "Convert Selection for iPod" Command Increases File Size?

    Hello!
    I'm trying to convert a file that has the following characteristics (as reported in Quicktime Pro):
    Format: H.264 Decoder, 496 x 208, Millions, AAC, Stereo (L R), 44.100 kHz
    FPS: 25
    Data Size: 572.20 MB
    Data Rate: 659.18 kbits/sec
    Normal Size: 496 x 208
    I know the dimensions are strange, but it's because this is just a test I'm running on a workflow using Hand Brake to bring content back from a DVD (my content).
    Now, when I drop just the original file into iTunes and then try to put it on an iPod, it says it can't be played. So I use the handy new option in the Advanced menu, "Convert Selection for iPod." This yields a new file with the following characteristics:
    Format: AAC, Stereo (L R), 44.100 kHz, H.264 Decoder, 640 x 268, Millions
    FPS: 25
    Data Size: 1.36GB
    Data Rate: 1609.01 kbits/sec
    Normal Size: 640 x 268
    How is it that the data rate and file size have increased so much? It now plays on an iPod, but why? I was under the impression that usually the problem with getting video to play on an iPod was a data rate that is too high. So it seems strange to me that the second file works and the first doesn't.
    Finally, what is the difference between a file with the extension .mov and the extension .m4v? The original file has .mov and the converted ends up with .m4v. But they have the same characteristics in terms of codec. So what's the difference?
    Thanks for any help and info!
    Cameron

    I think I was able to resolve this myself after some trial and error. It looks like it is all in the name of the file. I've gotten some files to transfer after going into the Get Info section and updating the name (usually shorten the name or take out non-letter/number/# characters and then get the filename on disk to match.

  • How to select top one in CDS view ?

    I have tried following logic to select top one in CDS view but its giving error -
    define view Cds_View_First_Reference as select  top one CReferredObject from CDSVIEWCROSSREF

    Hi Ruchi,
    since you posted this question in "ABAP in Eclipse" I assume you are asking about CDS in ABAP. This is important because the CDS features sets in ABAP and (native) HANA are different.
    Be that as it may,, SELECT TOP 1 is neither supported in the CDS implementation in ABAP nor in HANA.
    In ABAP you might consider using the min() or max() function together with the appropriate GROUP BY clause in the CDS view (depending on what you want to achieve), but you can also easily "implement" this in the Open SQL statement which selects from your CDS view.
    Using the additions SELECT SINGLE or UP TO 1 ROWS and an appropriate ORDER BY clause in Open SQL, you can achieve the same as SELECT TOP 1.
    Unfortunately there is currently no possibility to define a view which delivers the TOP 1 which you can again use in another view ("view on view").
    Kind regards
    Chris

  • A way to convert selection from query builder in DML language

    I search a way to convert selection from query builder in DML language.
    regards

    We will make a sample from this request and post it on OTN. I have pasted all the JSP code so you should be able to use it directly. Just change the BISession details and the presentation references.
    <%@ taglib uri="http://xmlns.oracle.com/bibeans" prefix="orabi" %>
    <%@ page contentType="text/html;charset=windows-1252"%>
    <%@ page import="java.util.Vector" %>
    <%@ page import="oracle.dss.thin.beans.crosstab.ThinCrosstab" %>
    <%@ page import="oracle.dss.util.DataAccess" %>
    <%@ page import="oracle.dss.selection.Selection" %>
    <%@ page import="oracle.dss.thin.beans.graph.ThinGraph" %>
    <%@ page import="oracle.dss.dataSource.client.QueryClient"%>
    <%-- Start synchronization of the BI tags --%>
    <% synchronized(session){ %>
    <orabi:BIThinSession id="BIThinSession1" configuration="/Project1BIConfig1.xml" >
    <orabi:Presentation id="untitled2_Presentation1" location="Presentation1" />
    <orabi:Presentation id="untitled2_Presentation2" location="Presentation2" />
    </orabi:BIThinSession>
    <%
    String CROSSTAB_ID = "untitled2_Presentation2";
    String GRAPH_ID = "untitled2_Presentation1";
    String MYProducts = "Nothing";
    String prodID = "MDM!D_CS_OLAP.SHAWPRODUCTS";
    //Find the crosstab object on the page
    Object crosstabObject = pageContext.findAttribute(CROSSTAB_ID);
    ThinCrosstab thinCrosstab = (ThinCrosstab)crosstabObject;
    //Get the various query components from the Crosstab
    QueryClient myQCXtab = (QueryClient)thinCrosstab.getDataSource();
    Selection mySelXtab = myQCXtab.findSelection(prodID);
    DataAccess daXtab = myQCXtab.createQueryAccess().getDataAccess(mySelXtab);
    // This is a one-d data access, only has the column edge
    int colExtentXtab = daXtab.getEdgeExtent(oracle.dss.util.DataDirector.COLUMN_EDGE);
    for (int i=0; i<colExtentXtab; i++)
    String memberLabel = (String)daXtab.getMemberMetadata(oracle.dss.util.DataDirector.COLUMN_EDGE, 0, i, oracle.dss.util.MetadataMap.METADATA_LONGLABEL);
    String memberValue = (String)daXtab.getMemberMetadata(oracle.dss.util.DataDirector.COLUMN_EDGE, 0, i, oracle.dss.util.MetadataMap.METADATA_VALUE);
    System.out.println(memberLabel + " " + memberValue);
    // As above except for graphs.
    Object graphObject = pageContext.findAttribute(GRAPH_ID);
    ThinGraph thinGraph = (ThinGraph)graphObject;
    QueryClient myQCGraph = (QueryClient)thinGraph.getDataSource();
    Selection mySelGraph = myQCGraph.findSelection(prodID);
    DataAccess daGraph = myQCGraph.createQueryAccess().getDataAccess(mySelGraph);
    // This is a one-d data access, only has the column edge
    int colExtentGraph = daGraph.getEdgeExtent(oracle.dss.util.DataDirector.COLUMN_EDGE);
    for (int i=0; i<colExtentGraph; i++)
    String memberLabel = (String)daGraph.getMemberMetadata(oracle.dss.util.DataDirector.COLUMN_EDGE, 0, i, oracle.dss.util.MetadataMap.METADATA_LONGLABEL);
    String memberValue = (String)daGraph.getMemberMetadata(oracle.dss.util.DataDirector.COLUMN_EDGE, 0, i, oracle.dss.util.MetadataMap.METADATA_VALUE);
    System.out.println(memberLabel + " " + memberValue);
    %>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>
    Hello World
    </title>
    </head>
    <body>
    <FORM name="BIForm">
    <!-- Insert your Business Intelligence tags here -->
    <orabi:Render targetId="untitled2_Presentation1" parentForm="BIForm" />
    <orabi:Render targetId="untitled2_Presentation2" parentForm="BIForm" />
    <%-- The InsertHiddenFields tag adds state fields to the parent form tag --%>
    <orabi:InsertHiddenFields parentForm="BIForm" biThinSessionId="BIThinSession1" />
    </FORM>
    <h2>
    The current time is:
    </h2>
    <p>
    <%= new java.util.Date() %></p>
    <input type="text" name="MyTextField" value=MYProducts readonly>
    </body>
    </html>
    <% } %>
    <%-- End synchronization of the BI tags --%>
    Hope this helps
    Business Intelligence Beans Product Management Team
    Oracle Corporation

  • Prepared Statement, executing  SELECT TOP in Ms Access

    I'm having the following problem. I built an application fetching data without any problem from MS SQL Server, this was using prepared statements. Now i'm having this strange problem with the following query:
    SELECT TOP 1 *
    FROM table
    WHERE appliance_id = ?
    AND ttimestamp_initpk <= ?
    AND ((Type = ?) OR (Type = ?) OR (Type = ?) OR (Type = ?) OR (Type = ?) OR (Type = ?))
    ORDER BY ttimestamp_initpk DESC
    While on SQL Server this fetches just a record, on MS Access it fetches the whole set of records without worrying about TOP instruction.
    That is, it acts like a SELECT * FROM, and this slows down runtime behaviour.
    I'm using sun.jdbc.odbc.JdbcOdbcDriver, is it the problem?
    Thanks, Mirko

    Thanks for your answer, but i'm not sure this is the reason.
    I made one more test: i wrote a .Net application connecting to a MS Access using an ODBC connection. SELECT TOP statement is working fine, so i think i'll try another JDBC driver. Any other solution??
    Thanks,
    Mirko

  • SELECT TOP query in HANA

       Hi,
    Can somebody give me the HANA equivalent of the following SQL query:
    SELECT TOP (731-624+1) COLUMNNAME FROM TABLENAME
    In case of HANA, it gives syntax error near "(".

    Hi Yash,
    As per the HANA SQL syntax supported case is
    <select_clause> ::= SELECT [TOP <unsigned_integer>] [ ALL | DISTINCT ]
    <select_list>
    After Top only an unsigned intger is expected and cannot handle an <expression> like in your example.
    Hope this is useful.
    Best Regards,
    Ranjit

  • SELECT TOP 1 .... ORDER BY

    Hi,
    I have the following statement in SQL SERVER:
    SELECT TOP 1 NAME FROM STUDENT ORDER BYGRADE
    Now, I am trying to translate it ti ORACLE PLSQL, I came up with this statement:
    SELECT NAME FROM STUDENT WHERE ROWNUM=1 ORDER BY GRADE
    It doesn't work. I guess ORACLE generates ROWNUM before the ORDER BY operation...
    How can I have SELECT TOP N ... ORDER BY ... in Oracle the way that I have it in SQL server?
    Any help would be apprecited,
    Alan

    Can you cut and paste exactly what you're doing in a SQL*Plus session? It seems to work for me
    SCOTT @ hp92 Local> create table t as select * from all_objects;
    Table created.
    Elapsed: 00:00:08.40
    SCOTT @ hp92 Local> desc t;
    Name                                                  Null?    Type
    OWNER                                                 NOT NULL VARCHAR2(30)
    OBJECT_NAME                                           NOT NULL VARCHAR2(30)
    SUBOBJECT_NAME                                                 VARCHAR2(30)
    OBJECT_ID                                             NOT NULL NUMBER
    DATA_OBJECT_ID                                                 NUMBER
    OBJECT_TYPE                                                    VARCHAR2(18)
    CREATED                                               NOT NULL DATE
    LAST_DDL_TIME                                         NOT NULL DATE
    TIMESTAMP                                                      VARCHAR2(19)
    STATUS                                                         VARCHAR2(7)
    TEMPORARY                                                      VARCHAR2(1)
    GENERATED                                                      VARCHAR2(1)
    SECONDARY                                                      VARCHAR2(1)
    SCOTT @ hp92 Local> create index idx_t on t( object_id );
    Index created.
    Elapsed: 00:00:00.78
    SCOTT @ hp92 Local> analyze table t compute statistics for all indexed columns;
    Table analyzed.
    Elapsed: 00:00:00.53
    SCOTT @ hp92 Local> set autotrace on;
    SCOTT @ hp92 Local> select *
      2    from (select * from t order by object_id)
      3   where rownum < 2;
    OWNER                          OBJECT_NAME                    SUBOBJECT_NAME
    OBJECT_ID DATA_OBJECT_ID OBJECT_TYPE        CREATED   LAST_DDL_ TIMESTAMP           STATUS  T G S
    SYS                            DUAL
           222            222 TABLE              12-MAY-02 12-MAY-02 2002-05-12:16:20:50 VALID   N N N
    Elapsed: 00:00:00.13
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE
       1    0   COUNT (STOPKEY)
       2    1     VIEW
       3    2       TABLE ACCESS (BY INDEX ROWID) OF 'T'
       4    3         INDEX (FULL SCAN) OF 'IDX_T' (NON-UNIQUE)
    Statistics
              0  recursive calls
              0  db block gets
              3  consistent gets
              1  physical reads
              0  redo size
           1142  bytes sent via SQL*Net to client
            511  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processedJustin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

Maybe you are looking for