Returning collection-associative array from pl-sql procedure
CREATE OR REPLACE procedure test_ganesh( p_deptno IN number,gana out PARTIES_RESULT)
is
query varchar2(200);
PARTY_ID varchar2(200);
PARTY_CODE varchar2(200);
PARTY_NAME varchar2(200);
PARTY_SEQ VARCHAR2(200);
counter number;
TYPE PARTIES IS TABLE OF varchar2(2000) index by binary_integer;
txn_parties PARTIES;
type PARTIES_RESULT IS TABLE OF PARTIES index by binary_integer;
total_result PARTIES_RESULT;
TYPE EmpTyp IS REF CURSOR;
p_du EmpTyp;
p_cursor EmpTyp;
global_counter number;
begin
global_counter:=1;
counter:=1;
open p_cursor FOR
select A.ref_no
from ot_lc_txn_details A
where rownum <12;
LOOP
FETCH p_cursor INTO query;
EXIT WHEN p_cursor%NOTFOUND;
counter:=1;
open p_du FOR
select party_id,party_code,seq_no,party_name from ot_txn_party where ref_no=query;
LOOP
FETCH p_du INTO PARTY_ID,PARTY_CODE,PARTY_SEQ,PARTY_NAME;
EXIT WHEN p_du%NOTFOUND;
txn_parties(counter):=PARTY_ID || '&&&' || PARTY_CODE || '&&&'||PARTY_SEQ || '&&&' || PARTY_NAME;
counter:=counter+1;
END LOOP;
CLOSE p_du;
total_result(global_counter):=txn_parties;
global_counter:=global_counter+1;
END LOOP;
CLOSE p_cursor;
--open gana FOR SELECT * FROM table(cast(total_result as PARTIES_RESULT)) ;
end;
The error comes at line one, PLS-00905- object PARTIES_RESULT is invalid.
i have used the create type thing to create this type.
if i remove the out parameter it works, no compilation error.
Questions i) How to return the associative array as out parameter?
ii)Am i doing aynthing qrong here?
iii) Can i open a ref cursor to this associative array and then return that ref_cursor?
Please anyone reply back, Thanks in advance
Message was edited by:
user649602
As an example:
SQL> create type PARTIES is table of varchar2(2000);
2 /
Type created.
SQL> create or replace procedure proc1(p_deptno number,gana out parties) as
2 begin
3 select ename
4 bulk collect into gana
5 from emp
6 where deptno = p_deptno;
7 end;
8 /
Procedure created.
Similar Messages
-
Returing array from PL/SQL procedure
Hi,
I am trying to return array from PL/SQL procedure. Heres is the code. I am getting an error "OracleParameter.ArrayBindSize is invalid ".
Will anybody let me know what is wrong in following code. or does anybody have code to return PL/SQL array using VB.NET.
oCommand.CommandText = "MyPack.TestVarchar2"
oCommand.CommandType = CommandType.StoredProcedure
Dim id As Integer = 10
Dim deptname As String()
Dim oParam1 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter("id", Oracle.DataAccess.Client.OracleDbType.Int32)
Dim oParam2 As Oracle.DataAccess.Client.OracleParameter = New Oracle.DataAccess.Client.OracleParameter("deptname", Oracle.DataAccess.Client.OracleDbType.Varchar2)
oParam1.Direction = ParameterDirection.Input
oParam2.Direction = ParameterDirection.Output
oParam1.CollectionType = Oracle.DataAccess.Client.OracleCollectionType.None
oParam2.CollectionType = Oracle.DataAccess.Client.OracleCollectionType.PLSQLAssociativeArray
oParam1.Value = id
oParam2.Value = ""
oParam1.Size = 10
oParam2.Size = 20
oCommand.Parameters.Add(oParam1)
oCommand.Parameters.Add(oParam2)
oCommand.ExecuteNonQuery()
Thanks
SameerThanks Arnold for the reply..
Yes, I am trying to get result set in array which is unknow to me (No of rows return by the query). For the test I will pre-define the result set so that I will able to set ArrayBindSize.
I have read C# example but when I try to write it in VB.NET it gives me syntax error when I try to set the ArrayBindSize.
oParam.ArrayBindSize = new int[3]{15,23,13} // individual max size of 3 outputsWill you please let me know how to set ArrayBindSize (VB.NET) because I am new to this..
There is an example at otn "How to: Bind an Array to an ODP.NET Database Command" which does multiple INSERTs in one trip to database. This works fine. I need to do same for the SELECT statement which will return me multiple rows. I do not mean refCursor. If I use refCursor, it will make soft parse which I am trying to avoid using this Array techniq.
Thanks
Sameer -
Sending message from PL/SQL procedure to form
Hello Friends,
How can I send messages from PL/SQL procedure to Form ?
Ultimate target is catching progress of PL/SQL procedure from
form. I heard about DBMS_PIPe but not sure,.
AdiHello,
Yeah , I got the solution using DBMS_PIPE function,I
followed following steps.
1. Pipe is created. see below procedure.
create or replace procedure proc_testpipe as
v_pipe_integer integer;
v_pipe_message integer;
begin
v_pipe_integer := DBMS_PIPE.Create_Pipe('adipipe');
dbms_pipe.pack_message('Hello Adinath Kamode,Message
from Pipe');
v_pipe_message := dbms_Pipe.Send_message('adipipe');
end;
end;
2. then I created one Function which will obtain message from
Pipe and
will return value to form.
create or replace function proc_callpipe return varchar2 as
v_msg integer;
v_rem integer;
v_message varchar2(500);
begin
v_msg:=dbms_pipe.receive_message('adipipe');
dbms_pipe.unpack_message(v_message);
dbms_pipe.purge('adipipe');
v_rem := dbms_pipe.remove_pipe('adipipe');
return(v_message);
end;
3. Last I called this function from form.
Cheers .. !
Adi -
Run report from PL/sql procedure
Please any one tell how to I run a report from pl/sql procedure.
I am not sure, but depending on your environment you can create a script to run your PL/SQL code and then generate the report. As is customary in an UNIX environment utilizing shell scripts.
-
Creating web service from pl/sql procedure
Hello.
I need to create a web service from pl/sql procedure and i chose JDeveloper for this implementation. I have wsdl, but I never created web services. So, I created web service with document/literal message format.
But I have several troubles:
1. All element names have lower case letters.
2. The SOAP envelope must begin from words soapenv:Envelope but i have soap:Envelope.
3. And operation name has tail like "Element".
I know bad way for implement 1 and 3 points. It's a modification of java_wsdl_mapping.xml and wsdl files. But if I want to add new method to my service all changes will be cleaned. It's not critical but inconvenient to support.
But for point 3 i have no ideas.
This task is very important for me. Can somebody help me?
JDeveloper 10.1.3.3
Regards,
Alekseyhttp://www.oracle.com/technology/obe/obe1013jdev/10131/wsfromplsqlpackage/devwsfrom%20plsql.htm
Frank -
How to call javascript function from PL/SQL procedure
Can anybody advice me how to call javascript function from PL/SQL procedure in APEX?
Hi,
I have a requirement to call Javascript function inside a After Submit Process.
clear requirement below:
1. User selects set of check boxes [ say user want to save 10 files and ticks 10 checkboxes]
2. user clicks on "save files" button
3. Inside a After submit process, in a loop, i want to call a javascript function for each of the file user want to save with the filename as a parameter.
Hope this clarify U.
Krishna. -
Unix shell script run from pl/sql procedure
Hi Guru
I want to run unix shell script from pl/sql procedure. Actual I want to run it from developer 10g form.
Please guide me in this regards
Regards
JewelLook at the host or client_host builtins in the help
-
How do I return a Boolean array from LabView to TestStand?
I am trying to return a Boolean array from Labview to TestStand and have TS evaluate the results. I can do this for arrays of integers or reals but booleans do not work. I tried copying the PassFailTest step type and adding an array of Bool but I couldn't get it to evaluate the array. It simply always passed. How can this be done?
Bob A.I have thought about evaluating the Boolean data in TestStand but, as you say, this is a lot of work. What I have been doing is to map the boolean data to integers in LV (very easy) and then use the multiple numeric step type to evaluate the integer array automatically. This feels kludgy and I have tried a couple of times to create a "multiple boolean" step type with little success. I'm surprised TS hasn't anticipated a test returning multiple pass/fail results. I do this all the time for production code.
What I have tried is to copy MultipleNumericLimitsTest data type to a custom type and add a BooleanArray with a data type Array of Boolean[0..empty]. Then when I specify module, I select Step.BooleanArray as the value. The last step (that I know of) is to select Step.BooleanArray as the data source in the edit limits window. At this point if I run the test, I get the error "expect numeric, found boolean" (or something similar). When I look at the properties of my custom step type, the Substeps has DoMultiNumericMeasEvaluation as the Post-Step. I believe this is the root of my problem but I can't figure out how to change this to "DoMultiBooleanMeasEvaluation" or similar. Any Ideas? -
Creating Excel Workbook from PL/SQL Procedure
I am trying to create Excel Workbook with two worksheets from PL/SQL procedure. I created one worksheet. Can I create a separate sheet from same procedure. I used OWA_UTIL.MIME_HEADER ('application/vnd.ms-excel', FALSE)
command to create the spreadsheet.
Any help would be helpful.
Thanks
Yagna ShahFurther to my previous post here is how I will develop a typical master details excel report.
by using the package,
It will also show sum of salary at each department.
Note : When I paste the code here I loose the indentation. So the code below is not indented properly.
DECLARE
r NUMBER := 0 ; --- r IS the ROW NUMBER IN this excel file
l_sum NUMBER ;
BEGIN
--- Generate the styles that we need
gen_xl_xml.create_excel( 'UTL_DIR','master_Detail.xls') ;
gen_xl_xml.create_style( 'dept_title' , 'Arial', 'Red',14, p_backcolor => 'LightGray' );
gen_xl_xml.create_style( 'sgs2' , 'Arial', NULL ,10, p_bold => TRUE );
gen_xl_xml.create_style( 'sgs3' , 'Arial', 'blue',14 );
gen_xl_xml.create_style( 'sgs4' , 'Arial', 'green',14 );
gen_xl_xml.create_style( 'emp_title' , 'Arial', 'Black',9, p_backcolor => 'LightBlue' );
gen_xl_xml.create_style( 'sal_tot' , 'Arial', 'Brown',13, p_backcolor => 'Yellow' );
-- SET ANY COLUMN AND ROW changes
gen_xl_xml.set_column_width( 3, 145 );
gen_xl_xml.set_column_width( 4, 145 );
l_sum := 0 ;
FOR recd IN ( SELECT department_id, department_name FROM departments ) LOOP
IF l_sum <> 0 THEN
r := r +1 ;
gen_xl_xml.write_cell_char( r, 4, 'Department Total ->' , 'sal_tot' );
gen_xl_xml.write_cell_num( r, 5, l_sum , 'sal_tot' );
l_sum := 0;
END if ;
r := r+1 ;
gen_xl_xml.write_cell_CHAR( r,1, 'Department : '|| recd.department_name , 'dept_title' );
-- As we need same style applied till the above data flows use write_cell_null
gen_xl_xml.write_cell_NULL( r,2 , null );
gen_xl_xml.write_cell_NULL( r,3, 'dept_title' );
gen_xl_xml.write_cell_NULL( r,4, 'dept_title' );
gen_xl_xml.write_cell_NULL( r,5, 'dept_title' );
--- Add employee heading
r := r+1 ;
gen_xl_xml.write_cell_CHAR( r,2, 'EmployeeID' , 'emp_title' );
gen_xl_xml.write_cell_CHAR( r,3, 'First Name' , 'emp_title' );
gen_xl_xml.write_cell_CHAR( r,4, 'Last Name' , 'emp_title' );
gen_xl_xml.write_cell_CHAR( r,5, 'Salary' , 'emp_title' );
FOR rec IN (SELECT employee_id , first_name , last_name, salary FROM employees WHERE department_id = recd.department_id ) LOOP
r := r+1 ;
gen_xl_xml.write_cell_num( r,2, rec.employee_id, 'sgs2' );
gen_xl_xml.write_cell_char( r,3, rec.first_name, 'sgs3' );
gen_xl_xml.write_cell_char( r,4, rec.last_name , 'sgs4' );
gen_xl_xml.write_cell_num( r,5, rec.salary );
l_sum := l_sum + rec.salary ;
END LOOP ;
END LOOP ;
gen_xl_xml.close_file ;
END ;
----------------------------------------------------------------------------------------------------------------- -
Sending OS command from PL/SQL procedure
"How can I send a operating system comand from PL/SQL procedure?
I want to move , to copy , delete a file from a PL/sql procedure. i.e under unix send mv, cp or
rm command";
my e-mail is [email protected]take a look at
http://asktom.oracle.com/pls/ask/f?p=4950:8:881946
regards
Freek D'Hooge
"How can I send a operating system comand from PL/SQL procedure?
I want to move , to copy , delete a file from a PL/sql procedure. i.e under unix send mv, cp or
rm command";
my e-mail is [email protected] -
Returning 2D array from a stored procedure
hi,
i'm trying to return a nested table from a procedure.can any one help me out i'm getting the fallowing error.
SQL> ed
Wrote file afiedt.buf
1 declare
2 TYPE data_t IS TABLE OF NUMBER
3 INDEX BY PLS_INTEGER;
4 TYPE array_t IS TABLE OF data_t
5 INDEX BY PLS_INTEGER;
6 array array_t;
7 begin
8 Sp_test(123,'12-jan-08',array);
9 dbms_output.put_line(array (10) (1));
10* end;
11 /
Sp_test(123,'12-jan-08',array);
ERROR at line 8:
ORA-06550: line 8, column 1:
PLS-00306: wrong number or types of arguments in call to
'SP_TEST
ORA-06550: line 8, column 1:
PL/SQL: Statement ignored
The procedure is
CREATE OR REPLACE PROCEDURE Sp_test(S_KEY NUMBER,V_DATE DATE, array_out OUT array_t) as....Below is the error i got when using the above suggestion.
SQL> ED
Wrote file afiedt.buf
1 DECLARE
2 TYPE data_t IS TABLE OF NUMBER
3 INDEX BY PLS_INTEGER;
4 TYPE array_t IS TABLE OF data_t
5 INDEX BY PLS_INTEGER;
6 begin
7 Sp_test(123,'12-jan-08',array REPORT.ARRAY_T);
8 dbms_output.put_line(array (10) (1));
9* end;
10 /
Sp_test(123,'12-jan-08',array REPORT.ARRAY_T);
ERROR at line 7:
ORA-06550: line 7, column 32:
PLS-00103: Encountered the symbol "REPORT" when expecting one of the
following:
. ( ) , * @ % & | = - + < / > at in is mod not range rem =>
.. <an exponent (**)> <> or != or ~= >= <= <> and or like
between ||
The symbol "." was substituted for "REPORT" to continue. -
Returning result sets from PL/SQL procedure to client app.
I was wondering if its possible in Oracle PL/SQL to DECLARE, OPEN a cursor and exit
the procedure without closing the cursor
and then retrieve the resultset from
the client.
Pl let me know..
nullYes, you need to use one OUT parameter in your PL/SQL procedure
to pass the cursor variable to
Java code. You can also return that as a return variable of
PL/SQL function. Get the cursor variable from the resultset using
Types.CURSOR data type and then proceed as usual.
Enrique (guest) wrote:
: Thank you Rajib for your prompt reply. I have been programming
a
: lot in Transact SQL( MSSQL ), but I am new to Oracle and I need
: to migrate MSSQL procedures to Oracle. I will try to use the
: refCursors. One more question, how do I pass the cursors back?
: With OUT parameters? In MSSQL you do not need to specify OUT
: parameters if you are returning a result set.
: Once Again,
: Thank you
: Rajib (guest) wrote:
: : You can return a variable of refcursor type from your PL/SQL
: : procedure (PL/SQL 2.3 or higher) to Java code. Oracle JDBC
has
: a
: : refcursor data type. Now you can use this cursor as a
: resultset.
: : Enrique (guest) wrote:
: : : Hi All,
: : : I am trying to write some store procedures( PL/SQL )
: : that
: : : will select rows from my tables, and then pass then back to
: my
: : : JDBC application as result sets....Does anyone know how can
I
: : do
: : : that? Do I need to use output parameters? Or Return
: functions?
: : : Any help or hint wourl be be gladly appreciate it.
: : : Enrique
: : : Thank you.
null -
Associative Array problem in Oracle Procedure
Hi,
I've searched through the internet and this forum and haven't been able to resolve a problem using associative array values within an IN clause. Everything I've read states that I can't 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'm receiving an "ORA-21700: object does not exist or is marked for delete" error when trying to access the table I've populated from the array. Please note that I have verified the table is actually being populated during the loop. I'm catching the error when referencing it in the SELECT statement.
I've declared the following in the ARCHIVE package specification:
TYPE RSType IS REF CURSOR;
TYPE integer_aat IS TABLE OF INTEGER INDEX BY PLS_INTEGER;
TYPE integer_table IS TABLE OF INTEGER;
The procedure is as follows:
PROCEDURE SEL_SEARCH_RESULTS (v_term IN VARCHAR2,
v_categories IN ARCHIVE.integer_aat,
rs OUT RSType)
AS
/* PURPOSE: Return Search Results for the Category and Keyword Provided
VARIABLES:
v_categories = Document Categories array
v_term = Keyword entered
rs = Result Set
tbl_cat ARCHIVE.integer_table := ARCHIVE.integer_table();
BEGIN
FOR i IN 1 .. v_categories.COUNT
LOOP
tbl_cat.EXTEND(1);
tbl_cat(i) := v_categories(i);
END LOOP;
OPEN rs FOR
SELECT A.ID,
B.CATEGORY,
A.FILENAME,
A.DISPLAY_NAME,
A.COMMENTS
FROM TBL_ARCHIVE_DOCUMENTS A,
TBL_ARCHIVE_DOC_CAT B,
TBL_ARCHIVE_DOC_KEYWORDS C
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,
MattThank you for the quick response. I looked at the example you suggested and made the following changes. Now I'm receiving an "Invalid datatype" error on the "SELECT column_value FROM TABLE(CAST(tbl_cat AS tbl_integer))" statement. I must be missing something simple and I just can't put my finger on it.
PROCEDURE SEL_SEARCH_RESULTS (v_term IN VARCHAR2,
v_categories IN ARCHIVE.integer_aat,
rs OUT RSType)
AS
/* PURPOSE: Return Search Results for the Category and Keyword Provided
VARIABLES:
v_categories = Document Categories array entered
v_term = Keyword entered
rs = Result Set
TYPE tbl_integer IS TABLE OF INTEGER;
tbl_cat tbl_integer;
BEGIN
FOR i IN 1 .. v_categories.COUNT
LOOP
tbl_cat.EXTEND(1);
tbl_cat(i) := v_categories(i);
END LOOP;
OPEN rs FOR
SELECT A.ID,
B.CATEGORY,
A.FILENAME,
A.DISPLAY_NAME,
A.COMMENTS
FROM TBL_ARCHIVE_DOCUMENTS A,
TBL_ARCHIVE_DOC_CAT B,
TBL_ARCHIVE_DOC_KEYWORDS C
WHERE A.ID = B.ID
AND A.ID = C.ID
AND B.CATEGORY IN (SELECT column_value FROM TABLE(CAST(tbl_cat AS tbl_integer)))
AND C.KEYWORD = v_term
ORDER BY A.ID;
END SEL_SEARCH_RESULTS; -
Passing array to pl/sql procedure - pls-00306 wrong number/types of args
its oracle 10.2 database;
I have a procedure with array parameters based on simple sql types.
eg
create or replace type vt_attrname is table of varchar2(50);
Now my call to the procedure works when the array is empty;
as soon as I bulk collect into my local array, I get a compilation error.
eg
declare
my_array vt_attrname;
begin
select label
bulk collect
into my_array
from table_name
where 1=1;
my_proc(p_array=>my_array); -- syntax error
end;if I pass null the call works but obviously array is empty.
I have read something about varray's being incompatible between sqltypes and pl/sql.
How do I get around this problem?
The bulk collect is working okay.
A small example would be appreciated.Yep, I spotted the syntax error earlier.
However even though that seems to compile ok, I still get the problem with my package call.
heres the actual call from the code
vt_attrname and vt_attrvalues are types declared on another schema.
I have redeclared them on the current schema now.
create or replace type vt_attrname is table of varchar2(50);
create or replace type vt_attrvalue is table of varchar2(500);
create procedure <name>
as
v_cardapplattrtag vt_attrname;
v_cardapplattrvalue vt_attrvalue;
for cardappl_cur in
(select cardappl_id
from ci_cardappl
where custcard_id = cur.document_logical_number)
loop
select label
bulk collect
into v_cardapplattrtag
from ci_applver_attribute
where applver_id = v_applver_id;
v_array_size := v_cardapplattrtag.count;
-- populate this array
-- ppt_cardapplattrtag comes from ci_pplver_attribute
--ppt_cardapplattrvalue -- various
cci_setcardappl.SetCardApplAttrValue(
pn_cardappl_id => cardappl_cur.cardappl_id,
ppt_cardapplattrtag => v_cardapplattrtag, -- works when null
ppt_cardapplattrvalue => NULL,
pn_cardapplattrsize => v_array_size,
pv_arn => cur.application_request_id,
pv_commit => 'FALSE');and the procedure protototype is
PROCEDURE SetCardApplAttrValue(
pn_cardappl_id IN NUMBER,
ppt_cardapplattrtag IN VT_BPATTRNAME DEFAULT NULL,
ppt_cardapplattrvalue IN VT_BPATTRVALUE DEFAULT NULL,
pn_cardapplattrsize IN NUMBER,
pv_arn IN VARCHAR2,
pv_commit IN VARCHAR2 DEFAULT 'FALSE');Edited by: Keith Jamieson on Sep 23, 2009 10:42 AM -
Find a element in a collection (associative array)
I am wondering is there any way that I can look for an item in an array when the subscript is not part of a key of a table.I mean if in a employee table I can fill the array with employee info if the subscript say employee id is numeric.
employee(emp_rec.emp_id) := emp_rec;
and then while searching I can search by emp_id ,,,,but what if emp_id is character then do you guys have any ideas on how to assign a subscript which will make the search easier .
thanks
Manohar.With associative arrays indexed by a string (in your case, employee name), you can just use the EXISTS method. Much faster than looping through looking for a match.
sql>declare
2 type arr is table of emp.ename%type index by emp.ename%type;
3 v_arr arr;
4 v_name emp.ename%type;
5 begin
6 for r in (select ename from emp) loop
7 v_arr(r.ename) := null;
8 end loop;
9 v_name := 'KING';
10 if v_arr.exists(v_name) then
11 dbms_output.put_line(v_name || ' exists');
12 else
13 dbms_output.put_line(v_name || ' does not exist');
14 end if;
15 v_name := 'SHETTY';
16 if v_arr.exists(v_name) then
17 dbms_output.put_line(v_name || ' exists');
18 else
19 dbms_output.put_line(v_name || ' does not exist');
20 end if;
21 end;
22 /
KING exists
SHETTY does not exist
PL/SQL procedure successfully completed.
Maybe you are looking for
-
Illustrator CS4 in Snow Leopard Issues
I have a logo file that I created in Illustrator CS4 on an iMac running Snow Leopard and it does not display some of the text layers when saving for the web or saving as an Illustrator CS3 file or copying and pasting into Photoshop CS4. Basically the
-
Lightroom 4 - Open Smart Object in Photoshop (or rather do not!)
Opening a PV2012 image as a smart object into Photoshop works ... except that all Lightroom adjustments are ignored. No doubt this will be fixed when Adobe releases Photoshop CS6 and ACR 7.0 ... but that the latest version of Lightroom does not work
-
I purchased an I book for the first time and now I can not find it. I thought it would bean icon on my apps page. Where did it go"?
-
Need to Modify Existing Hierarchy
Hi Experts, Problem: There are two hierarchies, one from CRM system and another from ECC system. Both the hierarchies show same data. however ECC hierarchy is having one more detail level then CRM hierarchy.CRM hierarchy is having 4(continent, subcon
-
hi..... Can we do provide constructor in an applet for initialization or can applet support constructor? regards.