Select with rownum : rownum « Query Select « Oracle PL/SQL Tutorial






SQL>
SQL> CREATE TABLE s_inventory
  2  (product_id               NUMBER(7),
  3   warehouse_id             NUMBER(7),
  4   amount_in_stock          NUMBER(9),
  5   reorder_point            NUMBER(9),
  6   max_in_stock             NUMBER(9),
  7   out_of_stock_explanation VARCHAR2(255),
  8   restock_date             DATE);

Table created.

SQL>
SQL> INSERT INTO s_inventory VALUES (10011, 101, 650, 625, 1100, NULL, NULL);

1 row created.

SQL> INSERT INTO s_inventory VALUES (10012, 101, 600, 560, 1000, NULL, NULL);

1 row created.

SQL> INSERT INTO s_inventory VALUES (10013, 101, 400, 400, 700, NULL, NULL);

1 row created.

SQL> INSERT INTO s_inventory VALUES (10021, 101, 500, 425, 740, NULL, NULL);

1 row created.

SQL> INSERT INTO s_inventory VALUES (10022, 101, 300, 200, 350, NULL, NULL);

1 row created.

SQL> INSERT INTO s_inventory VALUES (10023, 101, 400, 300, 525, NULL, NULL);

1 row created.

SQL> INSERT INTO s_inventory VALUES (20106, 101, 993, 625, 1000, NULL, NULL);

1 row created.

SQL> INSERT INTO s_inventory VALUES (20108, 101, 700, 700, 1225, NULL, NULL);

1 row created.

SQL> INSERT INTO s_inventory VALUES (20201, 101, 802, 800, 1400, NULL, NULL);

1 row created.

SQL> INSERT INTO s_inventory VALUES (20510, 101, 1389, 850, 1400, NULL, NULL);

1 row created.

SQL> INSERT INTO s_inventory VALUES (20512, 101, 850, 850, 1450, NULL, NULL);

1 row created.

SQL> INSERT INTO s_inventory VALUES (30321, 101, 2000, 1500, 2500, NULL, NULL);

1 row created.

SQL> INSERT INTO s_inventory VALUES (30326, 101, 2100, 2000, 3500, NULL, NULL);

1 row created.

SQL> INSERT INTO s_inventory VALUES (30421, 101, 1822, 1800, 3150, NULL, NULL);

1 row created.

SQL>
SQL>
SQL> SELECT product_id
  2  FROM   s_inventory
  3  WHERE  ROWNUM < 5;

PRODUCT_ID
----------
     10011
     10012
     10013
     10021

SQL>
SQL>
SQL> drop table s_inventory;

Table dropped.

SQL>








2.31.rownum
2.31.1.Select with rownum
2.31.2.Use rownum to limit the resultset
2.31.3.SELECTs using the ORDER BY clause with rownum
2.31.4.Getting the Five Most Expensive Products