SELECT TOP SQL alternative for Oracle databases

When querying SQL Server databases you can return the top X number of records that match the query criteria via a SQL statement similar to the following:

[sql]SELECT TOP 100 * FROM tbl_Products WHERE Prod_Desc LIKE ‘*widget*'[/sql]

However, this same SQL statement will not run against an Oracle database because there is no built-in “TOP” function.  To get around this, you can utilize the ROWNUM pseudocolumn.  Example:

[sql]SELECT * FROM tbl_Products WHERE Prod_Desc LIKE ‘%widget%’ AND ROWNUM < 101[/sql]

Leave a comment