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
Saturday, September 22, 2007
Using Dynamic Sql to work around PL/SQL bugs
A coworker encountered this problem. We search the Internet for a solution, but nothing was found. I am hoping that by posting this, others having the same problem will quickly find a solution. Furthermore, this example illustrates a more general principle which is that sometimes things work in SQL which do not work in PL/SQL and a simple solution is to use dynamic sql.
This problem is encountered when trying to access an NVARCHAR2 using a TABLE function in PL/SQL.
ORA-12714: invalid national character set specified
Originally written as:
FOR c IN ( SELECT * FROM TABLE (p_question_tab_i) ) LOOP
Processing….
END LOOP;
Raises error: ORA-12714: invalid national character set specified
Then re-written using dynamic SQL:
OPEN que_cursor FOR 'SELECT * FROM TABLE (:question_tab)'
USING p_question_tab_i;
The above example works correctly…
question_tab TABLE OF QUESTION_OBJis
SELECT_TYPE VARCHAR2(10)
DISPLAY_TEXT NVARCHAR2(4000)
PROMPT_TYPE_CODE VARCHAR2(50)
Technically, this is not a PL/SQL bug. It is, however, a feature that is supported in SQL but not PL/SQL. This often happens with new SQL features where PL/SQL has not 'caught up' yet.
Labels: dynamic cursor, example, nvarchar2, ORA-12714, PL/SQL, TABLE function
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)