Collection -- Nested tables
Hi,
I am trying to use collections as nested tables from below mentioned procedure, but facing a problem of getting only last rows.
Any help would be appreciated.
+CREATE OR REPLACE PROCEDURE pr_collection
AS
TYPE type_num IS TABLE OF NUMBER;
t_num type_num;
TYPE type_char IS TABLE OF VARCHAR2 (20);
t_char type_char;
BEGIN
FOR i IN (SELECT eid, nm
FROM emp)
LOOP
t_num := type_num (i.eid);
t_char := type_char (i.nm);
DBMS_OUTPUT.put_line (i.eid || i.nm);
END LOOP;
DBMS_OUTPUT.put_line (t_num.COUNT);
DBMS_OUTPUT.put_line (t_num.FIRST);
DBMS_OUTPUT.put_line (t_num.LAST);
FORALL J IN T_NUM.FIRST.. T_NUM.LAST
INSERT INTO TEST
VALUES (t_num (J), t_char (J));
COMMIT;
END;
/+
Output :
1
1
1
Thanks in Advance,
Prashant
Hi,
It's normal, you get only the last element because of the following
LOOP
t_num := type_num (i.eid);
t_char := type_char (i.nm);
END LOOP;Each time you call the nested table constructor with the new element, so the previous elements are lost. The correct way of doing this is to call once the constructor before the LOOP and then call the EXTEND method inside the loop in order to make room available for each new element.
Therefore, something like this:
CREATE OR REPLACE PROCEDURE pr_collection AS
TYPE type_num IS TABLE OF NUMBER;
t_num type_num;
t_num_idx PLS_INTEGER := 1;
TYPE type_char IS TABLE OF VARCHAR2 (20);
t_char type_char;
t_char_idx PLS_INTEGER := 1;
BEGIN
t_char := type_char();
t_num := type_num();
FOR i IN (SELECT eid, nm FROM emp) LOOP
t_num.EXTEND;
t_num(t_num_idx) := i.eid;
t_num_idx := t_num_idx + 1;
t_char.EXTEND;
t_char(t_char_idx) := i.nm;
t_char_idx := t_char_idx + 1;
DBMS_OUTPUT.put_line (i.eid || i.nm);
END LOOP;
DBMS_OUTPUT.put_line (t_num.COUNT);
DBMS_OUTPUT.put_line (t_num.FIRST);
DBMS_OUTPUT.put_line (t_num.LAST);
FORALL J IN T_NUM.FIRST.. T_NUM.LAST
INSERT INTO TEST VALUES (t_num (J), t_char (J));
COMMIT;
END;That being said, why do you add elements one by one, it is slow, why not using BULK COLLECT?
Regards,
Dariyoosh
Similar Messages
-
How to update nested table records ??
Hi, I am just starting to write anything in PL/SQL and having some difficulties with basic syntax. Thanks for any help in advance.
My problem is how to update collection (nested table of objects) with SQL statement. My nested table is not a column of regular table.
Example:
CREATE OR REPLACE TYPE tmpRec AS OBJECT(
Col1 INT,
Col2 INT
CREATE OR REPLACE TYPE tmpTable IS TABLE OF tmpRec;
DECLARE v tmpTable :=
tmpMBATable(
tmpRec(1,1),
tmpRec(2,2),
tmpRec(3,3),
BEGIN
--UPDATE TABLE(CAST(v AS tmpTable)) T SET T.Col2 = 1 WHERE T.Col1 =1;
--UPDATE TABLE(v) T SET T.Col2 = 12 WHERE T.Col1 =1;
--UPDATE (SELECT * FROM TABLE(v) )T SET T.Col2 = 12 WHERE T.Col =1;
END;
I am getting either
PL/SQL: ORA-22841: DML is not allowed on PL/SQL Collections
OR
PL/SQL: ORA-00903 Bad table name.
I found there is no problem when collection is a column of DB table (UPDATE TABLE(select collection_column from table) T SET T.Col2 = 12 WHERE T.Col1 =1;) but i want it to be just a collection without storing it in DB, is it possible ?
Please help.898539 wrote:
Thanks, for fast answer but my problem is more complex, maybe you can show me some workaround i try to use collection but maybe i should do something else...A complex problem does not mean a complex solution. In fact, complex problems should ideally be solved by breaking the complexity down into simpler components and then solving each of these in turn.
As far as nested tables go? An interesting feature. But one that I will need a lot of convincing and justification for to consider for a production system. There are some major limitations with using nested tables. And these do not exist when using the simpler form of a standard relational child table instead.
I am migrating from Sybase Adaptive Server Enterprise and searching for sollution for something we used temporary tables for so far.Temporary tables in Sybase are typically used to prevent concurrency issues (readers and writers blocking one another). Thus make a temp copy of the data and do not prevent concurrent access to the source data itself.
These reasons simply do not exist in Oracle. In most cases, using temporary tables in Oracle simply because that is how it was implemented in Sybase, would be fundamentally flawed.
Oracle is not Sybase. It does a very poor imitation of Sybase.
I need a collection that can store some data and I need to be able to use it as a table so I can join to it via SQL query or call some DML on it.Why do you need a collection? The best place for data in Oracle is inside a table. Not inside a collection - especially not if that collection resides in PGA memory in the PL/SQL engine.
In my store procedure I am updating, deleteing and inserting some data to it depends on context.What context? Oracle supports context namespaces - often used for virtual private database (VPDB) implementations. If you are referring to scope instead - there are a number of ways that Oracle supports scope too.
The bottom line is that you should not approach this problem with "+how do I convert this Sybase method into an Oracle method+". Instead you need to look at the business requirement that the Sybase method addresses and then determine how best to address that requirement using Oracle. -
Nested table collection in select query "in clause" taking long time
create or replace type t_circuitids is table of varchar2(100);
--Below anonymous block keeps on running and never ends
DECLARE
v_circuitid t_circuitids;
v_count number;
l_circuitids VARCHAR2 (4000)
:= 'value1,value2,value3,value4,value5';
BEGIN
--Below query converts comma concatinated output to list and stores in nested table collection v_circuitids
WITH a AS
(SELECT ',' || l_circuitids || ',' AS circuitid
FROM DUAL)
SELECT DISTINCT TRIM (SUBSTR (circuitid,
INSTR (circuitid, ',', 1, LEVEL) + 1,
INSTR (circuitid, ',', 1, LEVEL + 1)
- INSTR (circuitid, ',', 1, LEVEL)
- 1
) cid
BULK COLLECT INTO v_circuitid
FROM a
CONNECT BY LEVEL <
LENGTH (circuitid)
- LENGTH (REPLACE (circuitid, ','));
SELECT COUNT (1)
INTO v_count
FROM table
WHERE name IN (SELECT COLUMN_VALUE
FROM TABLE (v_circuitid));
END;
--I got the issue, query "SELECT COLUMN_VALUE FROM TABLE (v_circuitid)" which is used in above code is responsible for this.
--Same code works fine in Development and Test environments, But in prod it keeps on running
--I solved this issue by creating a temp table, loading all values in collection into the temp table and using that temp table in "in clause" "
--Can any one answer why its behaving like this when i use collection in where clause?
--I am using Oracle 9iBelow is the code i used
DECLARE
v_circuitid t_circuitids;
v_count number;
l_circuitids VARCHAR2 (4000)
:= 'value1,value2,value3,value4,value5';
BEGIN
--Below query converts comma concatinated output to list and stores in nested table collection v_circuitids
WITH a AS
(SELECT ',' || l_circuitids || ',' AS circuitid
FROM DUAL)
SELECT DISTINCT TRIM (SUBSTR (circuitid,
INSTR (circuitid, ',', 1, LEVEL) + 1,
INSTR (circuitid, ',', 1, LEVEL + 1)
- INSTR (circuitid, ',', 1, LEVEL)
- 1
) cid
BULK COLLECT INTO v_circuitid
FROM a
CONNECT BY LEVEL <
LENGTH (circuitid)
- LENGTH (REPLACE (circuitid, ','));
SELECT COUNT (1)
INTO v_count
FROM table
WHERE name IN (SELECT COLUMN_VALUE
FROM TABLE (ccard(v_circuitid)));
END;
And got below error
ORA-06550: line 27, column 5:
PL/SQL: ORA-00906: missing left parenthesis
ORA-06550: line 24, column 4:
PL/SQL: SQL Statement ignored -
Query Nested table (collection)
I try to query on a nested table (collection).
How ever, I get a 600 error.
Is there any way to reuse the result of query in the store procedure?
SQL> DECLARE
2 TYPE T_PER_ID IS TABLE OF PERIOD.PER_ID%TYPE;
3 V_EXP_PER_ID T_PER_ID;
4 V_EXP_PER_ID2 T_PER_ID;
5 BEGIN
6 SELECT PER_ID BULK COLLECT INTO V_EXP_PER_ID FROM PERIOD;
7 SELECT * BULK COLLECT INTO V_EXP_PER_ID2 FROM TABLE(V_EXP_PER_ID);
8 END;
9 /
DECLARE
ERROR at line 1:
ORA-00600: internal error code, arguments: [15419], [severe error during PL/SQL
execution], [], [], [], [], [], []
ORA-06544: PL/SQL: internal error, arguments: [pfrrun.c:pfrbnd1()], [], [], [],
ORA-06553: PLS-801: internal error [0]Oracle Version 8.1.6
-
What is Varray,Nested tables,Collections,Pragma?
Hi,
what is Varray,Nested tables,Collections,Pragma?
and in Which Situations will We Use this?.
Anyone having any dea regarding this?http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96624/05_colls.htm
http://awads.net/wp/2006/03/01/pragmatism-in-oracle-plsqlKhurram -
Error in bulk collect into nested table
I keep getting an error while trying to compile this line:
fetch c_juros bulk collect into wrk_juros_plano(p_ind_segreg);
LINE/COL ERROR
0/0 PLS-00801: internal error [74306]When i put that single line into comments it goes fine. Sure it doesn't do what I want.
The data structure i use is as follows:
cursor c_juros(p_ind_segreg in varchar2) is
select (((power(1 + (i.prc_juros_atuari_ano / 100), 1 / 12) - 1) * 100) / 100) prc_juros_efetiv_mes,
i.dat_inic_vigenc,
(nvl(i.dat_fim_vigenc, sysdate) + 1) dat_fim_vigenc,
i.ind_segreg
from v_indexador_taxa_atuarial i
where i.ind_segreg = p_ind_segreg
order by i.dat_inic_vigenc;
type t_juros_plano is table of c_juros%rowtype;
type t_tab_juros_plano is table of t_juros_plano index by binary_integer;
wrk_juros_plano t_tab_juros_plano;the code goes like this:
begin
if not(wrk_juros_plano.exists(p_ind_segreg))
then
if c_juros%isopen
then
close c_juros;
end if;
open c_juros(p_ind_segreg);
wrk_juros_plano(p_ind_segreg) := t_juros_plano();
fetch c_juros bulk collect into wrk_juros_plano(p_ind_segreg);
end if;
...p_ind_segreg is my input parameter, that should be the index of the array.
The purpose is to create the parameter indexed element if it doesn't already exist, fetching it
from the cursor, that defines a nested table.
I tried removing the initialization line to no effect, among other things.Ok, I just found out a way around it. It works, but that error is probably a bug, cause workarounds are not really cute.
I declared a nested table compatible with the element from the associative array:
wrk_juros t_juros_plano;and chaged that line that was causing the error
fetch c_juros bulk collect into wrk_juros_plano(p_ind_segreg);for
fetch c_juros bulk collect into wrk_juros;
wrk_juros_plano(p_ind_segreg) := wrk_juros;Awesome =\ -
Collections stored as Nested tables
I have created a Table with XMLTYPE column and the
column is defined as Object against a registered Schema.
I have also created nested tables for all collection types
and created appropriate indexes on the Nested tables
based on Nested_table_Id and array_index.
CREATE TABLE STATEMENT_DATA
TEST SYS.XMLTYPE
XMLTYPE COLUMN TEST STORE AS OBJECT RELATIONAL
XMLSCHEMA "StatementData.xsd"
ELEMENT "StatementData"
varray TEST."XMLDATA"."MessagePayload"."BillDeterminant"
STORE AS table BillDeterminant
( varray "AttributeList" STORE AS table BillDtr_AttrList,
varray "ChargeProfileData" STORE AS table BillDtr_ProfData )
varray TEST."XMLDATA"."MessagePayload"."MarketStatement"
STORE AS table MarketStatement
(varray "MarketStatementLineItem" STORE AS table marketlineitm
( varray "PassThroughBill"."AttributeList" STORE AS table Lineitm_ChargeProf_AttrList,
varray "PassThroughBill"."ChargeProfile" STORE AS table Lineitm_ChargeProfile
(varray "ChargeProfileData" STORE AS table ChargeProfileData),
varray "AttributeList" STORE AS table Lineitm_AttributeList),
varray "RTO" STORE AS table Rto
(varray "ErpAddress" STORE AS table rto_ErpAddress,
varray "ErpPerson" STORE AS table rto_Erpperson
(varray "ErpTelephoneNumber" STORE AS table rto_ErpTelephoneNumber)) ,
varray "Customer" STORE AS table Customer
(varray "ErpAddress" STORE AS table Cust_ErpAddress,
varray "ErpPerson" STORE AS table cust_Erpperson
(varray "ErpTelephoneNumber" STORE AS table cust_ErpTelephoneNumber)) ,
varray "ActivityRecord" STORE AS table ActivityRecord)
Sample Index :
CREATE UNIQUE INDEX MARKETLINEITM_indx1 ON MARKETLINEITM d
( d.NESTED_TABLE_ID,d.array_index);
Now when I tried to execute a sample query involving some of the
nested tables , Explain Plan shows that it is not using the indexes
I have created.
The following parameters are also set in the Database.
query_rewrite_enabled : TRUE
query_rewrite_integrity : TRUSTED.
I am using Oracle 9.2.0.5.0.
Can somebody tell me if I am missing something?
Thanks,
ArunThanks for the reply. XMPTYPE based column is not using the
indexes even after gathering Index statistics. However the Statistics
gathering is helping queries based on XMLTYPE based tables.
Any suggestion for XMLTYPE based columns ? Has anybody
been able to successfully use the indexes in 10g ?
Arun -
Associative Array to Nested Table: Anything faster?
(First Post! Some ASP.NET references, but I think this really is a PL/SQL question)
I work on a team that runs an Oracle instance for data warehousing and reporting along with an ASP.NET based website for display.
Sometimes, I may want to have many parameters come in and only show records that match those parameters. For example, I may want to show all employees who are Managers or Developers and not show employees who are Accountants or Scientists. Typically, I send a parameter into my PL/SQL stored procedures as an associative array (as declared in my package specification). Once in the procedure, I convert that associative array into another associative array (as a user created SQL type) and then I'm able to use it like a nested table to join on.
My question is: in your experience, is there any way to get around this type conversion or another faster way?
For example:
-- Create the sql type
CREATE OR REPLACE TYPE DIM.sql_string_table AS TABLE OF VARCHAR2(255);
--pretend that this works and it's in a package body
declare
type string_table is table of varchar2(255) index by binary_integer;
l_job_types string_table; -- Keep in mind I'd normally be sending this via ASP.NET
l_job_types_nested sql_string_table := sql_string_table();
begin
-- Add some data
l_job_types(0) := 'Manager';
l_job_types(1) := 'Developer';
-- Do the conversion
for i in l_job_types.first .. l_job_types.last
loop
l_job_types_nested.extend;
l_job_types_nested(l_job_types_nested.count) := l_job_types(i);
end loop;
-- get some data out (we're pretending)
open fake_ref_cursor for
Select e.*
from employees e,
the(select cast(l_job_types_nested as sql_string_table) from dual) jobs_types_wanted
where e.type = value(jobs_types_wanted);
end;
The result would be all employees whose have a type that was input into the l_job_types associatve array.
See: http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:110612348061
for additional reference> I convert that associative array into another associative array (as a user created SQL type)
Just so we're clear, Oracle use the term 'associative array' to refer to the exclusively PL/SQL sparse collection type ("table of x index by pls_integer" etc) as distinct from the common nested table collection type.
Also I could be wrong but I think
SELECT ..
FROM the(select cast(l_job_types_nested as sql_string_table) from dual) jobs_types_wantedis generally the same as
SELECT ..
FROM TABLE(l_job_types_nested) jobs_types_wantedthough "SELECT *" and implicitly collection casting don't always mix. The "THE()" syntax is deprecated. -
Problem in creating a nested table
Hi i am working on Oracle 10g and cleint is sqlplus.
Now while creating a nested table following error occured.
This is the script for your reference.:
CREATE OR REPLACE TYPE sec_pwd_hist_table
AS
TABLE OF sec_pwd_history_type
index by binary_integer
Warning: Type created with compilation errors.
SQL> show error
Errors for TYPE SEC_PWD_HIST_TABLE:
LINE/COL ERROR
0/0 PL/SQL: Compilation unit analysis terminated
3/1 PLS-00355: use of pl/sql table not allowed in this context
Please help on this issue
Regards,
Vikas Kumar> but i want to know just one thing why its working when i am removing "INDEX BY binaty_integer"
Vikas, I trust I answered that question when I said? :
"Do not confuse the two. Do not attempt to use PL/SQL array struct definition syntax in the SQL engine for defining an ADT collection. Which is why I referred you to the manual to see how an ADT is defined in SQL."
In other words, you are trying to apply a PL/SQL concept and PL/SQL syntax to a definition of a data type in SQL.
SQL is not PL/SQL.
SQL ADTs are not PL/SQL arrays/tables.
It is not even a syntax issue - it is a basic concept issue. SQL does not support PL/SQL arrays/tables. Period. -
Loading Nested table with SQL Loader
We have 15 nested tables in an table. Need help in creating a contol file. Tried with the syntax of object collection and didn't work. Can any none share the syntax please.
-- Thanks,
Phani AdusumilliThanks Srini and Zoltan.
I am able to figure out, here is the example with one nested table.
CREATE OR REPLACE TYPE feature_count_type AS OBJECT (
feature_type VARCHAR2(60),
occurs INTEGER
CREATE OR REPLACE TYPE feature_count_ntbl
AS TABLE OF feature_count_type;
CREATE TABLE PHANI_ADUSUMILLI(
state VARCHAR2(2),
county VARCHAR2(20),
feature_count feature_count_ntbl
) NESTED TABLE feature_count
STORE AS nested_feature_count_table;
LOAD DATA
INFILE *
TRUNCATE INTO TABLE PHANI_ADUSUMILLI
county CHAR TERMINATED BY ',' ENCLOSED BY '"',
element_count FILLER INTEGER EXTERNAL TERMINATED BY ',',
feature_count NESTED TABLE COUNT(element_count)
dummy_name COLUMN OBJECT
feature_type CHAR TERMINATED BY ',',
occurs INTEGER EXTERNAL TERMINATED BY ','
state CHAR TERMINATED BY ','
BEGINDATA
"Alger",5,lake,213,stream,88,falls,18,bay,11,island,5,MI
"Marquette",6,lake,293,stream,145,falls,5,bay,8,island,5,summit,23,MI
"Keweenaw",3,lake,86,falls,1,summit,16,MI -
Null value in Nested table of nested table for xml guru Steve Muench
The procedure I am using takes xml document with nested levels and insert into single table using DBMS_XMLSave.insertXML.
I am able to insert into table without any error message but when I am selecting row from table, it is showing null values in all the column of nested table's inner nested table.
When I am removing nested table's nested table by replacing with object type, it is showing data of object type for the first occurance and ignoring the rest nested occurance.
Help is greatly appreciated.
Below is the sql I used to create objects and table:-
Create or Replace Type addressType as Object
Line_one varchar2(40),
Line_two varchar2(40),
City Varchar2(30),
State Varchar2(2),
zip Varchar2(10)
Create or Replace Type ce_reqType as Object
Status varchar2(25),
Status_date Date,
type_code Varchar2(25),
review_begin_date Date,
assigned_review_date date
Create or Replace type ce_reqListType
as table of ce_reqType;
Create or Replace Type LicenseType as Object
type_code Varchar2(10),
license_number Varchar2(16),
ce_requirements ce_reqListType
Create or Replace type LicenseListType
as table of LicenseType;
Create table IndividualType
individual_id Number(9),
social_security_number Varchar2(9),
Last_name varchar2(40),
First_name Varchar2(40),
Middle_name Varchar2(40),
Birth_date Date,
address addressType,
Licenses LicenseListType
nested table licenses store as licensestab
(nested table ce_requirements store as lic_ce_reqtab);Maddy wrote:
dbms_output.put_line('The count is '||bookset.count); --> I can see COUNT =1 (why)Because instead of adding an element to bookset collectionto are assigning (ergo replacing) it a collection containing last fetched book. Use:
declare
bookset book_table;
ln_cnt pls_integer;
begin
bookset := book_table(book_obj('madhu','kongara','sudhan'));
dbms_output.put_line('The count is '||bookset.count); --> I can see COUNT =1
bookset := book_table(); --> Assigning back to NULL.
dbms_output.put_line('The count is '||bookset.count); --> I can see count as 0
for rec in (select * from book) loop --> Now Looping two times.
dbms_output.put_line(' name > '||rec.name);
bookset.extend;
bookset(bookset.count) := book_obj(rec.name, rec.author, rec.abstract);
end loop;
dbms_output.put_line('The count is '||bookset.count); --> I can see COUNT =1 (why)
end;
The count is 1
The count is 0
name > Harry Potter
name > Ramayana
The count is 2
PL/SQL procedure successfully completed.
SQL> Or better use bulk collect:
declare
bookset book_table;
ln_cnt pls_integer;
begin
bookset := book_table(book_obj('madhu','kongara','sudhan'));
dbms_output.put_line('The count is '||bookset.count); --> I can see COUNT =1
bookset := book_table(); --> Assigning back to NULL.
dbms_output.put_line('The count is '||bookset.count); --> I can see count as 0
select book_obj(name,author,abstract)
bulk collect
into bookset
from book;
for i in 1..bookset.count loop --> Now Looping two times.
dbms_output.put_line(' name > '||bookset(i).name);
end loop;
dbms_output.put_line('The count is '||bookset.count); --> I can see COUNT =1 (why)
end;
The count is 1
The count is 0
name > Harry Potter
name > Ramayana
The count is 2
PL/SQL procedure successfully completed.
SQL> SY. -
Inserting data with the help of nested table...!!!
The following block is giving error
ORA-06502: PL/SQL: numeric or value error
the signature and signature_bkp have the same structure
So, can anybody help me out to solve this issue :
for copying records from one table to another table
Thanking You advancely
DECLARE
CURSOR c1
IS
SELECT *
FROM signature
WHERE creation_time > TRUNC ( SYSDATE ) - 100
AND ROWNUM < 102;
TYPE sig_typ IS TABLE OF signature%ROWTYPE;
sig_t sig_typ;
BEGIN
OPEN c1;
FETCH c1
BULK COLLECT INTO sig_t;
CLOSE c1;
FORALL i IN sig_t.FIRST .. sig_t.LAST
INSERT INTO signature_bkp
VALUES sig_t ( i );
COMMIT;
END;
--DKarOr whether a INSERT statement with SELECT clause will do that for youby using this technique, it took 47:08:45 to copy 7252 rows
and by using a cursor for loop took 49:03:23 to copy 13567 rows
So there was appox. 40% increase in performance by using pl/sql. I thought it could be even faster using the bulk-bind ing features and nested tables.
OR i just want to know ....how to correct the block of code that was given in my 1st msg without changing its logic.
Thanks
--DKar -
Confusion over nested tables and system generated nested tables
Hi,
I have been reading other threads about nested tables, naming and updating them etc, but I have what seems
to me some odd behaviour.
I modified my schema to set the attribute xdb:maintainDom to be false for a collection and then registered
the schema with the generate tables option defaulted to true. The result was that I had to add xdb:tableProps
attributes specifying nested table storage at each element above the collection element, this was because Oracle
was creating tables at each level. So I have this kind of thing:
<xsd:element name="BibPt" xdb:SQLType="BIBPT_T"
xdb:defaultTable="BIBPT"
xdb:tableProps="NESTED TABLE XMLDATA.PTEES.PTEE_SEC.PTEE STORE AS NESTED_PTEE_SEC
NESTED TABLE XMLDATA.INVS.INV STORE AS NESTED_INV_BIBPT TABLESPACE BIBLIO">
<xsd:element name="Ptees" xdb:SQLType="PTEES_T" xdb:tableProps="NESTED TABLE
XMLDATA.PTEE_SEC.PTEE STORE AS NESTED_PTEE_SEC2">When I did this the nested tables were created, but when I loaded data never had anything in them. Instead
I found that nestes tables with systems generated names like "SYSNTxxxxxxxxx" has been created that contained
the data.
When I registered the schema without the tables being generated, I created a table with this syntax:
create table poc_wip2 of xmltype
xmlschema "http://www.derwent.co.uk/wpi.xsd" element "WPI"
NESTED TABLE XMLDATA."BibPt".PTEES.PTEE_SEC.PTEE STORE AS NESTED_PTEE_SEC
NESTED TABLE XMLDATA."BibPt".INVS.INV STORE AS NESTED_INV_BIBPT(Thanks to a posting by Sam Monsarrat which showed me this was possible).
Now I had my named nested tables, which contained the data after it was loaded and no system named
nested tables.
So why the difference?
In the first instance why do my named nested tables stay empty and why does the data go into system
generated tables I have no control over as regards tablespace placement?
Is it possible to have a XML schema registered that only generates tables that I have named with the defaultTable
attribute, rather than all or nothing?
And last but not least, what's the best approach for this, since I want to be able to access the data via indexes
on the nested tables.
Thanks
PeteHi Pete
Would you please publish the schema you are using?
Thanks,
Tobias -
Hi ,
Please assist as how can we do this thing
i have a nested table of object type
create or replace type a1 as object
a number,
b varchar2(30),
region varchar2(30)
create type a1_array s table of a1;
declare
v_a1 a1;
v_a1_array a1_array:=a1_array();
begin
v_a1= a1(1, '1' , 'AUS');
v_a1_array.EXTEND;
v_a1_array(1):=v_a1;
v_a1= a1(2, '2' , 'AUS');
v_a1_array.EXTEND;
v_a1_array(2):=v_a1;
v_a1= a1(3, '3' , 'NAM');
v_a1_array.EXTEND;
v_a1_array(3):=v_a1;
end;
Now, i have v_a1_array having 3 rows 2 with AUS region and one with NAM region.
Using SQL can i extract only 'AUS' rows and fetch in ARRAY OF TYPE v_a1_array (using Where clause and Table () functions )
Any help will be highly appreciated. Please assist. I have oracle 11g
ThanksHi,
GPU has already shown you how to do. I will just modify my original one:
SQL*Plus: Release 11.2.0.1.0 Production on Thu Aug 22 22:14:42 2013
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> set serveroutput on
SQL>
SQL> DECLARE
2 v_a1 a1;
3 v_a1_array a1_array := a1_array ();
4 v_a1_array2 a1_array;
5 BEGIN
6 v_a1 := a1 (1, '1', 'AUS');
7 v_a1_array.EXTEND;
8 v_a1_array (1) := v_a1;
9 v_a1 := a1 (2, '2', 'AUS');
10 v_a1_array.EXTEND;
11 v_a1_array (2) := v_a1;
12 v_a1 := a1 (3, '3', 'NAM');
13 v_a1_array.EXTEND;
14 v_a1_array (3) := v_a1;
15
16 SELECT a1(a, b, region)
17 BULK COLLECT INTO v_a1_array2
18 FROM TABLE (v_a1_array)
19 WHERE region = 'AUS';
20
21 FOR c1 IN (SELECT *
22 FROM TABLE (v_a1_array2))
23 LOOP
24 DBMS_OUTPUT.put_line ('A='||c1.a||', B='||c1.b||', REGION='||c1.region);
25 END LOOP;
26 END;
27 /
A=1, B=1, REGION=AUS
A=2, B=2, REGION=AUS
PL/SQL procedure successfully completed.
If you consider your question answered, please mark this thread as answered.
Regards.
Alberto -
How do you "Instantiate" a Nested Table from within a FUNCTION?
, I managed to compile and create the FUNCTION.
But when I invoked it,
ORA-06531: Reference to uninitialized collection
ORA-06512: at "DEV.SPGETPARENTSTABLE", line ...
I think I need to somehow *"Instantiate"* the Nested Table and I didn't:
CREATE OR REPLACE FUNCTION spGetParentsTable
ObjectId number,
ObjectClassifier varchar2
RETURN types.TmpHiearchyMapTableType
IS
TmpHierarchyMap types.TmpHiearchyMapTableType;
ThisTempId varchar2(32);
CURSOR spGetParents_cursor IS
SELECT
ReferencedId Id,
ParentId,
ChildId,
FROM TMP_HIERARCHYMAP
WHERE TmpUID = ThisTempId;
BEGIN
SELECT sys_guid() INTO ThisTempId FROM dual;
spRecursiveGetParents(ObjectId, ObjectClassifier, ThisTempId);
FOR oMap in spGetParents_cursor LOOP
TmpHierarchyMap.Extend(); **** BUT I haven't "Instantiate" the Nested Table yet ****
TmpHierarchyMap(TmpHierarchyMap.Count) := TmpHierarchyMapObjType( oMap.Id
, oMap.ParentId
, oMap.ChildId
END LOOP;
DELETE FROM TMP_HIERARCHYMAP WHERE TmpUID = ThisTempId;
RETURN TmpHierarchyMap;
END spGetParentsTable;It's annonyingly trivial to fix. In your declaration section try
TmpHierarchyMap types.TmpHiearchyMapTableType := types.TmpHiearchyMapTableType();
...Cheers, APC
blog: http://radiofreetooting.blogspot.com
Maybe you are looking for
-
Problem with successive calls to ItembyDN
I have a loop that looks at multiple GW users and performs various functions against the user. Everything works the first pass through the loop no mater what operation is executed. Any successive passes through the loop causes an access violation err
-
PLEASE HELP! Error Message When Trying to Publish Site
No matter how many of these errors I fix (edit the file and re-upload it onto the site), Muse comes up with a new error every time I try and publish. How can I resolve this issue, so I can publish my updated site. It should not be a problem with the
-
what is the diff btw start of selection and end of selection
-
Hi to everybody, I'm learning Java and I would like to know what's the difference between extending the Thread class and implementing the Runnable interface. Why when I run two objects that are instances of a Runnable class they seem to run concurren
-
Acrobat 8 cannot be launched at this time
I inherited a lab MacBook and tried to install my copy of Acrobat 8 onto it but I got the message that it could not be launched and that I must open one other suite component. The previous user removed all the Adobe suite components before turning th