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
Tags: Database
Similar Questions
-
the associative arrays containing the record type, cannot be used first
I am having trouble with the declaration of an associative array containing the Types of records and iteration using FIRST and NEXT functions.
This problem of mine is only appear when I use that types of records, the FIRST and FOLLOWING operators work very well when you use the regular NUMBER.
Trying to get the first element of the array, I get: ORA-06550: line 22, column 40: PLS 00382: expression is of the wrong type
See the code snippet below. Anyone know if this can be done in PL/SQL?
-----------------------------------------------------------------------------------------
DECLARE
-Set the record structure that will contain information on a post
TYPE PostRec IS (RECORD
post_type VARCHAR2 (4) - maybe DEB/CRED
);
lr_charge_back_post PostRec;
TYPE post_table IS TABLE OF PostRec NOT NULL
INDEX BY VARCHAR2 (4);
assoc_posts post_table;
BEGIN
-lr_charge_back_post.post_type: = "asd";
assoc_posts('1').post_type: = '1';
lr_charge_back_post: = assoc_posts.first;
END;
/Returns the index, not the file FIRST:
SQL> declare 2 TYPE PostRec IS RECORD ( 3 post_type VARCHAR2(4) -- Can be DEB/CRED 4 ); 5 6 lr_charge_back_post varchar2(20); 7 TYPE post_table IS TABLE OF PostRec NOT NULL 8 INDEX BY VARCHAR2(4); 9 10 11 assoc_posts post_table; 12 13 BEGIN 14 15 16 --lr_charge_back_post.post_type := 'asd'; 17 assoc_posts('1').post_type := '1'; 18 19 lr_charge_back_post := assoc_posts.first; 20 dbms_output.put_line('idx='||lr_charge_back_post); 21 END; 22 / idx=1 PL/SQL procedure successfully completed. SQL> declare 2 TYPE PostRec IS RECORD ( 3 post_type VARCHAR2(4) -- Can be DEB/CRED 4 ); 5 6 lr_charge_back_post varchar2(20); 7 TYPE post_table IS TABLE OF PostRec NOT NULL 8 INDEX BY VARCHAR2(4); 9 10 11 assoc_posts post_table; 12 13 BEGIN 14 15 16 --lr_charge_back_post.post_type := 'asd'; 17 assoc_posts('idx').post_type := '1'; 18 lr_charge_back_post := assoc_posts.first; 19 dbms_output.put_line('idx='||lr_charge_back_post); 20 END; 21 / idx=idx PL/SQL procedure successfully completed.
Max
http://oracleitalia.WordPress.com -
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
-
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:
-
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. ;)
-
Associative arrays... items in the index
I can control the index of an associative array like that...
How can I control the index in the statement of collection in bulk as follows... so that I can delete records using this indexTYPE aat_id IS TABLE OF PLS_INTEGER INDEX BY PLS_INTEGER; aa_ids aat_id; BEGIN aa_ids(1) := 3; aa_ids(2) := 8; aa_ids(2) := 10; aa_ids.delete(2); dbms_output.put_line(aa_ids.count); END;
Thank youSELECT decode(mod(rownum,2),1,1,2), object_name BULK COLLECT INTO aa_recs FROM all_objects WHERE ROWNUM <= 6;
HESH.HESH wrote:
but I have to play with the collected values, I want to delete the values in bulk without a loop through the list there at - it a trick possible to do this?
Using not PL/SQL and bays of PL/SQL at all - just using simple native SQL.
Before bulk collection and construction of an associative array, for the use of the values in table for future SQL operations, I rather to store the collection of values in a TWG (global temporary table) instead. A TWG can be indexed - and can thus provide much better access to the data as an associative array. He played better. It can be used via SQL, native mode.
The best place for the data is in the database. Not in the PL/SQL layer. This means that in SQL tables and not in PL/SQL tables or collections.
There are very few situations in PL/SQL, which require the use of associative arrays. If few, the majority of the PL/SQL code using associative arrays, IMO do badly. And what you've posted so far, I do not see a specific requirement for associative arrays.
So be sure you use the correct feature - and make sure that it is also well put to use in your code.
PS. HESH is a strange name. I'm used to HESH meaning High Explosive Squash Head (used for the filming of shielding). :-)
-
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 -
How to: compare 2 associative arrays element-by-element
After playing, I decided to go with the approach of the two sets of data of their own associative array. The code and the results of this are below. My question is the comparison. For each element within the matrix of order, check all the items in the details table to see if there's a football game. If there is a match > > > move to the next item in the control panel and check all the items in the details table to see if there is a football game. Go until the whole is considered to be a match (in number of rows and values). If no match, take the exit.
Below, you'll see my logic to get both sets of data into their respective tables. The results with a note attached to one of the elements is also pasted here (hereinafter the code).
DECLARE
TYPE details_t () IS RENDERING
SIDE AUTO_RECIPE_DETAILS. SIDE % TYPE.
REF_DES AUTO_RECIPE_DETAILS. REF_DES % TYPE,
PART_NUM AUTO_RECIPE_DETAILS. PART_NUM % TYPE
);
TYPE details_type IS TABLE OF details_t INDEX OF AUTO_RECIPE_DETAILS. PART_NUM % TYPE;
details_recipe details_type;
pid_recipe details_type;
compare_result details_type;
CURSOR details_cur
IS
SELECT A FACE, REF_DES, PART_NUM
OF AUTO_RECIPE_DETAILS
WHERE RECIPE_NAME =' 40617-000001;
CURSOR pid_cur
IS
SELECT cl. SIDE, lacpa. REF_DES, NVL(oecl.COMPONENT_ID, 'NOT APPLIED') AS PART_NUM
OF ORDER_ERP_COMPS_LIST lacpa
RIGHT OUTER JOIN CAD_LOCS cl
ON cl. REF_DES = LACPA. REF_DES
WHERE lacpa. ORDER_NUM = "PSY142420."
AND CL. FAB = '38112';
counter_d number (10): = 0;
counter_p number (10): = 0;
comp_counter number (10): = 0;
BEGIN
FOR rec IN details_cur
LOOP
counter_d: = counter_d + 1;
details_recipe (counter_d). SIDE: = rec. SIDE;
details_recipe (counter_d). REF_DES: = rec. REF_DES;
details_recipe (counter_d). PART_NUM: = rec. PART_NUM;
END LOOP;
FOR rec IN pid_cur
LOOP
counter_p: = counter_p + 1;
pid_recipe (counter_p). SIDE: = rec. SIDE;
pid_recipe (counter_p). REF_DES: = rec. REF_DES;
pid_recipe (counter_p). PART_NUM: = rec. PART_NUM;
END LOOP;
-for each pid_recipe element, double-check each record in details_recipe to see if there is an item matching (record)...
FOR indx_d IN details_recipe. FIRST... details_recipe. LAST
LOOP
DBMS_OUTPUT. Put_line (details_recipe (indx_d). SIDE | ', ' || details_recipe (indx_d). REF_DES | ', ' || details_recipe (indx_d). PART_NUM);
END LOOP;
DBMS_OUTPUT. PUT_LINE ('IN THE SECOND PART OF IT!');
FOR indx_p IN pid_recipe. FIRST... pid_recipe. LAST
LOOP
DBMS_OUTPUT. Put_line (pid_recipe (indx_p). SIDE | ', ' || pid_recipe (indx_p). REF_DES | ', ' || pid_recipe (indx_p). PART_NUM);
END LOOP;
END;
/
RESULT:
DETAILS TABLE
RECIPE FOR THE DETAILS TABLE:
B, R28, 34315-26R7
B, R38, 34315-4990
B, R40, 34152-1R60
B, R45, 34315-1002
B, R46, 34315-3011
B, R48, 34152-1004
B, R55, 34315-5901
B, R64, NOT APPLIED
B, R77, 34315-4992
CONTROL PANEL
THE RECIPE IS CALCULATED IN THE ORDER ITSELF:
B, C01, 39412-334 / / for that one single item-> check all the items from the table (above) details Table and see if an element matches. Move to the next item if there is a match...
B, C02, 39412-334
B, C03, NOT APPLIED
T, C11, 27249-105
T, C13, 35404-104
T, C14, 27531-224
T, C15, 35404-104
T, C18, 27249-105
T, C19, 27531-224
CHANGED:
THIS... is the solution to my original question. I had a little mistake that I set between this and my last post with this code. Just in case a person who could use an example like that falls on this thread.
FOR index_p IN pid_recipe. FIRST... pid_recipe. LAST
LOOP
Result WHEN the OUTPUT = 1;
FOR index_d IN details_recipe. FIRST... details_recipe. LAST
LOOP
IF (pid_recipe (index_p). SIDE = details_recipe (index_d). SIDE)
AND (pid_recipe (index_p). REF_DES = details_recipe (index_d). REF_DES)
AND (pid_recipe (index_p). PART_NUM = details_recipe (index_d). PART_NUM)
THEN
EXIT;
ON THE OTHER
DBMS_OUTPUT. Put_line("IT WAS NOT a MATCH");
result: = 1;
EXIT;
END IF;
END LOOP;
END LOOP;
DBMS_OUTPUT. Put_line('LOOP OUT');
-
Using associative arrays in query
Hi all
Please see my schedule. It works very well
[CODE]
DECLARE
type mechanics_type_tab is table of index varchar2 (15) by varchar2 (15);
l_mechanics_type mechanics_type_tab;
L_BULLETIN t_tfo_wf_varchar_table:=t_tfo_wf_varchar_table();
l_count pls_integer: = 0;
BEGIN
FOR I IN (select bulletin_id, mechancs_type_id
of TFO_BULLETIN_PROMO_MECHANICS
where mechancs_type_id is not null) LOOP
l_count: = l_count + 1;
l_mechanics_type (i.bulletin_id): = i.mechancs_type_id;
l_mechanics_type (i.mechancs_type_id): = i.mechancs_type_id;
L_BULLETIN.extend;
L_BULLETIN (l_count): = i.bulletin_id;
END LOOP;
FOR J IN (SELECT TABLE COLUMN_VALUE (L_BULLETIN)) LOOP - this will change
DBMS_OUTPUT. Put_line ('COLUMN_VALUE =' | l_mechanics_type (J.COLUMN_VALUE));
END LOOP;
/ * does not
Insert into test_table (test1)
SELECT values l_mechanics_type (COLUMN_VALUE) OF TABLE (L_BULLETIN); */
END;
[/ CODE]
instead of the code below:
FOR J IN (SELECT TABLE COLUMN_VALUE (L_BULLETIN)) LOOP - this will change
DBMS_OUTPUT. Put_line ('COLUMN_VALUE =' | l_mechanics_type (J.COLUMN_VALUE));
END LOOP;
When I did as below
[CODE]
insert into test_table (test1) to
SELECT values l_mechanics_type (COLUMN_VALUE) OF TABLE (L_BULLETIN);
[/ CODE]
It does not work. Why it does not work.
Please note that in the real-world scenario, there are several fields to insert for test_table and test1 is one of them.
Just because the associative arrays are not supported in SQL before ORACLE 12 c.
HTH
-
I have a table proj_test .i want to recover the data in the associative array.
How to do?
create table proj_test as select 1 as id, 1 as rn, 'Fred' as nm from dual union all select 1,2,'Bloggs' from dual union all select 2,1,'Scott' from dual union all select 2,2,'Smith' from dual union all select 3,1,'Jim' from dual union all select 3,2,'Jones' from dual
You need not Associative array if you do a bulk of collect. You can use the nested PL/SQL table type.
11g and more
declare
is of type tbl table of the proj_test % rowtype;
tbl l_tbl;
Start
SELECT id, rn, nm bulk collect into l_tbl
of proj_test;
because me in 1.l_tbl.count
loop
dbms_output.put_line
(
RPAD (to_char (l_tbl (i) USER.USER), 10, ' ')
|| RPAD (to_char (l_tbl (i). (RN), 10, ' ')
|| l_tbl (i) .nm
);
end loop;
end;
Before 11 g
declare
type id_tbl is table of the proj_test.id%type;
type rn_tbl is table of the proj_test.rn%type;
type nm_tbl is table of the proj_test.nm%type;
id_tbl l_id;
l_rn rn_tbl;
l_nm nm_tbl;
Start
SELECT id, rn, nm bulk collect into l_id, l_rn, l_nm
of proj_test;
because me in 1.l_id.count
loop
dbms_output.put_line
(
RPAD (to_char (l_id (i)), 10, ' ')
|| RPAD (to_char (l_rn (i)), 10, ' ')
|| l_nm (i)
);
end loop;
end;
-
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
-
An associative array, how the records using the loop counter?
In the associative array, how the records using the loop counter? for example
declare type population is table of number index by varchar2(64); city_population population; begin city_population('Samillve') := 200; city_population('Lindenhurst') := 300; for i in 1 .. city_population.count loop dbms_output.put_line(city_population(i)); -- compiler error end loop; end; /
That would look like
SQL> ed Wrote file afiedt.buf 1 declare 2 type population is table of number index by varchar2(64); 3 city_population population; 4 l_index varchar2(64); 5 begin 6 city_population('Samillve') := 200; 7 city_population('Lindenhurst') := 300; 8 l_index := city_population.first; 9 while( l_index IS NOT NULL ) 10 loop 11 dbms_output.put_line(city_population(l_index )); 12 l_index := city_population.next(l_index); 13 end loop; 14* end; SQL> / 300 200 PL/SQL procedure successfully completed.
Justin
-
Associative array of index files by varchar2 - PLS 00382
I have a SQL anonymous block that creates a report. At the end of each section, I need to summarize the data by "renting". The list of locations is finished (approx. 15 in a table) and not all sections will have data for each location, but I want the locations to order the same so I thought I'd use an associative array to store summary data. But when I try to initialize the associative array (I simply put the slots in the array in the "correct" order) I receive PLS-00382 expression is of the wrong type.
Here is the code (the lines where the error occurs are in bold):
TYPE summary_data () IS RENDERING
Summary1 NUMBER,
NUMBER of summary2
NUMBER of summary3
);
Summ_arr TYPE IS TABLE of summary_data INDEX OF VARCHAR2 (5);
location_summary summ_arr;
aLoc VARCHAR2 (5);
PROCEDURE init_summ (aSummArr IN OUT summ_arr) IS
BEGIN
aSummArr.Delete;
BEGIN
FOR in aLoc (select name - name is VARCHAR2 (5))
table
control key)
LOOP
aSummArr (aLoc) .summary_1: = 0;
aSummArr (aLoc) .summary_2: = 0;
aSummArr (aLoc) .summary_3: = 0;
END LOOP;
EXCEPTION
-exception handling
END;
END;
If this is not allowed, or I do something wrong? I tried substituting:
Summ_arr TYPE IS TABLE of summary_data INDEX OF VARCHAR2 (5);
with
Summ_arr TYPE IS TABLE of summary_data INDEX table.key%TYPE;
Nothing helps.
Thanks in advance for your help with this.
ANNUAL GENERAL MEETINGALOC is a record variable. You need to refrence the column in the file said. So, something like this:
aSummArr(aLoc.name).summary_1 := 0;
Cheers, APC
-
What is the difference between associative arrays and nested tables?
Hello
What is the difference between associative arrays and nested tables?
nested tables cannot be indexed by other than pls_integer and unlike nested tables table associative cananot be declared at the schema level.
is there any other difference set apart from the diff above 2?user13710379 wrote:
What is the difference between associative arrays and nested tables?Name-value pairs (associative) against a list of values (table standard/nested table).
nested tables cannot be indexed by other than pls_integer
They are not "indexed" the way in which an associative array is indexed. A standard table is referenced by the position of the cell in the table. This position is essentially the offset of the memory of the cell from the start address of the table.
Can not solve a cell in an associative array directly via a memory offset index. You place a cell reference value it by his 'name' (a search in the linked list/hash table).
The following example shows the difference between the pairs of name / value and a list of core values.
SQL> declare 2 --// associative arrays are NAME-VALUE pairs 3 type TArr1 is table of varchar2(10) index by pls_integer; 4 type TArr2 is table of varchar2(10) index by varchar2(10); 5 6 arr1 TArr1; 7 arr2 TArr2; 8 begin 9 arr1(100) := '1st entry'; 10 arr1(1) := '2nd entry'; 11 arr1(5) := '3rd entry'; 12 13 arr2('john') := 'New York'; 14 arr2('jane') := 'Paris'; 15 arr2('jack') := 'London'; 16 17 end; 18 / PL/SQL procedure successfully completed. SQL> SQL> SQL> declare 2 --// standard arrays are lists 3 type TArr3 is table of varchar2(10); 4 type TArr4 is table of number; 5 6 arr3 TArr3; 7 arr4 TArr4; 8 begin 9 arr3 := new TArr3( '1st entry', '2nd entry', '3rd entry' ); 10 11 arr4 := new TArr4( 100, 1, 5 ); 12 end; 13 / PL/SQL procedure successfully completed. SQL>
Maybe you are looking for
-
How to lower flow of songs on iTunes12
Back in my days, I know that we had this option when I tried to transfer music in my iPhone, but there are still? If Yes, where can I find this option? If not, is there anyone know why they removed? Thank you. iTunes 12.3.3.17 iPhone5s 9.3.1
-
Mail filter unwanted Outlook 2003 (KB2596972) guard trying and do not install
I am running Windows XP with Service Pack 3 on a Compaq laptop I replaced Outlook 2003 with Outlook 2007 as part of an Office upgrade My update, history shows that the update for the junk e-mail in Microsoft Office Outlook 2003 (KB2596972) filter did
-
Windows 7 starter OEM product key
Hi guys, someone out there would be able to give me a windows 7 starter (oem) iso I need, microsoft said that they got rid of all the Please HELP
-
Amplified BB Q10 Q10 blackBerry screen
Please note that by mistake, I opted for the screen enlarger... I would like to re - put it... Please guide me as I can't watch most of the icons because of this... Thank you Karim
-
Backup server AnyConnect when Session limit reach
Hello I did the usual search engine and forum crawl looking for the answer, but can't find anything definitive. Is it possible for AnyConnect use the backup server defined in the connection profile when the session limit is reached on a SAA? Basical