A Tally Table (also known as Number Table) is an essential tool that every database administrator like to have in their databases. Such a table helps to solve a number of PLSQL problems in a SET based manner. Waldar provided a PLSQL script to generate 1 million row tally table.
/*********************************************************************** Purpose: Create a standared "Numbers" table for use in solving PL-SQL Challenges. Programmers Notes: 1. This table contains all INTEGER values from 0 (zero) to 1,000,000 inclusive and has a clustered index on the single INTEGER column called "N". 2. The table is named for the challenges so as not to overwrite existing Tally or Numbers tables by accident. Even then, if the plsqlc_Tally exists, this run will fail. Revision History: Rev 00 - 18 FEB 2010 - Walder - Initial release. ***********************************************************************/ --===== If the table already exists, drop the table if you wish to re-create. -- DROP TABLE plsqlc_Tally; --===== Create and populate the Numbers table on the fly. CREATE TABLE plsqlc_Tally ( n number(7), CONSTRAINT PK_plsqlc_Tally_N PRIMARY KEY (N) using INDEX ) organization INDEX; INSERT INTO plsqlc_Tally (N) SELECT LEVEL FROM dual connect BY LEVEL <= 1e6; COMMIT;