Problems passing a nested table or Varray as a parameter
Hi,
could some one please show me the code for passing a varray or a table as a parameter in a PL/SQL function or procedure.
I have tried a number of ways but am not getting anywhere fast. A small bit of sample code that shows a function that takes a table/varray as a parameter and uses it to do something, and code also for the method that calls this function which demonstrates how the table/varray is created and passed.
I have a good idea how I think this should be done but cant get it to work in practice.
Thanks and happy new year!
sql >> CREATE OR REPLACE TYPE t_listachar
2 AS TABLE OF VARCHAR2(100)
3 /
Type created.
sql >> CREATE OR REPLACE PROCEDURE prcl_nested
2 (
3 p_Array IN t_ListaChar
4 )
5 IS
6 BEGIN
7 --
8 FOR i IN p_Array.FIRST .. p_Array.LAST LOOP
9 --
10 dbms_output.put_line('p_Array('||i||'): '||p_Array(i)) ;
11 --
12 END LOOP ;
13 --
14 END ;
15 /
Procedure created.
sql >> DECLARE
2 --
3 t_Array t_ListaChar := t_ListaChar('1','2','3','4','5') ;
4 --
5 BEGIN
6 --
7 prcl_nested(t_Array) ;
8 --
9 END ;
10 /
p_Array(1): 1
p_Array(2): 2
p_Array(3): 3
p_Array(4): 4
p_Array(5): 5
PL/SQL procedure successfully completed.
Similar Messages
-
Could some please let me know the differences between nested tables and varrays?
Check out
http://www.unix.org.ua/orelly/oracle/prog2/ch19_01.htm -
Using nested tables and varrays in Forms/Reports6i
Hi! Could anybody give practical examples of applications based on nested tables and varrays in Forms/Reports6i.
The possible schema of building user interface and so on.
Thank you.
[email protected]Hi,
Varrays and nested tables are not supported within Forms6i and Reports6i. This means tare is no way to use it.
Frank -
hi friends,
i have a question:
why do we use nested tables and varrays?Read the following and try to understand the examples. Try to relate them to various situations or scenarios where you can implement them. You will understand the benefits.
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/collections.htm#LNPLS005
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/tuning.htm#LNPLS01205 -
Hi ,
I created 2 Nested Table & tried to insert the data in Table through Procedure but it gave an err msg.
create type name as object
(fname varchar2(20),
mname varchar2(20),
lname varchar2(20));
create type address as object
(city varchar2(20),
state varchar2(20),
pin varchar2(20));
create type ename as table of name;
create type eaddress as table of address;
create table emp_rec
(employee_id varchar2(5),
employee_name ename,
employee_address eaddress)
nested table employee_name store as empname,
nested table employee_address store as empaddress;
insert into emp_rec
values('1',
ename(name('anand','kumar','chouksey')),
eaddress(address('vashi','mh','400093')));
//Data Inserted
//Procedure for Inserting Another Data Works
create or replace procedure nest_proc
is
begin
insert into
the
(select employee_address from emp_rec where employee_id=1 ) e
values('jbp','mp','482002');
--where employee_id=1;
end;
begin
nest_proc;
end;
PL/SQL procedure successfully completed.
//But if i'll try to insert the data into 2 nested tables then gets failed.
create or replace procedure nest_proc
is
begin
insert all into
the
(select employee_name,employee_address from emp_rec where employee_id=1 ) e
values('x','y','z');
into the(select employee_address from emp_rec where employee_id=1 ) e
values('a','b','c');
--where employee_id=1;
end;
Kindly help me out.
Rgrds,
AnandHi,
Thanks for replying ,actually i did the mistake. I'm using multitable insert stmt. on 2 different tables that's why it gave an err msg.Instead of using multitable insert stmts i used 2 insert stmt. on Procedure & it gets compiled.
Regards,
Anand -
Problem creating an nested table.
Hi,
I try to create a type of mytable%rowtype:
create type test_type is table of mytable%rowtype;
The response is:
Type created with compile errors. (<- free translation from german ;)
Creating a table of varchar2(100) works as expected.
Is this a license restriction of XE or am I just too stupid for this?
Thanks in advance.
ThomasAs far as I know this limitation is not an XE limitation, you can check for the other editions also.
%TYPE and %ROWTYPE can be used within PL/SQL, not SQL.
DECLARE
TYPE Cust_tab IS TABLE OF
Customers_Active%ROWTYPE;
Custs Cust_tab;
BEGIN
SELECT Customer_Account_Id, Effective_Date,
Expired_Date
BULK COLLECT INTO Custs
FROM Customers_Active;
END;
DECLARE
emprec employees_temp%ROWTYPE;
BEGIN
emprec.empid := NULL;
emprec.deptid := 50;
DBMS_OUTPUT.PUT_LINE('emprec.deptname: ' || emprec.deptname);
END;
/ -
Passing table of varray to a procedure
Hi,
I have a procedure which takes the following parameters:
create or replace
PROCEDURE VECTORSUMMARYSTATISTICS
chartOption IN CHARTOPTION,
userChoicedate IN C_TAB,
AllCases IN boolean,
strVector_id VARCHAR2,
strEntityName VARCHAR2,
CollectionName VARCHAR2
) AS
C_TAB is a type created on the database:
create or replace
TYPE C_TAB AS TABLE OF C_REC;
And C_REC:
create or replace
TYPE C_REC AS OBJECT
time_value TIMESTAMP
In the body of the procedure I am using the table "userChoicedate" in the following way:
for idx in userChoicedate.first..userChoicedate.last
loop
tuserdate_rec:=userChoicedate(idx); //table passed from the parameter
tuserdate.extend(1);
tuserdate(idx):=tuserdate_rec;
end loop;
where tuserdate_rec is declared in the following way:
--record for holding a single user date
tuserdate_rec C_REC;
Before executing this procedure from pl/sql I am filling some test date from another pl/sql page:
percRec2 C_REC;
result_tab C_TAB;
result_tab:=C_TAB();
result_tab.extend(10);
percRec2:=C_REC(TO_TIMESTAMP('01-01-2004 12:00:00.000', 'DD-MM-YYYY HH:MI:SS.FF3') );
result_tab(1):=percRec2;
percRec2:=C_REC(TO_TIMESTAMP('01-04-2004 12:00:00.000', 'DD-MM-YYYY HH:MI:SS.FF3') );
result_tab(2):=percRec2;
percRec2:=C_REC(TO_TIMESTAMP('01-07-2004 12:00:00.000', 'DD-MM-YYYY HH:MI:SS.FF3'));
result_tab(3):=percRec2;
percRec2:=C_REC(TO_TIMESTAMP('01-10-2004 12:00:00.000', 'DD-MM-YYYY HH:MI:SS.FF3'));
result_tab(4):=percRec2;
So when calling the procedure:
VECTORSUMMARYSTATISTICS(ch,result_tab,FALSE,'WBHP','PRD3','CaseCollection1');
I am getting the following error message:
Error report:
ORA-06531: Reference to uninitialized collection
ORA-06512: at "SIMSERVER.VECTORSUMMARYSTATISTICS", line 184
ORA-06512: at line 54
06531. 00000 - "Reference to uninitialized collection"
*Cause: An element or member function of a nested table or varray
was referenced (where an initialized collection is needed)
without the collection having been initialized.
*Action: Initialize the collection with an appropriate constructor
or whole-object assignment.
So here at this line in bold the problem is:
For idx in userChoicedate.first..userChoicedate.last
loop
tuserdate_rec:=userChoicedate(idx);
tuserdate.extend(1);
tuserdate(idx):=tuserdate_rec;
end loop;
Any help
Thanks
Message was edited by:
user646975Hi,
Are u sure cause always the procedure is not compiling
This time I got the following problem:
Error(182,11): PLS-00103: Encountered the symbol "(" when expecting one of the following: in The symbol "in" was substituted for "(" to continue.
Error(320,71): PLS-00103: Encountered the symbol "GROUP" when expecting one of the following: , from into bulk -
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 -
Passing PL/SQL table type as IN Parameter to DB Adapter
Hi,
I have an requirement to pass multiple record values(array of values) to an API from BPEL process.
For this,
1) I have created a package procedure having PL/SQL table type variable as IN Parameter.
2) In the BPEL process, created a DB adpater pointing to the above API.(Created wrapper API impicitly)
When I intiated the BPEL process passing multiple values, the API is taking only the first value, ignoring rest of the values.
Any reason, why only the first value is accepted by the API ?
Thanks,
Rapp.If I understand correctly, JPublisher generates a wrapper API for an underlying API that takes a PL/SQL table as an IN parameter. The wrapper will generate and use a SQL nested table as the type for the IN parameter of the wrapper procedure.
The DB adapter DOES support nested tables, varrays, and objects as IN parameters of an API. The problem you are seeing is most likely due to the way you are modeling your BPEL process, specifically with respect to your Assign activities.
When you Assign TO an IN parameter, make sure that you drill down all the way and choose the parameter name in the InputParameters root element. Similarly, when you Assign FROM the API value, you must drill down and choose the name of the OUT parameter in the OutputParameters root element.
In a Transform activity, you would use the FOR construct on the target side to get the values of the nested table or varray from the source side. -
How to use nested tables object in oracle form
Hello forum
How all r u ..
i need ur help guys, pls help me out...
i m using an object oriented approach to design my database by using nested tables and
varrays. it is quite done successfully.
but the problem is when i m trying to use that object of nested table into the datablock of the form it is not been added to item list of that block.
so what is the proper way to use these type of objects to the form.
all ideas are welcomed and vry much required.
pls give example if possible so easy to understand or have any demo form related to above case then pls post me to my id i.e [email protected]
thank u all and expecting some expert solutionsHello Francois Degrelle...
How r u doing ... i have searched the forum abt the above mentioned topic then i found that u have some demo form which will help out to explain the functionality of the nested table in forms ..
will u pls me that form to my i.e [email protected] pls mail all the detail u have regarding using nested tables to forms and reports
lots of thanks to u n advance. -
Inserting Data into nested table
I am exploring the differences between OBJECT & RECORD.
As i am still in process of learning, I found that both are structures which basically groups elements of different datatypes or columns of different datatypes, one is used in SQL and other is used in PL/SQL, please correct me if I am wrong in my understanding.
Below i am trying to insert data into an table of type object but i am unsuccessful can you please help.
CREATE OR REPLACE type sam as OBJECT
v1 NUMBER,
v2 VARCHAR2(20 CHAR)
---Nested Table---
create or replace type t_sam as table of sam;
--Inserting data----
insert into table(t_sam) values(sam(10,'Dsouza'));
Error Message:
Error starting at line 22 in command:
insert into table(t_sam) values(sam(10,'Dsouza'))
Error at Command Line:22 Column:13
Error report:
SQL Error: ORA-00903: invalid table name
00903. 00000 - "invalid table name"
*Cause:
*Action:Ariean wrote:
So only purpose of equivalent SQL types concept of nested tables is to use them as one of the data types while defining an actual table?
Sort of - you can definitely use them for more than just "defining an actual table". (I'm fairly certain you could pass a nested table into a procedure, for example - try it, though - I'm not 100% sure on that - it just "makes sense". If you can define a type, you can use it, pass it around, whatever.).
Ariean wrote:
And that nested table could be a record in SQL or an Object in PLSQL or just simple datatype(number,varchar etc)?
Nested tables are just like any other custom data type. You can create a nested table of other data types. You can create a custom data type of nested tables.
It could get stupidly .. er, stupid O_0
CREATE TYPE o_myobj1 AS object ( id1 number, cdate1 date );
CREATE TYPE t_mytype1 AS table of o_myobj1;
CREATE TYPE o_myobj2 AS object ( id2 number, dumb t_mytype1 );
CREATE TYPE t_dumber AS table of o_myobj2;
O_0
Ok, my brain's starting to hurt - I hope you get the idea
Ariean wrote:
Secondly is my understanding correct about OBJECT & RECORD?
I can't think of any benefit of describing it another way. -
Unable to export nested tables and vaarys
Hai
How to export nested tables and varrays in oracle 8i (8.1.6) .When exporting nested tables and varrays not exporting .What is the advantage use of nested tables and varrays
Thanks in advance
mohanHello,
I think that with such a new release you should use DataPump (expdp/impdb) to
export Tables.
For exporting a complete Schema you may use the following syntax:
expdp {color:red}+user+{color}/{color:red}+password+{color} PARFILE=pfexport.txt_With pfexport.txt as bellow:_
SCHEMAS={color:red}+schema_name+{color}
FLASHBACK_TIME="TO_TIMESTAMP(to_char(SYSDATE,'DD-MM-YYYY HH24:MI:SS'),'DD-MM-YYYY HH24:MI:SS')"
CONTENT=ALL
DIRECTORY=EXP_DIR
DUMPFILE={color:red}+dump_file_name+{color}
LOGFILE={color:red}+log_file_name+{color}Then, in this example, you'll get the "dump file" and the "log file" into the EXP_DIR Oracle directory (if it exists).
You can check your Oracle Directories with the following query:
select * from dba_directories;Then, you can use one of these Directories or create a new one with the following statement
CREATE OR REPLACE DIRECTORY {color:red}+directory_name+{color} AS '{color:red}+directory_path+{color}';
GRANT READ,WRITE ON DIRECTORY {color:red}+directory_name+{color} TO {color:red}+user_name+{color};Hope it can help,
Best regards,
Jean-Valentin
Edited by: Lubiez Jean-Valentin on Nov 28, 2009 12:08 PM -
Using Nested Table in Select Statement
Hi all ,
Can i use the PL/SQL nested table or Varray
in the select statement as a normal table joined with other database tables.
i.e.
I have a nested table NT_1 in PL/SQL proc
i have to use this NT_1 in the select statement as
select xxx from
tab_1,
tab_2,
NT_1
where
< some conditional joins >.
Please help me in this regard.
regds
Dhananjaya.Hyou can not use a varray as part of a SQL Statement in order to build joins.
Can you explain better what do you want to do ?
Joel P�rez -
Nested Tables select query soooooo slow
I know that varrays are supposed to be used for small arrays. But, we are comparing nested tables to varrays and two table joins. Nested table query is unimaginably ,unacceptably slow.
Is there anybody else out there who experienced the same thing. Are there ways to speed up the select queries.(besides indexes)If you try to use nested sql statement. Please be sure to setup the index to some specific tables inside oracle
Doing this will speed up your performance about 5 ~ 9 times original.
[email protected] -
Tables in memory (Nested tables ?)
For performance reasons, I would like to insert, update, etc...
a table in memory. Can I use a nested table as if it was a
normal table ? Can I do updates on nested tables with values
from normal database tables ??
Statement like : Update <nested-table> set <nested-
table>.x=<value> where <nested-table>.y = <normal-table>.y
Thanks for a quick response.The answer is yes and no.
A nested table is a "collection" and can be referenced in a SQL
statement using the pseudo-functions THE, CAST, MULTISET and
TABLE. The nested table and varray collections can be a column
in a database table (Oracle8) and are persistent. SQL
statements cannot act on memory held nested tables, varray and
index-by collections, which are transient. Index-by collections
are same as the older PL/SQL tables.
SQL statements cannot operate directly on transient collections.
For speed you can define an index-by collection as a table of
rowtype, and move data back and forth from database tables and
memory held tables using SQL. Records and index-by tables are
more efficient in Oracle 8 than in Oracle 7
In PL/SQL you can use replacement (:=) on the record or
record.column of the rowtype index-by collection. The downside
is you have to keep track of your own indexing which is only
BINARY_INTEGER, no SELECT, UPDATE, INSERT using FROM and WHERE
on transient collections. This works in Oracle 7 also.
Good Luck.
Maybe you are looking for
-
Get VLC to do fullscreen float in Xmonad
Hi, Short background: I have started to use XBMC for watching and organizing videos. Everything works great except playing the videos. I have a constant stutter about every 3-4 seconds and from time to time the picture freeze but the movie running in
-
Shipping notification and PO outstanding qty in ATP check
Hi all, I have the following situation: intercompany purchase order process with confirmation control key (including outbound and inbound delivery). In my ATP check I have included purchase orders and shipping notifications. This has as consequence t
-
Low Quality Video and Photo on iCloud
I recently upgraded from an iPhone 4 to an iPhone 6, in doing so thought I would take advantage of the iCloud facility. What a great idea until I replayed the video back, talk about grainy low quality same for the photos. Is there a fix for this or
-
Layout problem - multiple repeating frames
Hi, I have a layout problem, pls help! Short report description: - Repeating Frame1 - gives 1 record, contains all other frames, variable vertical elasticity - - Frame2 - contains all frames beneath - variable vertical elasticity - - - Frame3 - varia
-
Urgent! Please Answer iPod Touch Question!
How often does Apple come out with new iPods (on average) Is it about 2 years? Do you think they will drop the iPod? Do you think they will incorporate the new technologies they have discoved with the iPhone 5C and 5S eventually into iPod touch? Plea