Associative array in Oracle procedure problem
HelloI searched through the internet and this forum and have not been able to solve a problem using the associative array of values in an IN clause. Everything I read says that I can not use the associative array directly in the SQL statement. I have to convert it to a table and then I can use it. Unfortunately, I get a ' ORA-21700: object does not exist or is marked for deletion "error when trying to access the table, I filled the table. Please note that I checked the table is actually filled during the loop. I capture the error when you are referencing in the SELECT statement.
I stated the following in the ARCHIVE package specification:
TYPE RSType IS REF CURSOR;
TYPE integer_aat IS TABLE OF INTEGER INDEX BY PLS_INTEGER;
Integer_table TYPE TABLE IS OF INTEGER;
The procedure is the following:
PROCEDURE SEL_SEARCH_RESULTS (v_term IN VARCHAR2,
v_categories IN ARCHIVE.integer_aat,
RS ON RSType)
AS
/ * END: Returns the results for the category and key word provided
VARIABLES:
v_categories = array of categories of documents
v_term = keyword entered
RS = game results
*/
tbl_cat ARCHIVE.integer_table: = ARCHIVE.integer_table ();
BEGIN
BECAUSE me in 1... v_categories. COUNTY
LOOP
tbl_cat. EXTEND (1);
tbl_cat (i): = v_categories (i);
END LOOP;
OPEN FOR RS
SELECT A.ID,
B.CATEGORY,
A.FILENAME,
A.DISPLAY_NAME,
A.COMMENTS
OF TBL_ARCHIVE_DOCUMENTS,.
B TBL_ARCHIVE_DOC_CAT,
C TBL_ARCHIVE_DOC_KEYWORDS
WHERE A.ID = B.ID
AND A.ID = C.ID
AND B.CATEGORY in (SELECT * FROM TABLE (tbl_cat))
AND C.KEYWORD = v_term
ORDER BY A.ID;
END SEL_SEARCH_RESULTS;
Any help would be greatly appreciated and thanks in advance.
Matt
905707 wrote:
Thanks for the quick response. I looked at the example suggest you and made the following changes. Now, I get an invalid 'Data Type' error on the "column_value SELECT FROM TABLE (CAST (tbl_cat AS tbl_integer))' statement. I must be missing something simple and I can't put my finger on it.
You did not create a SQL type as I said. tbl_integer is still declared in the PLSQL code you have posted.
Reread my initial response and look at the example I posted (the very first thing that is done is to create a SQL type).
Tags: Database
Similar Questions
-
Access to the Oracle procedure table
Hi all
I can pass the array as a parameter of procedure Oracle object?
Application procedure for the environment to run Java and we pass the java array object as a parameter
Thanks in advance...
Kind regards...http://lmgtfy.com/?q=Java+pass+array+to+Oracle+procedure
-
Proc 10 call Oracle stored g with associative array from c# VS 2008
I have the following PL/SQL procedure:
CREATE OR REPLACE PROCEDURE HMA_ADM. PRC_VDM_SAVDEL_VEN_DOC
(
P_OP IN VARCHAR2,
P_USRID IN TB_VDM_MANAGE_DOCUMENTS. CREATEDBY % TYPE,
P_DATE IN VARCHAR2,--MUST BE STRING, OTHERWISE WE GET AN ERROR
P_DOCNAM IN TB_VDM_MANAGE_DOCUMENTS. DOCUMENTNAME % TYPE,
P_DOCLNK IN TB_VDM_MANAGE_DOCUMENTS. BUILDER % TYPE.
P_FNGUID IN TB_VDM_MANAGE_DOCUMENTS. FILENET_GUID % TYPE,
P_DESC IN TB_VDM_MANAGE_DOCUMENTS. DESCRIPTION % TYPE,
P_REQID IN VARR
) IS
Where VARR is:
CREATE OR REPLACE TYPE VARR'S ARRAY OF INTEGER;
In c#, I have the following code:
Int64 [] intReqID;
OracleCommand cmdVDL = new OracleCommand (DBQueries.SPQRY_SAVDELVENDOC, connDB);
cmdVDL.CommandType = CommandType.StoredProcedure;
cmdVDL.Parameters.Add (new OracleParameter ("P_OP", strop));
cmdVDL.Parameters.Add (new OracleParameter ("P_CREATEBY", strUID));
cmdVDL.Parameters.Add (new OracleParameter ("P_CREATEDATE", strDate));
cmdVDL.Parameters.Add (new OracleParameter ("P_DOCNAM", strDocNam));
cmdVDL.Parameters.Add (new OracleParameter ("P_DOCLNK", strURL));
cmdVDL.Parameters.Add (new OracleParameter ("P_FNGUID", strGUID));
cmdVDL.Parameters.Add (new OracleParameter ("P_DESC", strDesc));
cmdVDL.Parameters.Add (new OracleParameter ("P_REQID", OracleDbType.Int64) {}
CollectionType = OracleCollectionType.PLSQLAssociativeArray,
Size = intReqID.Count (),
Value = intReqID,
DbType = DbType.Int64,
OracleDbType = OracleDbType.Int64
});
[] OracleParameterStatus stat = new OracleParameterStatus [intReqID.Count ()];
for (i = 0; i < intReqID.Count (); i ++) {}
STAT [i] = OracleParameterStatus.Success;
}
"" "cmdVDL.Parameters ["P_REQID"]." ArrayBindStatus = stat;
cmdVDL.ExecuteNonQuery ();
When I run the present, I get the following error:
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in the call to 'PRC_VDM_SAVDEL_VEN_DOC '.
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
If I remove the associative array at the same time, the procedure works very well.
What I am doing wrong?In addition,
(1) support UDT requires ODP 11106.20 or later version (but can be used against db 10 g)
(2) if the plsql is editable, you can exchange to an associative array rather to avoid having to create classes customized for the UDT and here is a short example of soft.
Greg/* CREATE or replace PACKAGE MYPACK3 AS TYPE numarray is table of number index by BINARY_INTEGER; PROCEDURE getempsinarray(thearray IN numarray, numrecs out number); END MYPACK3; / CREATE or replace PACKAGE BODY MYPACK3 AS PROCEDURE getempsinarray(thearray IN numarray, numrecs out number) IS begin numrecs := thearray.count; END getempsinarray; END MYPACK3; / */ using System; using System.Data; using Oracle.DataAccess.Client; public class indexby { public static void Main() { OracleConnection con = new OracleConnection("data source=orcl;user id=scott;password=tiger;"); con.Open(); OracleCommand cmd = new OracleCommand("mypack3.getempsinarray", con); cmd.CommandType = CommandType.StoredProcedure; OracleParameter Param1 = cmd.Parameters.Add("param1", OracleDbType.Int32); Param1.Direction = ParameterDirection.Input; Param1.CollectionType = OracleCollectionType.PLSQLAssociativeArray; Param1.Value = new int[3]{7369,7499, 7521}; Param1.Size = 3; OracleParameter Param2 = cmd.Parameters.Add("param2", OracleDbType.Int32, DBNull.Value, ParameterDirection.Output ); cmd.ExecuteNonQuery(); Console.WriteLine("{0} records passed in",Param2.Value); con.Close(); } }
-
How to see the output of an associative array in procedure
Hello
I tried the following code
And confused about the research at the exit of the associative array.
In the above code, I want to see the output of the test_tab located in the search_obj procedure.CREATE OR REPLACE PACKAGE test_pak1 AS FUNCTION map_object (obj_typ_in VARCHAR2) RETURN VARCHAR2; CURSOR c_c1 IS SELECT * FROM emp; TYPE test_ttyp IS TABLE OF c_c1%ROWTYPE INDEX BY PLS_INTEGER; PROCEDURE search_obj (obj_type VARCHAR2); END; CREATE OR REPLACE PACKAGE BODY test_pak1 AS FUNCTION map_object (obj_typ_in VARCHAR2) RETURN VARCHAR2 IS BEGIN dopl ('Hello'); RETURN abc; END; PROCEDURE search_obj (obj_type VARCHAR2) IS test_tab test_ttyp; BEGIN DOPL (test_tab); end; END;
could you please help me in this
Thank youHi, smile,
If you want to see records, you must put the lines in your table. Here's a solution: in this solution, I only edit the search_obj procedure of your package like this:
PROCEDURE search_obj (obj_type VARCHAR2) IS test_tab test_ttyp; test_tab_r c_c1%ROWTYPE; BEGIN --test_tab; --Here we put something in test_tab OPEN c_c1; LOOP Fetch c_c1 into test_tab_r; exit when c_c1%NOTFOUND; test_tab(test_tab.COUNT + 1) := test_tab_r; END LOOP; CLOSE c_c1; FOR i IN 1 .. test_tab.COUNT LOOP dbms_output.put_line(test_tab(i).empno); END LOOP; END;
Here is the result:
SQL> exec test_pak1.search_obj('parameter_not_used_in_the_procedure'); 7369 7499 7521 7566 7654 7698 7782 7788 7839 7844 7876 7900 7902 7934 PL/SQL procedure successfully completed. SQL>
-
Problems associative Array (Object)
Here's the function that I face
I read in a delimited string and using indexed arrays to break them up and assign keys and values to an associative array in a loop.
I use variables in the loop and the load as expected in the loop table
but outside the loop, the only key is the name of the variable and the value is not set
This is the case by using dot or rating table, as well as literal strings for keys
any help is appreciated
watchSuspendData = function (id, oldval, newval): String {}
the incoming suspendData string is delimited by a semicolon;
newVal is: firstValue = Yes; captivateKey = 1
var listSuspendData:Array = newval.split(";"); convert to a list of key/value pairs
If (listSuspendData.length > 0) {}
line 123: listSuspendData.length is: 2
for (i = 0; i < listSuspendData.length; i ++) {//for each key/value pair}
var keyValArray:Array = new Array();
var myNameValue:String = listSuspendData ;
line 127: listSuspendData is: firstValue = Yes
keyValArray = myNameValue.split ("="); EM on the equal sign
var myKey:String = keyValArray [0];
var myVal:String = keyValArray [1];
keyValArray [0] is: firstValue
keyValArray [1] is: Yes
store the key and the value in an associative array
suspendDataArray.myKey = myVal;
trace ("line 134: suspendDataArray is:" + suspendDataArray.myKey);
trace is line 134: suspendDataArray is: Yes on the first pass and 1 on the second
}
the loop below always returns an array key: myKey and the undefined value
for (x in suspendDataArray) {}
trace ("x is:" + x); x is: myKey
trace ("the val is:" + suspendDataArray.x); the val is: undefined
} //end for
}
return newval;Many thanks to blemmo and everyone who responded
using the table syntax OK solved the problem
really appreciate the help! -
What is the preferred means of data transmission in the associative array of the nested table record vs
Choose between Nested Tables and associative arrays
The two nested tables and associative arrays (formerly index - by tables) use similar index notation, but they have different characteristics when it comes to persistence and ease of passing parameters.
Nested tables can be stored in a column of data, but can of associative arrays. Nested tables can simplify the SQL operations where you would normally join a single-column table with a larger table.
Associative arrays are appropriate for relatively small lookup tables where the collection can be constructed in memory whenever a procedure is called or a package is initialized. They are good for the collection of the information volume is unknown beforehand, because there is no fixed limit on their size. Their index values are more flexible, as associative array indices can be negative, can be no sequential and can use values of string instead of numbers.
PL/SQL automatically converts between the bays of the host and the associative arrays that use values of digital keys. The most effective way to move the collections to and from the database server is to implement data values in associative arrays, and then use these associative arrays with erections in bulk (the
FORALL
statement orBULK
COLLECT
clause).With the help of documents and Collections of PL/SQL
Read this:
-
Error renaming dates to an associative array of type date
Hi all
I am facing issue while assigning dates in an associative array of type date:
Oracle version:
SQL > select * from v version $;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
AMT for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - ProductionStored procedure, I try to write is as follows
- create or replace procedure (jp1)
- p_start_date default date trunc(sysdate,'MM')
- p_end_date date default trunc (sysdate)
- )
- is
- number of l_no_of_days;
- type t_date_id is table of date
- index by pls_integer;
- l_date_id_arr t_date_id;
- Start
- l_no_of_days: = p_end_date - p_start_date;
- for i from 0
- .. l_no_of_days - 1
- loop
- l_date_id_arr: = p_start_date + i;
- dbms_output.put_line (p_start_date + i);
- end loop;
- end;
- /
I get error on line 14 when compiling it. and the error message is as follows:
JP1 PROCEDURAL errors:
LINE/COL ERROR
-------- -----------------------------------------------------------------
14/5 PL/SQL: statement ignored
14/22 PLS-00382: expression is of the wrong typeWhile studying this, I tried the value of (p_start_date + i) using dbms_output.put_line and the output is so date itself.
- create or replace procedure (jp1)
- p_start_date default date trunc(sysdate,'MM')
- p_end_date date default trunc (sysdate)
- )
- is
- number of l_no_of_days;
- type t_date_id is table of date
- index by pls_integer;
- l_date_id_arr t_date_id;
- Start
- l_no_of_days: = p_end_date - p_start_date;
for i from 0... l_no_of_days-1
- loop
- -l_date_id_arr: = p_start_date + i;
- dbms_output.put_line (p_start_date + i);
- end loop;
- end;
- /
output of the
- exec jp1
is as follows:
1ST DECEMBER 13
2 DECEMBER 13
3 DECEMBER 13
DECEMBER 4, 13
5 DECEMBER 13
DECEMBER 6, 13
7 DECEMBER 13
DECEMBER 8, 13
9 DECEMBER 13
DECEMBER 10, 13
DECEMBER 11, 13
DECEMBER 12, 13
13 DECEMBER 13
14 DECEMBER 13
15 DECEMBER 13
16 DECEMBER 13
17 DECEMBER 13
18 DECEMBER 13
I see the release date itself. so why he throws error while the same assignment to an associative array of type date.
I tried Google too for the same but without success.
Any help is appreciated in this regard not or any pointer another thread on the internet or in this forum.
Thanks in advance
Jagdeep Seven
Read associative arrays:
- create or replace procedure (jp1)
- p_start_date default date trunc(sysdate,'MM')
- p_end_date date default trunc (sysdate)
- ) is
- number of l_no_of_days;
- type t_date_id is table of date
- index by pls_integer;
- l_date_id_arr t_date_id;
- Start
- l_no_of_days: = p_end_date - p_start_date;
- because me in 0.l_no_of_days - 1
- loop
- l_date_id_arr (I): = p_start_date + i;
- dbms_output.put_line (p_start_date + i);
- end loop;
- end;
----
Ramin Hashimzade
-
Associative array as a type of database
As it is very well create an associative array inside a stored procedure:
type urltype is table of varchar2(32767) index by varchar2(30);
Can it be created as a type of database at the level of the schema?
Brian.McGinity wrote:
As it is very well create an associative array inside a stored procedure:
- type urltype is the table of index varchar2 (32767) by varchar2 (30);
Can it be created as a type of database at the level of the schema?
Non - associative arrays are a function of PL/SQL.
See table 5-1 in the doc of the PL/SQL language for a description of each type of collection and where (pl/sql, sql, etc.) they can be used.
http://docs.Oracle.com/CD/E11882_01/AppDev.112/e25519/composites.htm#CHDBHJEI
-
Cannot run the autonomous block for input of associative array parameter
Hello
I have created an associative array in a package-PKG_CMT_DAP
TYPE r_supply_type_id IS RECORD( supply_type_id varchar2(50)); TYPE t_supply_type_id IS TABLE OF r_supply_type_id INDEX BY BINARY_INTEGER; l_supply_type_id t_supply_type_id;
Later created a test procedure with an input of the above kind parameter
create or replace procedure test_prc(p_in_st_id IN PKG_CMT_DAP.t_supply_type_id) AS v_input1 number; v_input2 number; BEGIN FOR z IN 1..p_in_st_id.COUNT LOOP DBMS_output.put_line(p_in_st_id(z)supply_type_id); END LOOP; END test_prc;
How to update successfully.
Created a stand-alone as block below
DECLARE BEGIN test_prc(p_in_st_id=>(100,200,300)); END;
Above am past in 100,200,300 as an input string, and the expected output should display all the numbers above on the screen.
But it throws the below error
Error report: ORA-06550: line 3, column 1: PLS-00306: wrong number or types of arguments in call to 'TEST_PRC' ORA-06550: line 3, column 1: PL/SQL: Statement ignored 06550. 00000 - "line %s, column %s:\n%s" *Cause: Usually a PL/SQL compilation error. *Action:
Could you please help me where I am doing wrong?
Kind regards
Claudy Kotekal
Claudy,
While calling the procedure, you must declare the variable of type table. Give the values for the elements in the begin block and then pass that variable in the procedure. Something like below:
Declare
in_array PKG_CMT_DAP. r_supply_type_id;
Begin
in_array (1) .supply_type_id: = 100;
in_array (2) .supply_type_id: = 200;
in_array (3) .supply_type_id: = 300;
test_prc (in_array);
end;
NOTE: There might be a few problems with my code syntax, but logic would be same.
Try this and let me know.
Thank you
-
Quoting docs.oracle.com lines
Associative arrays are used to represent sets of data of arbitrary size, with quick search of an individual element without its position in the table and without
having to loop through all the elements in the array. Here is a small example
DECLARE
TYPE population_type IS TABLE OF NUMBER INDEX OF VARCHAR2 (64);
country_population population_type;
continent_population population_type;
howmany NUMBER;
that VARCHAR2 (64);
BEGIN
country_population ('Greenland'): = 100000; -Creates the entry
country_population ('Iceland'): = 750000; -Creates the entry
-Research associated with a value chain
howmany: = country_population ('Greenland');
continent_population ('Australia'): = 30000000;
continent_population ('Antarctica'): = 1000; -Creates the entry
continent_population ('Antarctica'): = 1001; -Replaces the previous value
-Returns "Antarctic" which comes first in alphabetical order.
who: = continent_population. FIRST;
-Returns "Australia", which comes last in the alphabetical order.
who: = continent_population. LAST;
-Returns the value corresponding to the last key, in this
-case of the Australia population.
howmany: = continent_population (continent_population. LAST);
END;
/
my doubt is in what regards the statement "with a quick search of an individual element without its position in the table".can someone give a small relevant example. Therefore the associative arrays is also appropriate for relatively small lookup tables where the collection can be constructed in memory eachtime, a procedure is called? Thanks in advance...>
my doubt is in what regards the statement "with a quick search of an individual element without its position in the table".can someone give a small relevant example.
>
Think of it as gradually close equivalent to a hash of key/value pairs. When you want to insert an item provide you the key, Oracle axe key to find the entry in the hash table. It doesn't matter if the entry is the first, last, or any other arbitrary position in the table.
>
Therefore the associative arrays is also appropriate for relatively small lookup tables where the collection can be constructed in memory eachtime, a procedure is called?
>
The scope of the variables of the procedure is only the duration of the procedure. They are built when the procedure is called and destroyed when the procedure ends.If any associative array created in the procedure must be small to minimize the impact on the performance of the table fill. If the procedure performs complex calculations or ETL one record at a time, it is more efficient to get a value from the array instead of having to re - query a database table for him.
For example, for the United States, a list of 50 State and their full name abbreviations that can be stored in an associative array and procedure could extract the code of the State of a data element, and quickly find the name of the State of the table. It would be faster than executing a query on the database on a lookup table.
-
Check if a value is in an associative array?
Hello
I am writing a process to plug into an existing infrastructure. I have an associative array of data (that I can't change the definition of) which is defined as:
type vc_arr2 is table of the varchar2 (32767) index directory.
An example of a data set can be:
Now I need to be able to see information indicating if a specific text value appears in the values, that is to say "is"Bananas"in the table? Now of course I could do it by writing a procedure loop over all the elements in order but there at - it do something built that? There are the obvious overhead (potentially) to loop through each element for each item, I'm looking for - I hope that there is something built in which more effective (IE, 'index' values or something like that).Key Text 1 => Apple 2 => Banana 3 => Pear 4 => Plum 5 => Grape etc etc
As far as I know, ARRAY. Exists() works on the key and not the value, and MEMBER OF cannot be used with associative arrays.
I'm not interested in what the key is for a given value (and I realize, it may be more than one key mapping to a given value), all I want is just if the element exists in the table.
Any help or suggestions would be greatly appreciated!No, you will need to loop through each of them, as your index finger is not on the text.
No reason to use an associative array in the first place? Why not use database and SQL tables? Oracle is good at those. ;)
-
I'm doing an associative array, where the key is a string and the value is an array of strings.
I tried to declare it like this:
PROCEDURE myProcedure IS
tableau_donnees argument type is varray (200) of VARCHAR2 (20);
Column TYPE IS an ARRAY OF tableau_donnees INDEX BY VARCHAR2 (20);
my_collection columns; -collection of multi dimensional pl/sql
BEGIN
my_collection ('test') (1): = "Hello"; -It is the idea...
"my_collection ('test') (2): = ' 8128 is the number";
my_collection ("some other field' ') (1): = 'foo';
-etc etc.
But I get the error Oracle ORA-06531, reference to an uninitialized collection:
Cause: A service of element or member of a nested table or varray has been referenced (where an initialized collection is necessary) without the collection has been initialized.
Action: Initialize the collection with an appropriate constructor or assignment of the whole object.
I tried to use 'extend()' initialize the varray, but no help...
my_collection('test').extend (200);
-----
I also tried this:
PROCEDURE myProcedure IS
Data TYPE of TABLE IS OF VARCHAR2 (20);
Column TYPE IS an ARRAY OF data INDEX BY VARCHAR2 (20);
my_collection columns; -collection of multi dimensional pl/sql
But it's always the same. I am quite new to PL/SQL, if any help would be great!
-j900685 wrote:
I'm doing an associative array, where the key is a string and the value is an array of strings.create or replace procedure myProcedure is type data_array is varray(200) of varchar2(20); type coltype is table of data_array index by varchar2(20); my_collection coltype; begin my_collection('test') := data_array('hello','8128 is the number'); my_collection('some other field') := data_array('foo'); end; /
And if you want to add elements in varray:
create or replace procedure myProcedure is type data_array is varray(200) of varchar2(20); type coltype is table of data_array index by varchar2(20); my_collection coltype; begin my_collection('test') := data_array('hello'); my_collection('test').extend; my_collection('test')(2) := '8128 is the number'; my_collection('some other field') := data_array('foo'); end; /
Or:
create or replace procedure myProcedure is type data_array is varray(200) of varchar2(20); type coltype is table of data_array index by varchar2(20); my_collection coltype; begin my_collection('test') := data_array(); -- initialize my_collection('test').extend; my_collection('test')(1) := 'hello'; my_collection('test').extend; my_collection('test')(2) := '8128 is the number'; my_collection('some other field') := data_array('foo'); end; /
SY.
-
PLS-00201 when adressing field in an associative array
To calculate the scores, I created an associative array that contains the totals of players until last week.
In a loop, I can make each player and add their scores this week to their total of last week.
Code:
Associative array:
italics
create or replace
TYPE "NUMBER_ARRAY" in the table of the number;
cur_vorige_totalen_array number_array;
FOR r_vorige_totalen in c_vorige_totalen (ld_training_dag)
LOOP
cur_vorige_totalen_array.extend;
cur_vorige_totalen_array (r_vorige_totalen.lidnummer): = r_vorige_totalen.totaal_punten_dit_seizoen;
END LOOP;
italics
To add the total to the current scores can do:
italics
OPEN c_huidige_totalen.
LOOP
Get the c_huidige_totalen COLLECT LOOSE cur_totalen_array LIMIT 100;
EXIT WHEN c_huidige_totalen % NOTFOUND;
END LOOP;
CLOSE C_huidige_totalen;
FORALL i IN cur_totalen_array. FIRST... cur_totalen_array. LAST
Training_aanwezigheid UPDATE your
SET ta.totaal_punten_dit_seizoen TREAT (cur_totalen_array (i) AS huidige_totalen_type) = .totaal_punten_dit_seizoen + cur_vorige_totalen_array (ta.lidnummer)
WHERE ta.lidnummer = TREAT (cur_totalen_array (i) AS huidige_totalen_type) .lidnummer
AND ta.training_id = p_training_id;
italics
I get an error PLS-00201 (ta.lidnummer must be set) on "BOLD" cur_vorige_totalen_array (ta.lidnummer) "BOLD"
Is it not possible to address ta.lidnummer in this way? How can I solve my problem in this case?
TX for your advicecHello
Discover FORALL statement Chater:
http://download.Oracle.com/docs/CD/B19306_01/AppDev.102/b14261/forall_statement.htm#i34324
Your code is not to comply with these restrictions:
>
-Part of a loop FORALL, impossible to make reference to the collection even in both the SET clause and the WHERE clause of an UPDATE statement. You need to maybe make a second copy of the collection and the new name in the WHERE clause.
-Impossible to refer to the individual record fields in the DML statements called by a FORALL statement. Instead, you can specify the entire file with the ROW SET clause in an UPDATE statement, or the VALUES clause in an INSERT statement.
-Indexes collection should be just the index rather than an expression variable, such that I rather than I + 1.
>
The last restriction is because you use this:
FORALL i IN cur_totalen_array. FIRST... cur_totalen_array. LAST
Training_aanwezigheid UPDATE your
SET ta.totaal_punten_dit_seizoen = TREAT (cur_totalen_array (i) AS huidige_totalen_type) .totaal_punten_dit_seizoen
+ cur_vorige_totalen_array ( ta.lidnummer )Single index variable is allowed as a clue - you cannot use variable I have here.
Published by: kordirko on 2010-10-20 23:38
-
Difference between an associative array, table etc.?
Hello
I wonder what are the differences in comparison with these? They seem similar, but a table need a custom c# and the associative array type class does not. When should you use that? Say I want to pass a collection of numbers to a perhaps stored procedure?You want to test something to appropriate for what your use to gauge that.
I just did a quick test and associative is quite a bit faster than the UDT for my test regarding the disappearance of the object and the invocation of the proc (I went from size 1000 channels 2000), but I've also used an empty body of the stored procedure and the proc in fact might affect things.
Here is my code if you want to test. I used ODT to generate the V2TYP class and then changed string [] m_V2TYP; to the public within this category just for ease of use.
It will be useful,
Greg/* create type v2typ is table of varchar2(4000); / create or replace package testpack as TYPE v2array is table of varchar2(4000) index by BINARY_INTEGER; PROCEDURE test_assoc_array(v2arr1 IN v2array); procedure test_udt(v2udt in v2typ); END; / CREATE or replace PACKAGE BODY testpack AS PROCEDURE test_assoc_array(v2arr1 IN v2array) IS begin null; END; procedure test_udt(v2udt in v2typ) is begin null; end; END; / */ using System; using System.Data; using Oracle.DataAccess.Client; namespace compare_assocarray_and_udt { class Program { static string constr = "data source=orcl;user id=scott;password=tiger;"; static void Main(string[] args) { int numelements = 1000; string[] vals = new string[numelements]; for (int i = 0; i < numelements; i++) vals[i] = new string('a', 2000); V2TYP myv2typ = new V2TYP(); myv2typ.m_V2TYP = vals; test_assoc_array(vals); test_udt(myv2typ); } static void test_assoc_array(string[] vals) { using (OracleConnection con = new OracleConnection(constr)) { con.Open(); using (OracleCommand cmd = new OracleCommand("testpack.test_assoc_array", con)) { cmd.CommandType = CommandType.StoredProcedure; OracleParameter Param1 = cmd.Parameters.Add("param1", OracleDbType.Varchar2); Param1.Direction = ParameterDirection.Input; Param1.CollectionType = OracleCollectionType.PLSQLAssociativeArray; Param1.Size = vals.Length; Param1.Value = vals; DateTime start = System.DateTime.Now; cmd.ExecuteNonQuery(); Console.WriteLine("assoc array elapsed: {0}ms", (System.DateTime.Now - start).TotalMilliseconds.ToString()); } } } static void test_udt(V2TYP val) { using (OracleConnection con = new OracleConnection(constr)) { con.Open(); using (OracleCommand cmd = new OracleCommand("testpack.test_udt", con)) { cmd.CommandType = CommandType.StoredProcedure; OracleParameter Param1 = cmd.Parameters.Add("param1", OracleDbType.Object); Param1.Direction = ParameterDirection.Input; Param1.UdtTypeName = "SCOTT.V2TYP"; Param1.Value = val; DateTime start = System.DateTime.Now; cmd.ExecuteNonQuery(); Console.WriteLine("udt elapsed: {0}ms", (System.DateTime.Now - start).TotalMilliseconds.ToString()); } } } } }
-
Table binding error ORA-01485 when I try to get in an associative array
Hello
I test to pass in an array associative odp.net
So I created a simple testpackage:
CREATE TABLE jwetesttab (CLIENTNR NUMBER (10) NOT NULL);
CREATE OR REPLACE PACKAGE IN THE JWETEST_PK
TYPE t_CLIENTNRS IS TABLE OF NUMBER INDEX OF PLS_INTEGER;
PROCEDURE TestArrayIn (p_CLIENTNRS IN t_CLIENTNRS, p_NbOfRowsInserted OUT NUMBER);
END JWETEST_PK;
/
CREATE OR REPLACE PACKAGE BODY JWETEST_PK AS
PROCEDURE TestArrayIn (p_CLIENTNRS IN t_CLIENTNRS, p_NbOfRowsInserted ON the NUMBER)
IS
BEGIN
FORALL i IN p_CLIENTNRS.first... p_CLIENTNRS. Last
INSERT INTO jwetesttab (CLIENTNR) VALUES (p_CLIENTNRS (i));
p_NbOfRowsInserted: = SQL % ROWCOUNT;
COMMIT;
END TestArrayIn;
end JWETEST_PK;
/
Then I did as simple testapp as follows:
Protected Int As Integer = 0
Dim arrNums() As Integer = {1, 2, 3}
Dim cmd As New OracleCommand
Dim cnn as new OracleConnection (s_conn)
Try
With cmd
. ArrayBindCount = 3
. Connection = cnn
. CommandText = "JWETEST_PK. TestArrayIn ".
. CommandType = CommandType.StoredProcedure
Var p_Clientnrs As OracleParameter = New OracleParameter
With p_Clientnrs
. ParameterName = "p_CLIENTNRS."
. DbType = DbType.Int32
. CollectionType = OracleCollectionType.PLSQLAssociativeArray
. Value = arrNums
. Size = 3
Ends with
. Parameters.Add (p_Clientnrs)
. Parameters.Add (New OracleParameter ("p_NbOfRowsInserted", OracleDbType.Int32, ParameterDirection.Output))
CNN. Open()
cmd ExecuteNonQuery()).
Int = CInt (.) Parameters ("p_NbOfRowsInserted"). Value)
Ends with
Catch ex As Exception
MsgBox (ex.) Message)
Finally
If (cnn IsNot Nothing) = False Then
CNN. Close()
CNN. Dispose()
End If
End Try
When I run my testapp, the lines are inseterd in the database, but it gives me an error: link table error: ORA-01485Liaison of the table and the associative arrays are two different functions and tend to confuse because they both have the word Array in them.
The table binding is for "run this procedure and statement number X times, all the data here is at the front. ''
Associative array is to "perform this procedure once, here is the table I want to that you pass in.Start by removing ArrayBindCount = 3and see if that helps
If you still have problems, see the example of associative array on your hard disk to %OH%\ODP.NET\samples\2.x\AssocArray
It will be useful,
Greg
Maybe you are looking for
-
disabled dregol Firefox; How can I fix it?
I thought I was downloading a new driver but I dregol.com and now I can't start Firefox. Can I fix or do I have to remove Firefox and download a new copy? Chrome has been affected, but I was able to replace dregol by google.
-
can view is no longer wage that is supported by internet explore what should I change?
From 01/04/2013, the State of TN has converted the paychecks in pdf format and developed internet explorer 7 and 8 of the State standard.Before this change, I was able to view my paycheck. What should I do in Foxfire to allow me again to see my paych
-
after upgrade firefow does not start and reinstall does not help
Last week updated firefox and I can't use it since safe mode does not work, will not work reinstall I get a memory error code, pls help
-
Laptop does not turn on but the power button is on ip
I just bought my HP Pavilion 360 less than a month ago and it's been used for research and schoolwork. No virus or threats have been detected. It was working fine today until I had to load it. When it was fully charged, I turned it on and the screen
-
IntelliPoint says 'no mouse detected Microsoft. "
I just installed a mouse Intellimouse Explorer 4.0. I installed Intellipoint and then connected to the mouse. I use Vista. In Intellipoint on the Hardware tab, it says Microsoft PS2 Mouse, and that the device is functioning properly. However, the tab