This select statement will return as many rows as are indicated by the value of a column. For example, if the column value is 7, then 7 copies of that row will be returned.
CREATE TABLE S
(
RNUM NUMBER,
TPART CHAR(10),
SQ NUMBER
)
;
Insert into S
(RNUM, TPART, SQ)
Values
(101, 'TEST_PART1', 1);
Insert into S
(RNUM, TPART, SQ)
Values
(102, 'TEST_PART2', 2);
Insert into S
(RNUM, TPART, SQ)
Values
(103, 'TEST_PART3', 3);
Insert into S
(RNUM, TPART, SQ)
Values
(105, 'TEST_PART5', 5);
COMMIT;
SELECT rnum, tpart, sq
FROM s s_alias, TABLE(SELECT COLLECT(dummy)
FROM DUAL
CONNECT BY LEVEL <= s_alias.sq);
Tuesday, October 23, 2007
SELECT as many rows as indicated by column value
at 10:15 AM
Labels: collect, CONNECT BY LEVEL, duplicate rows, example, Oracle SQL, replicate rows, TABLE function
Subscribe to:
Post Comments (Atom)
Labels
- aggregate (1)
- broken (1)
- cast (3)
- collect (4)
- collect detail (1)
- conditional constraint (1)
- CONNECT BY LEVEL (2)
- convert excel date to oracle date (1)
- Copy data from Salesforce to Oracle (1)
- Createuri (1)
- CSV (1)
- database link (1)
- db link (1)
- DBMS_OUTPUT (1)
- disable (1)
- distributed transaction (1)
- does not work (2)
- duplicate rows (1)
- dynamic cursor (1)
- enable (1)
- error (1)
- example (11)
- excel to oracle (1)
- Export (1)
- Extract (1)
- Extract from SalesForce (1)
- fails (1)
- file too large (1)
- Firefox (1)
- Firefox has blocked content that isn't secure (1)
- Firefox mixed content blocking (1)
- flagger (1)
- Function Based Index (1)
- generate csv (1)
- grouping (1)
- grouping sets (1)
- how to (1)
- http iframed in https (1)
- http inside https (1)
- Httpuritype (1)
- Import (1)
- incomplete (1)
- incremental elimination (1)
- limit (1)
- limit listagg (1)
- listagg (1)
- Load (1)
- Load to Oracle (1)
- merge limitation (1)
- merge problem (1)
- merge restriction (1)
- Migrate data from Salesforce to Oracle (1)
- mixed content (1)
- MODEL (2)
- nested table (1)
- not all variables bound (1)
- nvarchar2 (1)
- ora-01008 (1)
- ORA-01756 (1)
- ORA-06502 (1)
- ORA-12714 (1)
- Oracle (3)
- oracle client (1)
- oracle merge (1)
- Oracle Q-strings (1)
- Oracle SQL (6)
- Oracle SQL reporting functions (1)
- Package Structure (1)
- Partition By (1)
- PL/SQL (6)
- PL/SQL collection (1)
- PL/SQL forward declaration (1)
- PL/SQL overload (1)
- PL/SQL subprogram (1)
- powermultiset (2)
- predicate negation (1)
- problem (2)
- replicate rows (1)
- reversing where clause logic (1)
- rollup (1)
- SalesForce (1)
- Salesforce to Oracle (1)
- save detail (1)
- sequence of numbers (1)
- Set_transfer_timeout (1)
- simple (1)
- SP2-004 (1)
- SP2-0734 (1)
- sql (1)
- sqlblanklines (1)
- SQLPLUS (2)
- sqlplus multiline (1)
- sqlplus multiline text (1)
- TABLE function (2)
- to Oracle (1)
- trigger (1)
- trouble (1)
- UTL_HTTP (1)
- UTL_HTTP Set_transfer_timeout (1)
- Utl_url Escape (1)
- Windows 7 Search (1)
- Windows Search (1)
- XMLAGG (2)
- XMLELEMENT (2)
3 comments:
This is a really slick little trick Mike. Thanks for sharing it!
I'm a little confused. Why would you do it this way?
If I wanted 5 rows from my Names table, I'd just
Select * from names where rownum < = 5
Hi,
If I have data like:
Mike,2
Fred,3
I want the output to be
Mike
Mike
Fred
Fred
Fred
In other words, the number of rows to be produced is indicated by the column value, in this case, 2 and 3.
Regards,
Mike
Post a Comment