Newbie: Nested table type problem
<< accidently posted the quiery twice >>
Message was edited by:
user575882
Ooooops....sorry that i posted this thread twice....
I actually gave me an error...
Now how to delete it???
Similar Messages
-
How to use nested table types with XDK
Im using Oracles XDK (xml development kit) to create xml-documents from data in database.4
Problem: I need to use nested tables but when trying to create nested table types I get error: A Table type may not contain a nested table type or VARRAY.
Hope I make myself clear! Are there any solutions or workarounds to this problem?
Help appreciated, thanks!Jesper,
I asked similar question last year (search for Tapsell, you will see my posting). Under 8.1.7 the "nesting" seems restricted to one level down. Thus you cannot create a type using another object that itself includes a nested table. Under Oracle 9, against which most current examples seem based, this limitation is removed making things easier. Under 8.1.7 the workaround I have used is to use the CAST syntax. This is not as neat, but it works. -
Java call stored procedure with nested table type parameter?
Hi experts!
I need to call stored procedure that contains nested table type parameter, but I don't know how to handle it.
The following is my pl/sql code:
create or replace package test_package as
type row_abc is record(
col1 varchar2(16),
col2 varchar2(16),
col3 varchar2(16 )
type matrix_abc is table of row_abc index by binary_integer;
PROCEDURE test_matrix(p_arg1 IN VARCHAR2,
p_arg2 IN VARCHAR2,
p_arg3 IN VARCHAR2,
p_out OUT matrix_abc
END test_package;
create or replace package body test_package as
PROCEDURE test_matrix(p_arg1 IN VARCHAR2,
p_arg2 IN VARCHAR2,
p_arg3 IN VARCHAR2,
p_out OUT matrix_abc
IS
v_sn NUMBER(8):=0 ;
BEGIN
LOOP
EXIT WHEN v_sn>5 ;
v_sn := v_sn + 1;
p_out(v_sn).col1 := 'col1_'||to_char(v_sn)|| p_arg1 ;
p_out(v_sn).col2 := 'col2_'||to_char(v_sn)||p_arg2 ;
p_out(v_sn).col3 := 'col3_'||to_char(v_sn)||p_arg3 ;
END LOOP ;
END ;
END test_package ;
My java code is following, it doesn't work:
Class.forName ("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection
("jdbc:oracle:thin:@10.16.102.176:1540:dev", "scott", "tiger");
con.setAutoCommit(false);
CallableStatement ps = null;
String sql = " begin test_package.test_matrix( ?, ? , ? , ? ); end ; ";
ps = con.prepareCall(sql);
ps.setString(1,"p1");
ps.setString(2,"p2");
ps.setString(3,"p3");
ps.registerOutParameter(4,OracleTypes.CURSOR);
ps.execute();
ResultSet rset = (ResultSet) ps.getObject(1);
error message :
PLS-00306: wrong number or types of arguments in call to 'TEST_MATRIX'
ORA-06550: line 1, column 8:
PL/SQL: Statement ignored
Regards
LouisLouis,
If I'm not mistaken, record types are not allowed. However, you can use object types instead. However, they must be database types. In other words, something like:
create or replace type ROW_ABC as object (
col1 varchar2(16),
col2 varchar2(16),
col3 varchar2(16 )
create or replace type MATRIX_ABC as table of ROW_ABC
/Then you can use the "ARRAY" and "STRUCT" (SQL) types in your java code. If I remember correctly, I recently answered a similar question either in this forum, or at JavaRanch -- but I'm too lazy to look for it now. Do a search for the terms "ARRAY" and "STRUCT".
For your information, there are also code samples of how to do this on the OTN Web site.
Good Luck,
Avi. -
Public Synonyms for Nested Tables - Insertion Problem
Hi,
we are facing a problem during implementation. Our DB set up
is , we will be having two schema named OWNR and COPY.
In the schema, OWNR we have to create all the tables,
types,procedures, packages and obj.....This schema will have
both DDL and DML privileges.
In the schema, COPY we are not supposed to create any tables,
objects. We have to create public synonyms for all the tables,
types, procedures... in OWNR and grant ALL privilege to the
schema COPY.The schema, COPY will have only DML privileges.
The problem is we have some nested tables in our application.
When I try to insert into the synonym which is created for the
nested table, it is not allowing me to insert..The whole
implementation is stucked..Please help.The scripts are given
below.......
We have a type name SITA_ADDRESS_TY which is used by the nested
table SITA_ADDRESSES_NT.Script used for creating the Type,Nested
table,Table, Public Synonym and granting all privilege to these
types and tables are
CREATE OR REPLACE TYPE SITA_ADDRESS_TY AS OBJECT (
SITA_ADDRESS VARCHAR2(10),
REMARKS VARCHAR2(100)) ;
PROMPT SITA_ADDRESSS_NT...
CREATE OR REPLACE TYPE SITA_ADDRESSES_NT AS TABLE OF
SITA_ADDRESS_TY ;
Using this nested table we have created the table,
UMS_SITA_ADDRESS
CREATE TABLE UMS_SITA_ADDRESS (
COMPANY_CODE VARCHAR2 (6) NOT NULL,
AIRLINE_CODE VARCHAR2 (6) NOT NULL,
DESTINATION VARCHAR2 (6) NOT NULL,
SITA_ADDRESS SITA_ADDRESSES_NT)
TABLESPACE EKUMDAT
PCTFREE 5
PCTUSED 40
INITRANS 1
MAXTRANS 255
STORAGE (
INITIAL 64K
NEXT 64K
PCTINCREASE 0
MINEXTENTS 1
MAXEXTENTS 505
FREELISTS 1 FREELIST GROUPS 1 )
NOCACHE
NESTED TABLE SITA_ADDRESS STORE AS UMSNT_SITA_ADDRESS ;
PROMPT SYNONYM SITA_ADDRESS_TY...
CREATE PUBLIC SYNONYM SITA_ADDRESS_TY FOR SITA_ADDRESS_TY
PROMPT SYNONYM SITA_ADDRESSES_NT...
CREATE PUBLIC SYNONYM SITA_ADDRESSES_NT FOR SITA_ADDRESSES_NT
PROMPT UMS_SITA_ADDRESS...
CREATE PUBLIC SYNONYM UMS_SITA_ADDRESS FOR UMS_SITA_ADDRESS
Granting Privileges
PROMPT SITA_ADDRESS_TY...
GRANT EXECUTE ON SITA_ADDRESS_TY TO COPY
PROMPT SITA_ADDRESSS_NT...
GRANT EXECUTE ON SITA_ADDRESSES_NT TO COPY
PROMPT UMS_SITA_ADDRESS...
GRANT ALL ON UMS_SITA_ADDRESS TO COPY
When I connect to copy and desc UMS_SITA_ADDRESS, the structure
is
SQL> desc ums_sita_address
Name Null? Type
COMPANY_CODE NOT NULL VARCHAR2(6)
AIRLINE_CODE NOT NULL VARCHAR2(6)
DESTINATION NOT NULL VARCHAR2(6)
SITA_ADDRESS
OWNR.SITA_ADDRESSES_NT
Why is it so??. Even though I have a synonym for
SITA_ADDRESSES_NT, it is not referencing the synonym but instead
refer the OWNR.SITA_ADDRESSES_NT
Because of this when I try to insert into ums_sita_address(in
schema COPY), it is giving the following error,
SQL> insert into ums_sita_address values
('EK','EK','DXB',SITA_ADDRESSES_NT());
insert into ums_sita_address values
('EK','EK','DXB',SITA_ADDRESSES_NT())
ERROR at line 1:
ORA-00932: inconsistent datatypes
But when the same connect to OWNR and try to insert with the
same stmt, it is inserting...
Our middle tier can connect only to COPY schema alone..Is there
anything to be done in the DBA side to achieve this??.
Please help from your valuabe experience...Or can you ask your
collegues if they have got a soln to this probs..Our
implementation team is stucked with this...
Thanks
PriyaHi
I am not sure but maybe you need to use this command:
SQL> insert into ums_sita_address values
('EK','EK','DXB',SITA_ADDRESSES_TY());
SITA_ADDRESSES_TY() instead SITA_ADDRESSES_NT
Regards -
Public Synonyms for Nested Tables - Insertion Problem - Please Help!!!!!
Hi,
we are facing a problem during implementation. Our DB set up
is , we will be having two schema named OWNR and COPY.
In the schema, OWNR we have to create all the tables,
types,procedures, packages and obj.....This schema will have
both DDL and DML privileges.
In the schema, COPY we are not supposed to create any tables,
objects. We have to create public synonyms for all the tables,
types, procedures... in OWNR and grant ALL privilege to the
schema COPY.The schema, COPY will have only DML privileges.
The problem is we have some nested tables in our application.
When I try to insert into the synonym which is created for the
nested table, it is not allowing me to insert..The whole
implementation is stucked..Please help.The scripts are given
below.......
We have a type name SITA_ADDRESS_TY which is used by the nested
table SITA_ADDRESSES_NT.Script used for creating the Type,Nested
table,Table, Public Synonym and granting all privilege to these
types and tables are
CREATE OR REPLACE TYPE SITA_ADDRESS_TY AS OBJECT (
SITA_ADDRESS VARCHAR2(10),
REMARKS VARCHAR2(100)) ;
PROMPT SITA_ADDRESSS_NT...
CREATE OR REPLACE TYPE SITA_ADDRESSES_NT AS TABLE OF
SITA_ADDRESS_TY ;
Using this nested table we have created the table,
UMS_SITA_ADDRESS
CREATE TABLE UMS_SITA_ADDRESS (
COMPANY_CODE VARCHAR2 (6) NOT NULL,
AIRLINE_CODE VARCHAR2 (6) NOT NULL,
DESTINATION VARCHAR2 (6) NOT NULL,
SITA_ADDRESS SITA_ADDRESSES_NT)
TABLESPACE EKUMDAT
PCTFREE 5
PCTUSED 40
INITRANS 1
MAXTRANS 255
STORAGE (
INITIAL 64K
NEXT 64K
PCTINCREASE 0
MINEXTENTS 1
MAXEXTENTS 505
FREELISTS 1 FREELIST GROUPS 1 )
NOCACHE
NESTED TABLE SITA_ADDRESS STORE AS UMSNT_SITA_ADDRESS ;
PROMPT SYNONYM SITA_ADDRESS_TY...
CREATE PUBLIC SYNONYM SITA_ADDRESS_TY FOR SITA_ADDRESS_TY
PROMPT SYNONYM SITA_ADDRESSES_NT...
CREATE PUBLIC SYNONYM SITA_ADDRESSES_NT FOR SITA_ADDRESSES_NT
PROMPT UMS_SITA_ADDRESS...
CREATE PUBLIC SYNONYM UMS_SITA_ADDRESS FOR UMS_SITA_ADDRESS
Granting Privileges
PROMPT SITA_ADDRESS_TY...
GRANT EXECUTE ON SITA_ADDRESS_TY TO COPY
PROMPT SITA_ADDRESSS_NT...
GRANT EXECUTE ON SITA_ADDRESSES_NT TO COPY
PROMPT UMS_SITA_ADDRESS...
GRANT ALL ON UMS_SITA_ADDRESS TO COPY
When I connect to copy and desc UMS_SITA_ADDRESS, the structure
is
SQL> desc ums_sita_address
Name Null? Type
COMPANY_CODE NOT NULL VARCHAR2(6)
AIRLINE_CODE NOT NULL VARCHAR2(6)
DESTINATION NOT NULL VARCHAR2(6)
SITA_ADDRESS
OWNR.SITA_ADDRESSES_NT
Why is it so??. Even though I have a synonym for
SITA_ADDRESSES_NT, it is not referencing the synonym but instead
refer the OWNR.SITA_ADDRESSES_NT
Because of this when I try to insert into ums_sita_address(in
schema COPY), it is giving the following error,
SQL> insert into ums_sita_address values
('EK','EK','DXB',SITA_ADDRESSES_NT());
insert into ums_sita_address values
('EK','EK','DXB',SITA_ADDRESSES_NT())
ERROR at line 1:
ORA-00932: inconsistent datatypes
But when the same connect to OWNR and try to insert with the
same stmt, it is inserting...
Our middle tier can connect only to COPY schema alone..Is there
anything to be done in the DBA side to achieve this??.
Please help from your valuabe experience...Or can you ask your
collegues if they have got a soln to this probs..We are stucked
with this...
Thanks
PriyaHi
I am not sure but maybe you need to use this command:
SQL> insert into ums_sita_address values
('EK','EK','DXB',SITA_ADDRESSES_TY());
SITA_ADDRESSES_TY() instead SITA_ADDRESSES_NT
Regards -
Select from nested table in a nested table security problem
please help
running Oracle 9.2.0.3.0 on RH AS 2.1
I can select the inner most nested table as the creator, but can't use the same select statement as USER2.
ORA-00942: table or view does not exist
-- begin make of objects and tables
create or replace type mydata_t as object ( x float, y float);
create or replace type mydata_tab_t as table of mydata_t;
create or replace type mid_t as object (
graphname varchar2(12),
datapoints mydata_tab_t );
create or replace type mid_tab_t as table of mid_t;
create or replace type top_t as object (
someinfo int,
more_mid mid_tab_t );
create table xyz (
xyzPK int,
mainstuff top_t )
nested table mainstuff.more_mid store as mid_nt_tab
(nested table datapoints store as mydata_nt_tab)
-- grants
grant all on mydata_t to user2;
grant all on mydata_tab_t to user2;
grant all on mid_t to user2;
grant all on mid_tab_t to user2;
grant all on top_t to user2;
grant all on xyz to user2;
-- insert
insert into xyz values (1, top_t(22,mid_tab_t(mid_t('line1',mydata_tab_t(
mydata_t(0,0),
mydata_t(15,15),
mydata_t(30,30))))));
commit;
-- select fails as user2
select * from table(select Y.datapoints as DP_TAB
from table(select X.mainstuff.more_mid as MORE_TAB
from scott.xyz X
where X.xyzPK=1) Y
where Y.graphname='line1') Z;
-- select works as user2, but i need individual lines
select Y.datapoints as DP_TAB
from table(select X.mainstuff.more_mid as MORE_TAB
from scott.xyz X
where X.xyzPK=1) Y
where Y.graphname='line1';Thank you for your reply.
I have tried
select value(t) from table t;
but it is still not working. I got almost the same answer as before.
Anyway thank you very much again.
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by MARCELO OCHOA ([email protected]):
Originally posted by meimei wu ([email protected]):
[b]I created a nested object-relational table using REF type in oracle8i. when I tried to select * from the table, I got lots of number as the ref type values, but actually, the value in ref type should be of type varchar2 and number. The number I got looked like following code:
JARTICLE_REF_TYPE(000022020876108427C2FE0D00E0340800208FD71F76103B99B12009C0E0340800208FD71F,
Does anyone know how I can get the actual value that I inserted into the nested table?
your help is appreciated.<HR></BLOCKQUOTE>
Try this:
select value(t) from table t;
Best regards, Marcelo.
null -
Nested table type in object view on 8.1.7
Object views seem to be the ideal way to deliver XML datagrams from database queries with nested data.
I need to create a datagram that contains nested data within another nested set of data eg. a family has many people, each person may have many hobbies.
The following code taken from Oracle documentation would create the Types I need, but this does not work on 8.1.7 (gets PLS-00534 error). Can someone advise if nested tables within a table type is a new Oracle 9 feature?
CREATE TYPE project_t AS OBJECT
( projname VARHCAR2(20)
, mgr VARHCAR2(20));
CREATE TYPE nt_project_t AS TABLE OF project_t;
CREATE TYPE emp_t AS OBJECT
( ename VARCHAR2(20)
, salary NUMBER
, deptname VARHCAR2(20)
, projects nt_project_t);
CREATE TYPE nt_emp_t AS TABLE OF emp_t;
CREATE TYPE dept_t AS OBJECT
( deptno NUMBER
, deptname VARHCAR2(20)
, emps nt_emp_t);
Thks, Matt. (asked same question in XML forum but maybe more appropriate here).
nullMatthew,
Value-based multi-level collections, such as the one you have here, were not supported in 8.1.7. You have two choices:
1. Upgrade to 9i to take advantage of value-based multi-level collections (see http://download-west.oracle.com/otndoc/oracle9i/901_doc/appdev.901/a88878/adobjbas.htm#462243), type inheritance, type evolution and other new features.
2. Use REFs in 8.1.7 to build a reference-based multi-level collections (see http://otn.oracle.com/docs/products/oracle8i/doc_library/817_doc/appdev.817/a76976/adobjdes.htm#446229).
Regards,
Geoff -
MetaData for nested table type
in a nested table a column is of datatype "TYPE"
so how can i get metadata for this column..
if "OPTIONS" is a column of datatype "TYPE"
and it has 2 columns option_id and option_value
then when i'am trying to get
array.getBaseTypeName
m gettin TAB_TY_OPTION_DETAILS
like this only..
how can i get metadata for this datatype.
Thanks in advance.check out ResultSetMetaData
-
Building an object of nested table types
Hi,
Looking for suggestions for the following.
I have a procedure with 4 table types.
They are in a hierarchical order so that 4 is the child of 3, 3 is the child of 2 and 2 is the child of 1.
One of the columns of table 1 is a table type holding all the child records from table 2,
One of the columns of table 2 is a table type holding all the child records from table 3,
One of the columns of table 3 is a table type holding all the child records from table 4,
I have 4 cursors that pull out all of the data to populate each of my 4 table types.
I am trying to figure out how to nest my fetches to populate all of my table types to create a single object that hold all of my data.
It’s a table of a table of a table of a table.
Column 3 of table 1 holds table 2
Column 3 of table 2 holds table 3
Column 3 of table 3 holds table 4
I’ve tried creating my procedure like this (pseudo code)
declare
tab_1 tab_1_type;
tab_2 tab_2_type;
tab_3 tab_3_type;
tab_4 tab_4_type;
cursor get_tab_1 is
select col1, col2, tab_2 – added the table type for the child records
from data_table_1
cursor get_tab_2(tab_1_pk in number) is
select col1, col2, tab_3 – added the table type for the child records
from data_table_2
where tab_2_fk = tab_1_pk
cursor get_tab_3(tab_2_pk in number) is
select col1, col2, tab_4 – added the table type for the child records
from data_table_3
where tab_3_fk = tab_2_pk
cursor get_tab_4(tab_3_pk in number) is
select col1, col2, col3
from data_table_4
where tab_4_fk = tab_3_pk
begin
open get_tab_1;
loop
open get_tab_2
loop
open get_tab_3
loop
open get_tab_4(tab_3_pk);
bulk collect get_tab_4 into tab_4;
close get_tab_4;
fetch get_tab_3 into tab_3;
tab_4:= null;
exit when get_tab_3 %notfound;
end loop;
close get_tab_3;
fetch get_tab_2 into tab_2;
tab_3:= null;
exit when get_tab_2 %notfound;
end loop;
close get_tab_2;
fetch get_tab_1 into tab_1;
tab_3:= null;
exit when get_tab_1 %notfound;
end loop;
close get_tab_1;
l_return := tab_1;
end;
The above won’t work because once the cursor is opened the child tables will be assigned values of null before they have had a chance to populate from the nested fetches.
It’s almost as if I need to execute the fetch and update the extra columns afterwards somehow, something like:
fetch get_tab_3 into tab_3;
tab_3.col3 := tab_4;
tab_4 := null;
end loop;
close get_tab_3;
can I do that?
Also the above seems very cumbersome. If there is a more elegant way of building up this object I’d like to hear it.
Cheers
YogInteresting little exercise getting a 3 deep nested structure using a single SQL. Below is my attempt. You should be able to run it in any schema that has CREATE TYPE privs.
SQL> -- Nested structure design:
SQL> --
SQL> -- USER LIST = (
SQL> -- (USER1,OBJECT_LIST1).., (USERn,OBJECT_LISTn)
SQL> -- )
SQL> --
SQL> -- LIST OF OBJECTS = (
SQL> -- (TYPE1, NAME_LIST1).., (TYPEn, NAME_LISTn)
SQL> -- )
SQL> --
SQL> -- LIST OF NAMES = ( NAME1..,NAMEn )
SQL>
SQL>
SQL> create or replace type TObjectList is table of varchar2(50)
2 /
Type created.
SQL>
SQL> create or replace type TObjType is object(
2 obj_type varchar2(50),
3 obj_list TObjectList
4 );
5 /
Type created.
SQL>
SQL> create or replace type TObjTypeList is table of TObjType;
2 /
Type created.
SQL>
SQL> create or replace type TUser is object(
2 user_name varchar2(50),
3 objects TObjTypeList
4 );
5 /
Type created.
SQL>
SQL> create or replace type TUserList is table of TUser;
2 /
Type created.
SQL>
SQL> col NESTED_STRUCTURE format a100
SQL>
SQL> -- constructing the above user list (have made the start of the USER bold in the output below)
SQL> select
2 CAST( COLLECT(
3 TUser(
4 username,
5 CAST( MULTISET(
6 select
7 TObjType(
8 object_type,
9 CAST( COLLECT(o.object_name) as TObjectList)
10 )
11 from all_objects o
12 where o.owner = u.username
13 group by
14 o.object_type
15 ) as TObjTypeList
16 )
17 )
18 ) as TUserList
19 ) as NESTED_STRUCTURE
20 from all_users u
21 where u.username in ('BILLY','DBSNMP')
22 /
NESTED_STRUCTURE(USER_NAME, OBJECTS(OBJ_TYPE, OBJ_LIST))
TUSERLIST(TUSER('BILLY', TOBJTYPELIST(TOBJTYPE('FUNCTION', TOBJECTLIST('GETEMP', 'GETEMP2', 'TESTRET
URN', 'WTF', 'ANOOP_REF')), TOBJTYPE('INDEX', TOBJECTLIST('PK_DEPT', 'PK_EMP')), TOBJTYPE('PROCEDURE
', TOBJECTLIST('USESEQ1', 'FOOPROC', 'W')), TOBJTYPE('TABLE', TOBJECTLIST('X', 'LOAD_TABLE', 'DEPT',
'EMP', 'BONUS', 'SALGRADE')), TOBJTYPE('TYPE', TOBJECTLIST('TEMP', 'TEMPLOYEE', 'TX', 'TARRAY2D', '
TARRAY1D', 'TARRAY3D', 'TOBJECT', 'TOBJTYPE', 'TOBJECTLIST', 'TOBJTYPELIST', 'TUSER', 'TUSERLIST', '
SYSTPTkQoC5hBR+DgQPsKOl0PFQ==', 'SYSTPTkQoC5hyR+DgQPsKOl0PFQ==', 'SYSTPTkQoC5qzR+DgQPsKOl0PFQ==', 'S
YSTPTkQoC5raR+DgQPsKOl0PFQ==')))), TUSER('DBSNMP', TOBJTYPELIST(TOBJTYPE('INDEX', TOBJECTLIST('MGMT_
DB_FILE_GTT_PK', 'MGMT_DB_SIZE_GTT_PK')), TOBJTYPE('PACKAGE', TOBJECTLIST('MGMT_RESPONSE')), TOBJTYP
E('PACKAGE BODY', TOBJECTLIST('MGMT_RESPONSE')), TOBJTYPE('SEQUENCE', TOBJECTLIST('MGMT_RESPONSE_CAP
TURE_ID', 'MGMT_RESPONSE_SNAPSHOT_ID')), TOBJTYPE('TABLE', TOBJECTLIST('MGMT_SNAPSHOT', 'MGMT_SNAPSH
OT_SQL', 'MGMT_BASELINE', 'MGMT_BASELINE_SQL', 'MGMT_CAPTURE', 'MGMT_CAPTURE_SQL', 'MGMT_RESPONSE_CO
NFIG', 'MGMT_LATEST', 'MGMT_LATEST_SQL', 'MGMT_HISTORY', 'MGMT_HISTORY_SQL', 'MGMT_TEMPT_SQL', 'MGMT
DBFILE_GTT', 'MGMT_DB_SIZE_GTT')), TOBJTYPE('VIEW', TOBJECTLIST('MGMT_RESPONSE_BASELINE')))))
SQL>
PS. To understand how the SQL works, run it from the inside out - i.e. run the innermost select on its own to see the output and then add to it until the full select is reached. -
Tough question : table type problem
CREATE OR REPLACE TYPE myObj is OBJECT(
id number
create or replace type myTbl is TABLE OF myObj ;
list myTbl ;
list := myTbl(); --I don't understand
list.extend; --I don't understand
list(list.last) := myTbl(22); --I don't understand>>list := myTbl(); I don't understand <br /><br /><br /><br />For each type Oracle provides a default CONSTRUCTOR to initialize it.<br /><br /><br /><br />>>list.extend; I don't understand
EXTEND function extend the number of elements by 1.
>>list(list.last) := myTbl(22); --I don't understand<br /><br />Will give you the last element.<br /><br /><br /><br />How about reading the manual first.<br /><br /><br /><br />http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/collections.htm#LNPLS005<br /><br />http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/collection_method.htm#i33024<br /><br /><br /><br />Regards,<br /><br /><br /><br /><br /><br /> -
How to assign values into nested table type in plsql
hi all,
I feel some what difficult to return user defined types from plsql function and procedures .
Can any one help me to learn this .
Version details are as follow
BANNER
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
SQL>
create or replace type emp_names_nt is table of varchar2(100);
/* Formatted on 2012/04/05 15:23 (Formatter Plus v4.8.8) */
CREATE OR REPLACE FUNCTION get_emp_names
RETURN emp_names_nt
IS
CURSOR ec
IS
SELECT ename
FROM emp;
v_emp_names emp_names_nt := emp_names_nt ();
BEGIN
FOR i IN ec
LOOP
v_emp_names.EXTEND ();
v_emp_names (i) := i.ename;
END LOOP;
RETURN v_emp_names;
END;
Error :
PL/SQL: Statement ignored
PLS-00382: expression is of wrong typeThanks in advance .............
Thanks,
P PrakashCREATE OR REPLACE FUNCTION get_emp_names
RETURN emp_names_nt
IS
CURSOR ec
IS
SELECT ename
FROM scott.emp;
v_emp_names emp_names_nt := emp_names_nt();
cnt number:=1;
BEGIN
FOR i IN ec
LOOP
v_emp_names.EXTEND;
v_emp_names(cnt) := i.ename;
cnt:=cnt+1;
END LOOP;
RETURN v_emp_names;
END;
show errors -
How to call nested table type from Java
I needed a 2 dimensional array and asked the questuion here.
[Original thread| http://forums.oracle.com/forums/message.jspa?messageID=3419944#3419944]
I have my program working correctly in pl/sql.
The java guys are building this array and passing it in to me, but they don't know how.
A small example of this would be appreciated.
Heres an example of the procedure prototype and the type definitions in use
create or replace
type csn_array_obj
as object
(csn varchar2(20 char),
box_id varchar2(10)
create or replace
type csn_array_type is table of csn_array_obj;
procedure populate_stock(
p_csn_array in csn_array_type
added in example of object and type definition.There's an orl Oramag article by Tom Kyte rounding up [some Java tips|http://asktom.oracle.com/tkyte/omag/00-nov/o60tom.html] which includes an example of how to do this. You'll need to replace Tom's SIMPLARRAY with your own type.
Cheers, APC
blog: http://radiofreetooting.blogspot.com -
Fill datagridview with Nested Table Object Type ???
Hello everybody, please you help me resolve my problem?
I follow this example: *(A Sample Application using Object-Relational features)* http://download-west.oracle.com/docs/cd/B14117_01/appdev.101/b10799/adobjxmp.htm
And this tutorial: *(Using Oracle User-Defined Types with .NET and Visual Studio)* http://www.oracle.com/technology/obe/hol08/dotnet/udt/udt_otn.htm
Now I have 3 Object Table: Stock, Customer and Purchase Order. With the tutorial it's OK to show the data of Stock and Customer Table [there is no nested table in], but I can't do this with table Purchase Order, the tutorial don't show how to work with Nested Table type [Missing or something ?]
When I try to display the data of table Purchase Order, I get the error:
typeName='LINEITEMLIST_NTABTYP'' is not specified or is invalid*
Follow the tutorial, I generate custom class for this UDT and get another error:
this.STOCK_REF = ((object)(Oracle.DataAccess.Types.OracleUdt.GetValue(con, pUdt, "STOCK_REF")));*
Argument Exception Unhandle: Object attribute is not mapped to a custom type member.*
Can You show me how to do this ? Show the data of the Nested Table in Visual Studio, do I have something wrong ??? Thanks and Best Regards.I think you need to go through the tutorial more carefully. I think you are missing steps.
You are using a REF. Are you creating an object table for the objects to be stored in? Are you dereferencing the REF? This is covered by the Oracle by Example tutorial.
http://www.oracle.com/technology/obe/hol08/dotnet/udt/udt_otn.htm#t11
When you receive the nested table, it will be inside a .NET class. You can create this class by using the Create Custom Class menu item on the nested table type in server explorer.
This class will contain a ToString method and a ToXML method.
The question is, where are you attempting to display the data from this nested table? In a grid?
Does it make sense to display a nested table inside one cell of a grid? No. You would need to construct a special UI that will show the
nested table. Maybe the user clicks on the cell on the grid, which opens a new grid that displays the data. Or maybe there is a second grid on the form that always shows the nested table for the row that the first grid currently has selected.
I realize I am not providing you the code... but it sounds like you need to design a more sohisticated UI than what the tutorial is using -- one that can handle displaying one additional table per row. -
Problem in truncate/drop partitions in a table having nested table columns.
Hi,
I have a table that has 2 columns of type nested table. Now in the purge process, when I try to truncate or drop a partition from this table, I get error that I can't do this (because table has nested tables). Can anybody help me telling how I will be able to truncate/drop partition from this table? IF I change column types from nested table to varray type, will it help?
Also, is there any short method of moving existing data from a nested table column to a varray column (having same fields as nested table)?
Thanks in advance.>
I have a table that has 2 columns of type nested table. Now in the purge process, when I try to truncate or drop a partition from this table, I get error that I can't do this (because table has nested tables). Can anybody help me telling how I will be able to truncate/drop partition from this table?
>
Unfortunately you can't do those operations when a table has a nested table column. No truncate, no drop, no exchange partition at the partition level.
A nested table column is stored as a separate table and acts like a 'child' table with foreign keys to the 'parent' table. It is these 'foreign keys' that prevent the truncation (just like normal foreign keys prevent truncating partions and must be disabled first) but there is no mechanism to 'disable' them.
Just one excellent example (there are many others) of why you should NOT use object columns at all.
>
IF I change column types from nested table to varray type, will it help?
>
Yes but I STRONGLY suggest you take this opportunity to change your data model to a standard relational one and put the 'child' (nested table) data into its own table with a foreign key to the parent. You can create a view on the two tables that can make data appear as if you have a nested table type if you want.
Assuming that you are going to ignore the above advice just create a new VARRAY type and a table with that type as a column. Remember VARRAYs are defined with a maximum size. So the number of nested table records needs to be within the capacity of the VARRAY type for the data to fit.
>
Also, is there any short method of moving existing data from a nested table column to a varray column (having same fields as nested table)?
>
Sure - just CAST the nested table to the VARRAY type. Here is code for a VARRAY type and a new table that shows how to do it.
-- new array type
CREATE OR REPLACE TYPE ARRAY_T AS VARRAY(10) OF VARCHAR2(64)
-- new table using new array type - NOTE there is no nested table storage clause - arrays stored inline
CREATE TABLE partitioned_table_array
( ID_ INT,
arra_col ARRAY_T )
PARTITION BY RANGE (ID_)
( PARTITION p1 VALUES LESS THAN (40)
, PARTITION p2 VALUES LESS THAN(80)
, PARTITION p3 VALUES LESS THAN(100)
-- insert the data from the original table converting the nested table data to the varray type
INSERT INTO PARTITIONED_TABLE_ARRAY
SELECT ID_, CAST(NESTED_COL AS ARRAY_T) FROM PARTITIONED_TABLENaturally since there is no more nested table storage you can truncate or drop partitions in the above table
alter table partitioned_table_array truncate partition p1
alter table partitioned_table_array drop partition p1 -
UserDefined Type Question - Nested Table Attribute
I have a question about some types I'm trying to create and whether or not it's even possible .....
Here's the background ...
I have the following type i created :
create type asset_stat (
stat_current varchar2(50),
stat_change_date date,
stat_change_user varchar2(30)
All this type does is simply put a user and date/time stamp when constructed. I want to track status changes for historical tracking.
Then I want to create a nested table type of the above type as follows:
create type asset_stat_nt as table of asset_stat
Then, I have another type i've created which will have the nested table type created above as an attribute.
create type asset (
asset_name varchar2(30),
asset_type varchar2(3),
asset_stat asset_stat_nt
Now, the constructor for this asset type is defined like this: ( this is where i get lost)
constructor function asset (
asset_nm IN varchar2,
asset_type_cd in varchar2,
asset_stat_cd in varchar2 ) return self as result is
begin
self.asset_nm := asset_nm
self.asset_type := asset_type_cd ;
self.asset_stat := asset_stat_nt(asset_stat_cd);
return;
end;
I just created a table of asset type and tried to do an insert and I'm getting an error related to the line where the nested type is being assigned. Is this possible? If so is my syntax completely off? I'm not quite sure how to set values for the nested type because i want to keep all records of change. Any help would be greatly appreciated.
thanksthe block of code shows that asset_stat_nt is the type assigned to asset_stat inside the type asset as shown below
create type asset (
asset_name varchar2(30),
asset_type varchar2(3),
asset_stat asset_stat_nt
I guess for the following block of code, the line with the arrows should be given like shown below in bold letters
constructor function asset (
asset_nm IN varchar2,
asset_type_cd in varchar2,
asset_stat_cd in varchar2 ) return self as result is
begin
self.asset_nm := asset_nm
self.asset_type := asset_type_cd ;
self.asset_stat := asset_stat_nt(asset_stat_cd);return;
end;
[b][b]self.asset_stat := asset(asset_stat_nt(asset_stat_cd));
I am not pretty sure.......try it anyway.....if it works....good to you
Maybe you are looking for
-
My IPOD TOUCH is frozen with the Apple logo sitting there on the screen. I have already reset the ipod because it was freezing up so I reset it, but now it won't shut off or got o main screen it just sits with the logo on it. I can't turn it off.
-
G4 +23" CD Not keeping resolution after reboot
Heya folks I have a powerbook g4 and a cinema display 23". I have been using the 2 of them together without problems, but I recently installed some of the apple service updates and after doing so I am having problems with with the external monitor. I
-
Why can I not open email from comcast?
Suddenly I have lost the capacity to open email on my Comcast account. I can view that I have mail but they will not open.
-
Can't open Procedures, Functions from JDeveloper 11g on 9i DB
Hi, Today using JDeveloper I tried to connect to a 9i database to edit some procedures and packages but I didn't see it. I saw some errors in the message log Once the connection opens is shows Mar 8, 2010 11:49:55 AM oracle.dbtools.db.DBUtil SEVERE:
-
Can't start the Import Export Wizard - "No Description Found"
Microsoft SQL Server Management Studio 9.00.3042.00 Microsoft Analysis Services Client Tools 2005.090.3042.00 Microsoft Data Access Components (MDAC) 2000.085.1117.00 (x