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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • How do I select top 100 records in query

    I would like to get only the first 100 or 200 records in a query. In Access query, it is TOP 100, is there an equal in Oracle sql?
    Thanks!

    select * from your_table
    where rownum < 101;

  • Sybase "Top (n) percent" does not work, any suggestions?

    Hi All,
    I want to select a percentage of records in Sybase. I can only use "SELECT TOP n" to select n rows. If I want to select 100% of the rows in SQL I use "SELECT TOP (100) PERCENT", Sybase does not recognize the syntax.
    Does anyone know if this is possible in Sybase? What is the syntax in Sybase?
    Thank you in advance.
    Regards,
    Reshma
    Please Vote as Helpful if an answer is helpful and/or Please mark Proposed as Answer or Mark As Answer when question is answered

    Try : SELECT TOP 100 PERCENT ...
    and find a right forum to ask question related Sybase. It is not the same product now.

  • Select top 10 percentage

    Hi,
    I want to get the top 10% of salaries in employees table. But I got error:
    SQL> select top 10 percent salary
      2  from employees
      3  order by salary desc;
    ORA-00923: FROM keyword not found where expectedHow can I get the top 10% percent?
    Thanks a lot

    Hi,
    998093 wrote:
    ... What if I want to get, for example, the employees who are in the top 12% of the salaries? here we cannot use deciles (maybe we can but it won't be very nice).Actually, you can. How nice it will be depends on your data and your exact requirements.
    Earlier, we said that the top 10% was the 10th of 10 buckets.
    We could say that the top 12% is the last 12 of 100 buckets:
    WITH     got_tenth     AS
         SELECT     last_name, salary
         ,     NTILE (100) OVER (ORDER BY salary)     AS hundredth
         FROM     hr.employees
    SELECT       last_name, salary
    FROM       got_tenth
    WHERE       hundredth     > 100 - 12
    ORDER BY  salary     DESC
    ;I won't clutter up this message by showing the results for every query; I'll just report the total number of rows. The query I posted earlier (for the top 10%) produced 10 rows of output; the query immediately above produces 12. That's starting to bother me. There are 107 rows in hr.employees. (They all have a salary; don't forget to deal with NULLs in general.) The top 10% should contain 107 * .1 = 10.7 rows. Of course, this has to be rounded to an integer, so it would have been a little better if the top 10% showed 11 rows (since 11 is closer to 10.7 than 10 is), but it's not a real big problem. Likewise, the top 12% should have 107 * .12 = 12.84 rows, so 13 rows of output might be better, but 12 rows isn't too bad.
    Now say we want to simplify the condition "WHERE     hundredth     > 100 - 12". Instead of taking the last 12 buckets in ascending order, let's take the first 12 buckets in descending order:
    WITH     got_tenth     AS
         SELECT     last_name, salary
         ,     NTILE (100) OVER (ORDER BY salary DESC)     AS hundredth
         FROM     hr.employees
    SELECT       last_name, salary
    FROM       got_tenth
    WHERE       hundredth     <= 12
    ORDER BY  salary     DESC
    ;The result set now contains 19 rows! Why? Because NTILE puts extra items (when there are extras) in the lower-numbered buckets. When there were 10 buckets, then buckets 1 trough 7 had 11 items each, and buckets 8 through 10 had 10 items. We were only dispolaying bucket #10, so we only saw 10 items. Now that there are 100 buckets, buckets 1 through 7 will have 2 items each, and buckets 8 through 100 will have 1 item each. When we numbered the buckets in ascending order, and took the last 12 buckets, we wound up with 12 * 1 = 12 rows, but when we numbered the buckets in descending order and took the first 12 buckets, we got (7 * 2) + (5 * 1) = 19 rows.
    When you have R rows and B buckets, and R/B doesn't happen to be an integer, then NTILE will distribute the rows as equally as possible, but some rows will have 1 item more than others. When the ratio R/B is high, that might not be very significant, but when R/B gets close to 1, then you have situations like the one above, where the bigger buckets, although they have only 1 more item than the smaller buckets, are twice as big. Even worse is the situation where R/B is less than 1; then the last buckets will have 0 items.
    So, as you noticed, NTILE isn't a good solution for all occasions. Here's a more accurate way, using the analytic ROW_NUMBER and COUNT functions:
    WITH     got_analytics     AS
         SELECT     last_name, salary
         ,     ROW_NUMBER () OVER (ORDER BY  salary  DESC)     AS r_num
         ,     COUNT (*)     OVER ()                                AS n_rows
         FROM     hr.employees
    SELECT       last_name, salary
    FROM       got_analytics
    WHERE       r_num / n_rows <= 12 / 100
    ORDER BY  salary     DESC
    ;This produces 12 rows.
    If you want 13 rows (because 107 * .12 = 12.84 is closer to 13), then you can change the main WHERE clause like this:
    WITH     got_analytics     AS
         SELECT     last_name, salary
         ,     ROW_NUMBER () OVER (ORDER BY  salary  DESC)     AS r_num
         ,     COUNT (*)     OVER ()                                AS n_rows
         FROM     hr.employees
    SELECT       last_name, salary
    FROM       got_analytics
    WHERE       r_num     <= ROUND (n_rows * 12 / 100)
    ORDER BY  salary     DESC
    ;

  • Installing oracle 10g on windows XP is giving problem

    Iam successfully installed oracle 10g on top of that iam installing some scripts to load ALUI.(aqua logic user interaction)
    in that when iam running this script (CreateService.bat PLUM10 plum10) facing below error.
    D:\oracle\product\10.2.0\admin\PLUM10\plumtreescripts>CreateService.bat PLUM10 p
    lum10
    D:\oracle\product\10.2.0\admin\PLUM10\plumtreescripts>ORADIM -NEW -SID PLUM10 -I
    NTPWD plum10 -STARTMODE AUTO -PFILE D:\oracle\admin\PLUM10\pfile\initPLUM10.ora
    1>>CreateService.log
    D:\oracle\product\10.2.0\admin\PLUM10\plumtreescripts>SET ORACLE_SID=PLUM10
    D:\oracle\product\10.2.0\admin\PLUM10\plumtreescripts>echo PLUM10 1>>SetEnvServ
    ice.log
    D:\oracle\product\10.2.0\admin\PLUM10\plumtreescripts>type CreateService.log
    Unable to find error file %ORACLE_HOME%\RDBMS\opw<lang>.msb
    Message 51 not found; No message file for product=RDBMS, facility=ORADIM
    Unable to find error file %ORACLE_HOME%\RDBMS\opw<lang>.msb
    DIM-00019: Message 19 not found; No message file for product=RDBMS, facility=ORA
    DIM
    O/S-Error: (OS 1073) The specified service already exists.
    Unable to find error file %ORACLE_HOME%\RDBMS\opw<lang>.msb
    DIM-00019: Message 19 not found; No message file for product=RDBMS, facility=ORA
    DIM
    O/S-Error: (OS 1073) The specified service already exists.
    Unable to find error file %ORACLE_HOME%\RDBMS\opw<lang>.msb
    Message 51 not found; No message file for product=RDBMS, facility=ORADIM
    Unable to find error file %ORACLE_HOME%\RDBMS\opw<lang>.msb
    DIM-00019: Message 19 not found; No message file for product=RDBMS, facility=ORA
    DIM
    O/S-Error: (OS 1073) The specified service already exists.
    Unable to find error file %ORACLE_HOME%\RDBMS\opw<lang>.msb
    DIM-00019: Message 19 not found; No message file for product=RDBMS, facility=ORA
    DIM
    O/S-Error: (OS 1073) The specified service already exists.
    Unable to find error file %ORACLE_HOME%\RDBMS\opw<lang>.msb
    DIM-00019: Message 19 not found; No message file for product=RDBMS, facility=ORA
    DIM
    O/S-Error: (OS 1073) The specified service already exists.
    D:\oracle\product\10.2.0\admin\PLUM10\plumtreescripts>
    If any body help is much needed...
    Thanks u so much...

    maybeSET ORACLE_HOME=D:\oracle\product\10.2.0

  • Recommended books for Oracle 10g

    I'm new to this group, so my apologies in advance if this is not the appropriate group for this question. If it is not, please steer me in the right direction. Thanks!
    Here's my situation: I'm currently a Microsoft SQL Server developer and have been for about 6 years, so I'm fairly conversant with SQL. Our company is in the process of purchasing an application that runs under Oracle 10g, and I need to learn as much as I can as quickly as I can about 1) being the Oracle DBA for our (small) company, and 2) developing in Oracle SQL.
    Are there any specific books some of you would recommend for my particular situation (beginning level Oracle user, intermediate/advanced in SQL)? Any and all advice/suggestions/help will be gratefully accepted.
    Thanks in advance --
    Carl

    First thing I would recommend is going in the OTN and download the 2 day dba article
    and the top 20 Oracle 10g features
    Top 20:
    http://www.oracle.com/technology/pub/articles/10gdba/index.html
    2 day dba:
    http://www.oracle.com/technology/pub/columns/kestelyn_manage.html

  • Update with Select top n statement

    Hi All,
    Can I use update statemet like this..
    Update table1
    set Name=(select top (100) t2.name from table2 t2 where table1.ID=t2.ID)
    Please let me know ASAP its very urgent
    Thanks in Advance
    RH
    sql

    Hi sql9 !
    You might need below query;
    CREATE TABLE Table1 (ID INT,Name VARCHAR(10))
    CREATE TABLE Table2 (ID INT,Name VARCHAR(10))
    --TRUNCATE TABLE Table1
    --TRUNCATE TABLE Table2
    INSERT INTO Table1
    SELECT 1,'ABC' UNION ALL
    SELECT 2,'DEF' UNION ALL
    SELECT 3,'GHI'
    INSERT INTO Table2
    SELECT 1,'JKL' UNION ALL
    SELECT 1,'MNO' UNION ALL
    SELECT 2,'PQR' UNION ALL
    SELECT 2,'STU' UNION ALL
    SELECT 3,'VWX' UNION ALL
    SELECT 3,'YZ'
    UPDATE Table1 SET Name = (SELECT TOP 1 T2.Name FROM Table2 T2 WHERE Table1.ID = T2.ID)
    SELECT * FROM Table1
    --ID Name
    --1 JKL
    --2 PQR
    --3 VWX
    --You can simply re-write your SQL with below query and you don't have to specify TOP Clause inside subquery
    UPDATE T1 SET T1.Name = T2.Name
    FROM Table1 T1
    INNER JOIN Table2 T2 ON T2.ID = T1.ID
    SELECT * FROM Table1
    --ID Name
    --1 JKL
    --2 PQR
    --3 VWX
    Note : In your first query TOP 100 returning more than 1 value from subquery which is not allowed.
    Please let me know if this doesn’t work for you. Hope I have answered you correctly.
    Thanks,
    Hasham

  • Oracle 10g - Date format in SELECT query for CFOUTPUT

    Hello, everyone.
    The project that I am working on in the dev environment is connected to an Oracle 11g database, but the production side is Oracle 10g.
    I have a page that is erroring in production (but not development) when it gets to a date that it needs to display.
    A co-worker mentioned that, in 10g, if a date/time is being SELECTed, you have to put it in to_char(), so I did that.
    But it's still erroring, and I'm not getting an error message, so I'm assuming that I have an incorrect format for the date in the SELECT.
    What is the proper format for SELECTing a date/time when using to_char()?  Right now, I have SELECT to_char(create_date,'MM-DD-YYYY HH:MI') FROM tableA .  Is this not correct for CF to output?
    Thank you,
    ^_^

    Please see my original post ("I have a page erroring in production (but not in development) when it gets to a date that it needs to display.")  Sorry if it came across as vague.  It made sense, to me, when I typed it.  But, then, I'm usually typing fast just to get the question out there, when I'm in a hurry.
    Haven't done a CFDUMP, yet, as every time I make a change in development that needs to be tested in production, I have to notify my supervisor that there are files that need to be copied into production, which can sometimes take a while, so I try to do troubleshooting on dev side - it's a pain in the you-know-what, but that's the kind of environment I'm working in.
    As it turns out, changing the format in the SELECT to_char() did the trick.  If anyone else has this issue with Oracle 10g, I'm now using SELECT to_char(create_date,'YYYY/MM/DD HH:MI') FROM tableA, and now the CFOUTPUT is processing the whole page.  I guess the MM-DD-YYYY threw CF into a tizzy, breaking the process?
    Anyhoo, it's working, now.  Thank you, Dan and Adam, for your thoughts on this.
    ^_^

  • Tomcat 4.0 and Oracle 10g takes 100% CPU and grinds to a halt

    Hi, I have a system to support that is currently running on Tomcat 4.0 on a Windows Server 2003 R2 SP2 machine with 3.06Ghz, 4Gb Memory, 2Gb Page file connecting to an Oracle 8.1.6 database on a Windows NT 4 virtual server with 3.2Ghz, 1152Mb Memory, 1536Mb Page file.
    I have another Windows virtual server 2003 R2 SP2 machine with 2Gb of memory and a 4Gb page. This server has Tomcat 4.0 and an Oracle 10.2.0.3.0 database. I have made sure that the Oracle 10g classes12.jar file is used.
    I am trying to run the application on the new server. In some tests I had users logging on one by one for the first 5 users - performance was great and the application ran faster than the current live system. When I then got another 10 - 15 people logging on the CPU stuck at 100% on the server, even exploring the server was almost impossible, and the application slowed down to unworkable.
    We dont know if the problem lies with the very fact that we are trying to connect to a 10g database which is cost based and the application was written using rule based Oracle 8. Or is it the virtual server? Or is it the fact that we have both the application and the database on the same server.
    I dont know if it is possible to have another Tomcat4.0 server running on our live server but connecting to the 10g database - what would happen with classes12.zip and classes12.jar? would there be a conflict?
    I would really appreciate some help here. You should know though that I am not a hardened java programmer - I can dabble, but am an Oracle Forms, Reports, Discoverer, SQL person by trade. I am also a trainee DBA, so again am not an expert by any means.
    Thanks in advance for your help
    Lizzie

    lizzie8 wrote:
    Hi, I have a system to support that is currently running on Tomcat 4.0 on a Windows Server 2003 R2 SP2 machine with 3.06Ghz, 4Gb Memory, 2Gb Page file connecting to an Oracle 8.1.6 database on a Windows NT 4 virtual server with 3.2Ghz, 1152Mb Memory, 1536Mb Page file.Tomcat 4? We're up to Tomcat 6. The important difference is the JDK supported. What JDK are you using for Tomcat?
    >
    I have another Windows virtual server 2003 R2 SP2 machine with 2Gb of memory and a 4Gb page. This server has Tomcat 4.0 and an Oracle 10.2.0.3.0 database. I have made sure that the Oracle 10g classes12.jar file is used.classes12.jar is pretty old technology. The JAR should match your JDK and version of Oracle.
    I am trying to run the application on the new server. In some tests I had users logging on one by one for the first 5 users - performance was great and the application ran faster than the current live system. When I then got another 10 - 15 people logging on the CPU stuck at 100% on the server, even exploring the server was almost impossible, and the application slowed down to unworkable.You don't say anything about the whether or not you're using a connection pool or what's happening to the open connections and cursors. If you find that those are drifting up over time, it's likely that the code isn't closing resources properly.
    We dont know if the problem lies with the very fact that we are trying to connect to a 10g database which is cost based and the application was written using rule based Oracle 8. Or is it the virtual server? Or is it the fact that we have both the application and the database on the same server.Database and app server should be separated, IMO.
    I dont know if it is possible to have another Tomcat4.0 server running on our live server but connecting to the 10g database - what would happen with classes12.zip and classes12.jar? would there be a conflict?
    I would really appreciate some help here. You should know though that I am not a hardened java programmer - I can dabble, but am an Oracle Forms, Reports, Discoverer, SQL person by trade. I am also a trainee DBA, so again am not an expert by any means.You need more data. Get some tools to see where the time is being spent. Start monitoring your Oracle connections and cursors to see what's going on. Install some filters to get raw timings on your Java calls. Without data, you're guessing in the dark.
    %

  • Select * from tab is not working in oracle 10g

    select * from tab is not working in oracle 10g. But at the same time,
    select * from <<table>> is working.
    Please advise me.

    This works for me in 10.2.0.2
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
    SQL> select * from tab;
    TNAME                          TABTYPE            CLUSTERID
    LOAN_DETAIL                    TABLE
    PLAN_TABLE                     TABLE
    ...

  • Issue with "Select Distinct" query in Oracle 10g against Oracle 9i

    Hi,
    I would appreciate if some one help me here because it is really urgent.
    We are upgrading our database from 9i to 10g.
    There are the "Select distinct" queries in the code which populated the grid on the applications screens. We found a difference in 9i and 10g the way the result is populated for these queries. If "Select Distinct" query wihtout a order by clause is executed in 9i then the result is automatically sorted. But Oracle 10g does not do this.
    We can change the queries adding order by clause but we are almost at the end of the testing and want to know if there is any way that we can do this from database settings. Would there be any impact of these settings change on overall operation of Oracle 10g?
    I would appreciate if some one can help me here.
    Thanks,
    Dinesh

    then the result is automatically sorted.No. Oracle may have done a sort operation to perform the distinct, but it still did not guarantee the order of your results.
    In 10g and in 9i, if you want your results in a certain order you must use order by.

  • Oracle 10g: How to reduce the select * time

    Hello,
    We have 10 million entries in our database (Oracle 10g in windows 32 bit machine.)
    The execution of 'select * ....' takes 3 to 4 hour. Is there any way to reduce this time.
    Is any tool available which can read the oracle export data and produce the output in text file format.
    or any idea ?
    Thanks
    With Regards
    Hemant.

    hem_kec wrote:
    Hello EdStevens
    Is that 3 to 4 hours scrolling data past your screen?Answer: The Oracle is taking 3-4 hr to produce the output.
    OK, let me try again. Where is the output being directed? To the screen? To a file?
    The reason I ask is that often people will say "It takes n minutes to run this query" when in fact Oracle is producing the result set in a few seconds and what is taking n minutes is to run the results past the screen.
    You should take a statspack report while the query is running and see where it is spending its time.
    >
    That's a different problem. I assume by "export data" you mean a .dmp file created by exp or expdp? If so what do you hope to achieve by outputting it in text format? What is the business problem to be solved?Answer: Since customer want to read all 10 milion entries. so we are think if we can dump (Oracle export) the data and using some tool (not Oracle) to read the data so there is no wait for the customer.As stated, a dmp file is oracle proprietary binary file that exists solely to transport data across platforms/versions. It is not suitable for your purpose. You are far better off finding where the current query is spending its time than looking for some kludge. 10 million rows of data is still 10 million rows of data. Do you think extracting it from the db, storeing it in some other format, and having some other tool read it off of disk in that format is going to be faster than simply selecting it from the db -- asking the db to do what it was designed to do?
    >
    >
    Thanks
    With Regards
    Hemant.

  • Oracle 10g 10.2.0.100 for Windows 7 64 bit

    Hi,
    I have been trying with the installation for Oracle 10g 10.2.0.100 for 64bit WIndows7 (*ITs Client not Database*) . I am getting error that unknown files have to be replaced or something. I think i dont have correct version or have a corrupted version.Can you guys help me downloading Oracle 10g 10.2.0.100 for Windows7 64bit.Please post the valid links because i have tried different links which are not functioning right now.

    940230 wrote:
    Hi,
    I have been trying with the installation for Oracle 10g 10.2.0.100 for 64bit WIndows7 (*ITs Client not Database*) . I am getting error that unknown files have to be replaced or something. I think i dont have correct version or have a corrupted version.Can you guys help me downloading Oracle 10g 10.2.0.100 for Windows7 64bit.Please post the valid links because i have tried different links which are not functioning right now.Oracle 10.2.0.1 is not certified with Windows 7 OS. If you want to install 10gR2 client on Windows 7 OS you will need to go with 10.2.0.5
    Statement of Direction: Oracle Database 10g Release 2 Client (10.2.0.5) with Microsoft Windows 7 and Windows Server 2008 R2 [ID 1061272.1]
    Cannot Install Oracle 10g Instant Client On Windows 7 With UAC [ID 1407565.1]
    Thanks,
    Hussein

  • Oracle 10g 10.2.0.3.0 takes 100% CPU

    Hi,
    We are using Web sphere commerce server (IBM) with Oracle 10g. we are currently in development phase. what ever execute (jobs) small job like uploding 100 records, CPU takes 100%. the process can't complete, it goes on.
    System Details
    2 CPU and 8 GB RAM Intel Based system
    OS: Redhat server 5.1
    SQL> show sga
    Total System Global Area 2097152000 bytes
    Fixed Size 1262740 bytes
    Variable Size 251661164 bytes
    Database Buffers 1828716544 bytes
    Redo Buffers 15511552 bytes
    shared_pool_size big integer 112M
    java_pool_size big integer 112M
    PGA and SGA
    pga_aggregate_target big integer 200M
    sga_target big integer 2000M
    Pls could any one help on this. is it correct values SGA has or what could be the issue.
    Thanks
    Regards
    Settu Gopal

    Settu Gopal wrote:
    Hi,
    We are using Web sphere commerce server (IBM) with Oracle 10g. we are currently in development phase. what ever execute (jobs) small job like uploding 100 records, CPU takes 100%. the process can't complete, it goes on.Settu,
    in addition you might want to trace the session to find out what it is waiting for. In 10g you can use the DBMS_MONITOR package to enable the tracing, and then use the "tkprof" utility as outlined in the article to get the trace file generated analyzed.
    You can also use the V$SESSION view (BLOCKING_SESSION_STATUS, BLOCKING_SESSION, BLOCKING_INSTANCE) to find out if the session is blocked for any reason, although it shouldn't consume CPU in that case.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • In Oracle 10g,nmupm.exe  runs at 100% CPU usages

    Hi There this is Bal Mukund Sharma from Computer Associates,HYD.I have recently installed Oracle 10g on windows 2000 server with 1 GB RAM,i have observed that nmpsupm.exe which is under the bin directory under c:\oracle\product\10.1.0\Db_1\nmupm.exe.is consuming all CPU resources.
    when i set all Oracle services to manual and restarted the machine then it shows normal CPU usages. Can you please suggest something regarding this.
    Regards
    Mukund.

    This is a known issue, see here
    Re: 10g Db Windows 2000 NMUPM 100% CPU

Maybe you are looking for