Nested table of Object View
Hi all!
1. I need canonical form of XML from my XSQL servlet. So I write
select * from my_obj_view;
2. When I need to use 'where' condition for nested table in object view, I do follows:
select * from my_object_view o, TABLE(o.my_nested_table) n where n.col_name = 5;
But result has not such form as in first example (has form of relational table w/o nested data of nested table). When I write:
select * from my_obj_view where my_obj_view.nested_table.col_name = 5;
I got error: ORA-00904: invalid column name
Please, where I am wrong?
I'm not sure what you are looking for exactly but is it something like this?
SELECT id
, p.ctx_name
, p.ctx_value
FROM tt
, TABLE(ctx) pWith the following test data:
INSERT INTO tt VALUES(1,CTX_TAB(CTX_LINE('A','SOME VALUE1')));
INSERT INTO tt VALUES(1,CTX_TAB(CTX_LINE('B','SOME VALUE2')));
INSERT INTO tt VALUES(1,CTX_TAB(CTX_LINE('B','SOME VALUE2')));this is the result:
SQL> SELECT id
2 , p.ctx_name
3 , p.ctx_value
4 FROM tt
5 , TABLE(ctx) p
6 /
ID CTX_NAME CTX_VALUE
1 A SOME VALUE1
1 B SOME VALUE2
1 B SOME VALUE2
Similar Messages
-
Performance impact using nested tables and object
Hi,
Iam using oracle 11g.
While creating a package, iam using lot of nested tables created based on objects which will be passed between multiple functions in the package..
Will it have any performance impact since all the data is stored in the memory.
How can i measure the performance impact when the data grows ?
Regards,
Oracle User
Edited by: user9080289 on Jun 30, 2011 6:07 AM
Edited by: user9080289 on Jun 30, 2011 6:42 AMuser9080289 wrote:
While creating a package, iam using lot of nested tables created based on objects which will be passed between multiple functions in the package.. Not the best of ideas in general, in PL/SQL. This is not client code that can lay sole claim to most of the memory. It is server code and one of many server processes that need to share the available resources. So capitalism is fine on a client, but you need socialism on the server? {noformat} ;-) {noformat}
Will it have any performance impact since all the data is stored in the memory.Interestingly yes. Usually crunching data in memory is better. In this case it may not be so. The memory used is the most expensive memory Oracle can use - the PGA. Private process memory. This means each process copy running that code, will need lots of memory.
If you're not passing the data structures by reference, it means even bigger demands on memory as the data structure needs to be copied into the call stack and duplicated.
The worse case scenario is that such code consumes so much free server memory, and make such huge demands on having that in pysical memory, it trashes memory management as the swap daemons are unable to keep up with the demand of swapping virtual memory pages into and out of memory. Most CPU time is spend by the swap daemons.
I have seen servers crash due to this. I have seen a single PL/SQL process causing this.
How can i measure the performance impact when the data grows ?Well, you need to look at the impact of your code on PGA memory. It is not SQL performance or I/O performance that is a factor - just how much private process memory your code needs in order to execute. -
How to cast RECORD of nested tables into OBJECT of nested tables
Right, we have an existing massive pl/sql package where some of the processing is taking too long so they want to try multithreading it.
The data in this package is stored in an array of records which contains nested tables, which themselves contain nested tables.
So, we want to split this table into 10, and submit them to 10 dbms_jobs to run concurrently, write the modified arrays to the database so they can be picked up again by the original process.
I'm stuck on converting the associative array of data (containing tables of records) into objects which can be stored in the DB.
My database objects:
CREATE OR REPLACE
TYPE ktest_claims_rt IS OBJECT
col1 varchar2(10)
,col2 varchar2(10));
CREATE OR REPLACE
TYPE ktest_claims_tt IS TABLE OF ktest_claims_rt;
CREATE OR REPLACE
TYPE ktest_driver_rt IS OBJECT
col1 varchar2(10)
,col2 varchar2(10)
,claims_nt ktest_claims_tt);
CREATE OR REPLACE
TYPE ktest_driver_tt IS TABLE OF ktest_driver_rt;
CREATE OR REPLACE
TYPE ktest_policy_rt IS OBJECT
col1 varchar2(10)
,col2 varchar2(10)
,driver_nt ktest_driver_tt);
CREATE OR REPLACE
TYPE ktest_policy_tt IS TABLE OF ktest_policy_rt;
CREATE TABLE ktest_job_table
(job_no NUMBER
,tab_type VARCHAR2(3)
,policy_nt ktest_policy_tt
NESTED TABLE policy_nt STORE AS policy_nested_tab
(NESTED TABLE driver_nt STORE AS driver_nested_tab
(NESTED TABLE claims_nt STORE AS claims_nested_tab))
/ And my local package versions:
TYPE claims_rt IS RECORD
col1 varchar2(10)
,col2 varchar2(10));
TYPE claims_tt IS TABLE OF claims_rt INDEX BY PLS_INTEGER;
TYPE driver_rt IS RECORD
col1 varchar2(10)
,col2 varchar2(10)
,claims_nt claims_tt);
TYPE driver_tt IS TABLE OF driver_rt INDEX BY VARCHAR2(20);
TYPE policy_rt IS RECORD
policy_no policy.policy_no%TYPE
,driver_tab driver_tt
,other_col VARCHAR2(20));
TYPE policy_tt IS TABLE OF policy_rt
INDEX BY pls_integer;
main_table policy_tt;What I can't get through my pea sized brain is how to turn "main_table" into an array based on ktest_policy_tt.
I got as far as:
FUNCTION convert (p_table IN policy_tt) RETURN ktest_policy_tt
IS
db_vers ktest_policy_tt := ktest_policy_tt();
db_rec ktest_policy_rt;
BEGIN
FOR i IN p_table.FIRST..p_table.LAST
LOOP
db_rec := ktest_policy_rt(p_table(i).policy_no
,p_table(i).other_col
,ktest_driver_tt(p_table(i).driver_tab(i).col1
,p_table(i).driver_tab(i).col2
,ktest_claims_tt(p_table(i).driver_tab(i).claims_nt(i).col1
,p_table(i).driver_tab(i).claims_nt(i).col1
db_vers(i) := db_rec;
END LOOP;
END;but, apart from the fact that it only coverts the first row of each table, it doesn't compile:
LINE/COL ERROR
139/10 PL/SQL: Statement ignored
143/52 PLS-00306: wrong number or types of arguments in call to
'KTEST_CLAIMS_TT'
143/52 PLS-00306: wrong number or types of arguments in call to
'KTEST_CLAIMS_TT'I'd appreciate any help as this is getting urgent.
Thanks!I would recommend writing your function in a more stepwise, explicit fashion rather than trying to write the conversion as basically one big constructor.
Firstly, you will require nested loops in your pl/sql code for the different levels of nested tables. This is not a choice, you need to do this.
Within each level of looping, explicitly create the object of the desired type before adding it to the table / record as need be.
cheers,
Anthony -
Varray, Nested Table and Object types in OWB r2
Requirement:
Flat file with repeating groups of nested content need to move into Object Relational ORACLE table (using varray or nested tables - no preference). The data will be loaded, then mapped/transformed into a richer O-R output to directly produce XML outputs.
Problem:
Generated PL/SQL "seems" to do the correct thing, but deployment errors show failures on mapping of collections (varrays, NTs or OTs) and in sqlplus recompiling the PKB still gives the errors. Is this a PL/SQL generator error, or is there a more meaningful example of using CONSTRUCT OBJECT operator than the embedded odcumentation - it is a simple type (single instance) and not a variable repeating group of nested data.
Anyone had any success with these, or know of any collateral to assist in the process. Thanks.The process we are following is very simple. We are talking 10 columns from a source flat file table and wish to map this into a Varray/Nested table, with one column of Varchar2(10).
When you create your map in OWB, select the construct object, you have to choose an object type - it does not allow you to select a VARAAY or NESTED table.
I have then created an object defined in the same structure as the VARRAY/NESTED table - I have then made the VARRAY/NESTED table of this TYPE.
Example:
CREATE OR REPLACE TYPE "O_REL_PUB_INDEX" AS OBJECT (
X_REL_PUB_INDEX_1 VARCHAR2(10))
CREATE OR REPLACE TYPE "V_REL_PUB_INDEX" AS VARRAY(15) OF O_REL_PUB_INDEX
In OWB you can then select O_REL_PUB_INDEX when creating the 'Contruct Object'.
The problem I have is that when I map to my target column of type V_REL_PUB_INDEX and DEPLOY my map I get the following errors taken from OWB control centre
Name
Action
Status
Log
TEST
Create
Warning
ORA-06550: line 2931, column 9:
PL/SQL: SQL Statement ignored
TEST
Create
Warning
ORA-06550: line 3174, column 11:
PL/SQL: ORA-00932: inconsistent datatypes: expected OWB_USER.O_REL_PUB_INDEX got OWB_USER.V_REL_PUB_INDEX
TEST
Create
Warning
ORA-06550: line 401, column 7:
PL/SQL: SQL Statement ignored
TEST
Create
Warning
ORA-06550: line 643, column 13:
PL/SQL: ORA-00932: inconsistent datatypes: expected OWB_USER.O_REL_PUB_INDEX got OWB_USER.V_REL_PUB_INDEX
TEST
Create
Warning
ORA-06550: line 7221, column 9:
PL/SQL: SQL Statement ignored
TEST
Create
Warning
ORA-06550: line 7464, column 11:
PL/SQL: ORA-00932: inconsistent datatypes: expected OWB_USER.O_REL_PUB_INDEX got OWB_USER.V_REL_PUB_INDEX
Any ideas? anyone succesfully mapped to either a VARRAY or an NESTED TABLE target column? -
Error when creating table with nested table of object
Dear all,
I tried to create a table that contains nested table of an object but got an error:
create or replace type some_obj is object (
a number, b blob
4 /
Type created.
create or replace type some_type is table of some_obj;
2 /
Type created.
SQL>
create table test (obj_id number, temp some_type) nested table temp store as nes_tab;
Table created.
SQL> create table test (obj_id number, temp some_type) nested table temp store as nes_tab
ERROR at line 1:
ORA-00955: name is already used by an existing objectWhat is causing the error? How can I troubleshoot this?
best regards,
ValValerie Debonair wrote:
never mind, I put "/" at the end of the create statement that makes executing create table twice....Yep. If I'm writing a script, I tend to just stick with "/" for all my statements, including the SQL as well as the DDL, otherwise it can be confusing whether a ";" is needed or not or whether it will try and execute it twice like you found.
"/" works for all. -
Converting Relational Tables to Object Views
We have extra information stored for each
field in a table. We call these Vertical
Tables:
rowid primary key - ties to normal tab
column_name "" - ties to column in ""
text_value the value if text
reliability rating for level of accuracy...
date of entry
Yes there are normal tables that the applications also access if they just need the value of the columns.
So I want to take this to object views. This way, while oracle is learning how to alter objects, we can still maintain our data and old application while converting to the use of objects.
I thought the best solution would be Type(s) based on the orignal data type. A generic type, text65_t could be created to hold every column that is less than 65 characters long:
CREATE TYPE text65_t AS OBJECT
WITH OBJECT IDENTIFIER(row_id) AS
row_id VARCHAR2(30),
value VARCHAR2(65),
reliability NUMBER(1,0),
doe DATE
A view can easily be created of this. The
mapping is one to one.
My problem is the next level. How can I build another view on top of text65_t, integer_t, date_t... that ties all of the
vertical rows back into a normal relational table or object.
Thanks,
bill
nullHi migration group,
I realize this is kind of off topic for
this discussion group. Where can I ask
questions like this?
thanks
bill -
Adding nested table to object table
if I alter an object type and add a nested table to it, there seem to be no syntax to add "STORE AS" clause for that nested table in the object table containing the altered object type. E.G.:
ALTER TYPE fd_dao ADD ATTRIBUTE Own_Name Own_Name_ntt;
where Own_Name_ntt is a nested table type, then
ALTER TABLE FD_DOT NESTED TABLE Own_Name STORE AS Own_Name_ntab;
does not work but the table FD_DOT can not be used since it lacks the storage for the newly added nested table.Check your syntax.
CREATE TYPE Own_Name_ntt AS TABLE OF VARCHAR2(25);
CREATE TYPE fd_dao AS OBJECT
(col1 date
,col2 number);
CREATE TABLE fd_dot(cola varchar2(10)
,colb date);
ALTER TYPE fd_dao ADD ATTRIBUTE Own_Name Own_Name_ntt;
ALTER TABLE FD_DOT ADD (Own_Name Own_Name_ntt)
NESTED TABLE Own_Name STORE AS Own_Name_ntab;
SQL> CREATE TYPE Own_Name_ntt AS TABLE OF VARCHAR2(25);
2 /
Type created.
SQL>
SQL> CREATE TYPE fd_dao AS OBJECT
2 (col1 date
3 ,col2 number);
4 /
Type created.
SQL>
SQL> CREATE TABLE fd_dot(cola varchar2(10)
2 ,colb date);
Table created.
SQL>
SQL> ALTER TYPE fd_dao ADD ATTRIBUTE Own_Name Own_Name_ntt;
Type altered.
SQL>
SQL> ALTER TABLE FD_DOT ADD (Own_Name Own_Name_ntt)
2 NESTED TABLE Own_Name STORE AS Own_Name_ntab;
Table altered.
SQL> desc fd_dot
Name Null? Type
COLA VARCHAR2(10)
COLB DATE
OWN_NAME OWN_NAME_NTT
SQL> desc fd_dao
Name Null? Type
COL1 DATE
COL2 NUMBER
OWN_NAME OWN_NAME_NTT
SQL> disconnect
Disconnected from Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining options
SQL> CREATE TYPE Own_Name_ntt AS TABLE OF VARCHAR2(25);
2 /
Type created.
SQL>
SQL> CREATE TYPE fd_dao AS OBJECT
2 (col1 date
3 ,col2 number);
4 /
Type created.
SQL>
SQL> CREATE TABLE fd_dot(cola varchar2(10)
2 ,colb date);
Table created.
SQL>
SQL> ALTER TYPE fd_dao ADD ATTRIBUTE Own_Name Own_Name_ntt;
Type altered.
SQL>
SQL> ALTER TABLE FD_DOT ADD (Own_Name Own_Name_ntt)
2 NESTED TABLE Own_Name STORE AS Own_Name_ntab;
Table altered.
SQL> desc fd_dao
Name Null? Type
COL1 DATE
COL2 NUMBER
OWN_NAME OWN_NAME_NTT
SQL> desc fd_dot
Name Null? Type
COLA VARCHAR2(10)
COLB DATE
OWN_NAME OWN_NAME_NTT
SQL> disconnect
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.3.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.3.0 - Production -
Nested Tables with Object Types
Hi,
Does someone know from which version on object Types can be referenced via database links ?
I could not manage with Oracle 8.1.7 and needed this features as the only way to access
a stored procedure array is via collection and using Object Types.
But Object Types are not possible to access remotlely.
Thanks in advance.
brg robertClick on the link below and see if you can use that method as a way to work around the problem:
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:1252400357305 -
When selecting a row from a view with a nested table I want just ONE entry returned
Does a nested table in a view "EXPLODE" all values ALWAYS no matter the where clause for the nested table?
I want to select ONE row from a view that has columns defined as TYPE which are PL/SQL TABLES OF other tables.
when I specify a WHERE clause for my query it gives me the column "EXPLODED" with the values that mathc my WHERE clause at the end of the select.
I dont want the "EXPLODED" nested table to show just the entry that matches my WHERE clause. Here is some more info:
My select statement:
SQL> select * from si_a31_per_vw v, TABLE(v.current_allergies) a where a.alg_seq
=75;
AAAHQPAAMAAAAfxAAA N00000 771 223774444 20 GREGG
CADILLAC 12-MAY-69 M R3
NON DENOMINATIONAL N STAFF USMC N
U
E06 11-JUN-02 H N
05-JAN-00 Y Y
USS SPAWAR
353535 USS SPAWAR
SI_ADDRESS_TYPE(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NUL
L, NULL)
SI_ADDRESS_TAB()
SI_ALLERGY_TAB(SI_ALLERGY_TYPE(69, 'PENICILLIN', '11-JUN-02', NULL), SI_ALLERGY
TYPE(74, 'SHELLFISH', '12-JUN-02', NULL), SIALLERGY_TYPE(68, 'PEANUTS', '13-J
UN-02', NULL), SI_ALLERGY_TYPE(75, 'STRAWBERRIES', '13-JUN-02', NULL))
SI_ALLERGY_TAB()
75 STRAWBERRIES 13-JUN-02
*******Notice the allergy entry of 75, Strawberries, 13-JUN-02 at the
end. This is what I want not all the other exploded data.
SQL> desc si_a31_per_vw
Name Null? Type
........ Omitted uneeded previous column desc because of metalink
character limit but the view is bigger then this.......
DEPT_NAME VARCHAR2(20)
DIV_NAME VARCHAR2(20)
ADDRESSES SI_ADDRESS_TAB
CURRENT_ALLERGIES SI_ALLERGY_TAB
DELETED_ALLERGIES SI_ALLERGY_TAB
SQL> desc si_allergy_tab
si_allergy_tab TABLE OF SI_ALLERGY_TYPE
Name Null? Type
ALG_SEQ NUMBER
ALG_NAME VARCHAR2(50)
START_DATE DATE
STOP_DATE DATE
SQL> desc si_allergy_type
Name Null? Type
ALG_SEQ NUMBER
ALG_NAME VARCHAR2(50)
START_DATE DATE
STOP_DATE DATECan you explain what do you mean by the following?
"PL/SQL tables (a.k.a. Index-by tables) cannot be used as the basis for columns and/or attributes"There are three kinds of collections:
(NTB) Nested Tables
(VAR) Varrying Arrays
(IBT) Index-by Tables (the collection formerly known as "PL/SQL tables")
NTB (and VAR) can be defined as persistent user defined data types, and can be used in table DDL (columns) and other user defined type specifications (attributes).
SQL> CREATE TYPE my_ntb AS TABLE OF INTEGER;
SQL> CREATE TABLE my_table ( id INTEGER PRIMARY KEY, ints my_ntb );
SQL> CREATE TYPE my_object AS OBJECT ( id INTEGER, ints my_ntb );
/IBT are declared inside stored procedures only and have slightly different syntax from NTB. Only variables in stored procedures can be based on IBT declarations.
CREATE PROCEDURE my_proc IS
TYPE my_ibt IS TABLE OF INTEGER INDEX BY BINARY_INTEGER; -- now you see why they are called Index-by Tables
my_ibt_var my_ibt;
BEGIN
NULL;
END;That sums up the significant differences as it relates to how they are declared and where they can be referenced.
How are they the same?
NTB and VAR can also be (non-persistently) declared in stored procedures like IBTs.
Why would you then ever use IBTs?
IBTs are significantly easier to work with, since you don't have to instantiate or extend them as you do with NTB and VAR, or
Many other highly valuable PL/SQL programs make use of them, so you have to keep your code integrated/consistent.
There's a lot more to be said, but I think this answers the question posed by Sri.
Michael -
Create a view problem on nested tables
I have a table which has a column of nested table:
create table Person (
id NUMBER(10), --primary key
attr1 varchar2(10),
attr2 varchar2(10),
kids KIDS_NT --KIDS_NT is a nested table of object
--which has two columns: name, age.
) nested table store as kids_nt_tab;
Now I like to create a view which has the id (key), concatenation of attr1 and attr2 with a ".", and count of how many kids this persion has):
create view Person_V as (
select id, attr1||'.'||attr2 as attr12,
count(*) from A a, table(a.kids)
group by id)
This won't work since it says attr1.attr2 is not a GROUP BY expression. If I don't specify a group by statement, it will say "not a single group group function).
One solution that I think it will work but quite ugly is to create a view of id and attr1.attr2, andother for id and kids count, then a final view to join them.
Does anyone have a better solution? Thanks in advance!
AliceOne way could be:
SQL> create or replace type kids as object (
2 name varchar2(10),
3 age number) ;
4 /
Type created.
SQL>
SQL> create or replace type kids_nt as table of kids ;
2 /
Type created.
SQL>
SQL> create table Person (
2 id NUMBER(10) primary key,
3 attr1 varchar2(10),
4 attr2 varchar2(10),
5 kids KIDS_NT
6 ) nested table kids store as kids_nt_tab;
Table created.
SQL>
SQL> insert into Person values (1, 'attr1', 'attr2', kids_nt(kids('kid1', 10), kids('kid2', 8))) ;
1 row created.
SQL> insert into Person values (2, 'attr1', 'attr2', kids_nt(kids('kid1', 6), kids('kid2', 13))) ;
1 row created.
SQL>
SQL> select id, attr1||' '||attr2, (select count(*) cnt from table(p.kids)) cnt
2 from Person p
3 /
ID ATTR1||''||ATTR2 CNT
1 attr1 attr2 2
2 attr1 attr2 2
2 rows selected.
SQL> -
Inserting, deleting in nested tables
I am trying to delete and insert to a nested table.
delete from table (select address from employee where
employeeId = 1 );
or
insert into table (select address from employee where
employeeId = 1 )
values ('street', 'city');
I get the error message:
<b>ORA-22906: cannot perform DML on expression or on nested
table view column</b>
Does anybody know what I am doing wrong?
Thank you.You can select from a nested table like this
Create table like this
CREATE TYPE Address AS OBJECT (
street VARCHAR2(20),
city VARCHAR2(10)
We may create a type that is a (nested) table of
objects of this type by:
CREATE TYPE AddressTable AS
TABLE OF Address;
CREATE TABLE Employees (
empno number(5),
addr AddressTable
NESTED TABLE addr STORE AS
address_tab;
SELECT ad.city
FROM THE(
SELECT addr
FROM Employees
WHERE empno = 123
) ad 'You can also add a where clause after this to select a particular address if there are multiple addresses
Insert
Insert into employees values (345,
addresstable ( Address('Street','City')));
Hope this helps -
Nested Tables and Advanced Queues- Please Help.
How do i work with NestedTable type and Advanced Queue.
I have done the following
I have Oracle 8.1.7 enterprise edition.
create type myType as TABLE OF varchar(32);
create type myObject as OBJECT (
id int,
myt myType);
DECLARE
BEGIN
dbms_aqadm.create_queue_table(
queue_table => 'my_queue_table',
multiple_consumers => TRUE,
queue_payload_type => 'myObject',
compatible => '8.1.3'
END;
The Nested Table and Object are created successfully.
but the queue is not created.
I get the following message.
DECLARE
ERROR at line 1:
ORA-22913: must specify table name for nested table column or
attribute
ORA-06512: at "SYS.DBMS_AQADM_SYS", line 2012
ORA-06512: at "SYS.DBMS_AQADM", line 55
ORA-06512: at line 3
I know how to specify the nested table storage clause for
create table statement, but there is no provision for
it in the create_queue_table procedure.
Any help will be greately appriciated.
i have already created and tested aqs with simple data types,
also i have created simple tables with nested table type
elements.
but the combo of Nested tables and AQ is not working.
thanks in advance.Hi Francois. Thank you very much for your reply, but it seems that i still get errors. So let me tell what i have done.
As you suggested me: i have done a block based on a sub-query for the nested-table:
'select courses from department where name= :department.name'.
In the master block(department) i have the when-new-record-instance trigger:
Declare
LC$Req varchar2(256);
Begin
LC$Req := '(select ns.courses from table
( select courses from department where name = ''' || :DEPARTMENT.name || ''' ) ns )';
Go_block('block11');
Clear_Block ;
Set_Block_Property( 'block11', QUERY_DATA_SOURCE_NAME, LC$Req ) ;
Execute_query ;
End ;
Now the errors i receive, this time in the runtime mode are:
- FRM-41380: Cannot set the blocks query data source
-FRM-41003: This function cannot be performed here.
Since it seems that you know how to work with the nested table i would really appreaciate your help. I am new in the nested table and if you could give an ex with my tables it would be great.
Thank you in advance. -
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 -
Elements order in Nested Tables
In PL/SQL when I am adding element to a nested table of objects one by one(in order), and then trying to insert that nested table type to a physical table , the order of element changes. how can I prevent this behavior?
Your example is incomplete and has errors. Oracle does not guarantee the order of anything unless you use an order by clause. So, if you expect the following to produce rows in some order:
Open cur1 for select * from another_table;
then you need to add an order by clause, such as:
Open cur1 for select * from another_table order by id;
The following does minimal correction, completion, and provides sample data to demonstrate:
SCOTT@orcl_11gR2> create or replace TYPE coord AS OBJECT
2 (id number,
3 x number,
4 y number);
5 /
Type created.
SCOTT@orcl_11gR2> create or replace TYPE coord_tab AS TABLE OF coord;
2 /
Type created.
SCOTT@orcl_11gR2> create table demo_table
2 (id number,
3 coords coord_tab)
4 NESTED TABLE coords STORE AS coords_tabb
5 /
Table created.
SCOTT@orcl_11gR2> create table another_table
2 (id number,
3 x number,
4 y number)
5 /
Table created.
SCOTT@orcl_11gR2> insert into another_table values (10, 20, 30)
2 /
1 row created.
SCOTT@orcl_11gR2> insert into another_table values (60, 50, 40)
2 /
1 row created.
SCOTT@orcl_11gR2> DECLARE
2 type cur is ref cursor;
3 cur1 cur;
4 type rec_type is record
5 (id number,
6 x number,
7 y number);
8 record_type rec_type;
9 coords_tab coord_tab := coord_tab();
10 idx number := 1;
11 BEGIN
12 Open cur1 for select * from another_table order by id desc;
13 LOOP
14 fetch cur1 into record_type;
15 exit when cur1%notfound;
16 coords_tab.extend() ;
17 coords_tab(idx) := coord(record_type.id, record_type.x , record_type.y);
18 idx := idx + 1;
19 End LOOP;
20 -- EXECUTE IMMEDIATE 'insert into demo_table values (1,:1)' USING coords_tab ;
21 insert into demo_table values (1,coords_tab);
22 End;
23 /
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> select * from demo_table
2 /
ID
COORDS(ID, X, Y)
1
COORD_TAB(COORD(60, 50, 40), COORD(10, 20, 30))
1 row selected.
SCOTT@orcl_11gR2> -
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.
Maybe you are looking for
-
How to sync an older Ipod Mini to a 2010 version of itunes?
I recently found my old Ipod Mini (2nd generation). It still works, but I am not able to connect or synch it with my newer version of itunes. What can I do to clear out what is on there and put in my music from my 2010 itunes?! I have an Ipod Classic
-
My app world log o won't work how do I reset
updated appworld lost it downloaded nothing and my sign in keeps saying wrong how do I reset
-
I am trying to sync my iPad from iOS 5.1 however a message is displayed "This iPad could not be updated. This device isnt eligible for the requested build". How do I fix this?????
-
Hello, I have been struggling with this request for a while. We just upgraded from 46B to ECC60. for report CN41, the user want to setup a default display variant so every time they logon, they don't need to manually pick a display variant. In the 46
-
PDF converted to a messy Word Doc, why is it so
I just purchased PDF converter and tried to convert pdf to a Word doc and half of the document was jumbled up, I restarted my computer and did it again and the same thing happened. Does anyone know why this is happening, there is no point having the