Discussions
Categories
- 385.5K All Categories
- 4.9K Data
- 2.5K Big Data Appliance
- 2.4K Data Science
- 453.4K Databases
- 223.2K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 47 Multilingual Engine
- 606 MySQL Community Space
- 486 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.2K ORDS, SODA & JSON in the Database
- 585 SQLcl
- 4K SQL Developer Data Modeler
- 188K SQL & PL/SQL
- 21.5K SQL Developer
- 46 Data Integration
- 46 GoldenGate
- 298.4K Development
- 4 Application Development
- 20 Developer Projects
- 166 Programming Languages
- 295K Development Tools
- 150 DevOps
- 3.1K QA/Testing
- 646.7K Java
- 37 Java Learning Subscription
- 37.1K Database Connectivity
- 201 Java Community Process
- 108 Java 25
- 22.2K Java APIs
- 138.3K Java Development Tools
- 165.4K Java EE (Java Enterprise Edition)
- 22 Java Essentials
- 176 Java 8 Questions
- 86K Java Programming
- 82 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 208 Java User Groups
- 25 JavaScript - Nashorn
- Programs
- 667 LiveLabs
- 41 Workshops
- 10.3K Software
- 6.7K Berkeley DB Family
- 3.6K JHeadstart
- 6K Other Languages
- 2.3K Chinese
- 207 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 474 Portuguese
Passing array to PL/SQL function

AlanShar
Member Posts: 10
Hi,
I am passing an array to a PL/SQL package function. I am doing this to use this array in a query inside the function which has IN clause.
My declaration of package looks like :
Thanks,
Alan
Edited by: AlanShar on Apr 30, 2013 5:50 AM
I am passing an array to a PL/SQL package function. I am doing this to use this array in a query inside the function which has IN clause.
My declaration of package looks like :
create or replace PACKAGE selected_pkg IS TYPE NUM_ARRAY IS TABLE OF NUMBER; FUNCTION get_selected_kml( in_layer IN NUMBER, in_id IN NUMBER, in_feature_ids IN selected_pkg.NUM_ARRAY, in_lx IN NUMBER, in_ly IN NUMBER, in_ux IN NUMBER, in_uy IN NUMBER ) RETURN CLOB; END selected_pkg;In my PL/SQL function I am firing a query like following
select a.id, a.geom from Table_FIELD a where a.id in (select * from table (in_feature_ids)) and sdo_filter(A.GEOM,mdsys.sdo_geometry(2003,4326,NULL,mdsys.sdo_elem_info_array(1,1003,3), mdsys.sdo_ordinate_array(0,57,2.8,59)),'querytype= window') ='TRUE'The same query runs fine if I run it from anonymous block like
CREATE TYPE num_arr1 IS TABLE OF NUMBER; declare myarray num_arr1 := num_arr1(23466,13396,14596); BEGIN FOR i IN (select a.id, a.geom from Table_FIELD a where a.id in (select * from table (in_feature_ids)) and sdo_filter(A.GEOM,mdsys.sdo_geometry(2003,4326,NULL,mdsys.sdo_elem_info_array(1,1003,3), mdsys.sdo_ordinate_array(0,57,2.8,59)),'querytype= window') ='TRUE' loop dbms_output.put_line(i.id); end loop; end;If I try to run it by calling function as below
create type num_arr1 is table of number; --Running function from passing array for IDs declare result CLOB; myarray selected_pkg.num_array := selected_pkg.num_array(23466,13396,14596); begin result:=SELECTED_PKG.get_selected_kml(3, 19, myarray, 0.0,57.0,2.8,59); end;I am getting error
ORA-00904: "IN_FEATURE_IDS": invalid identifierCould someone please help me understand the cause of it?
Thanks,
Alan
Edited by: AlanShar on Apr 30, 2013 5:50 AM
Answers
-
I don't think you're showing us everything.
The anonymous block you posted, for example, cannot possibly compile. You're declaring a local variable named MyArray. You're then referencing a variable IN_FEATURE_IDS in your query. There is no way that could work unless IN_FEATURE_IDS is somehow defined somewhere else. I suspect that this block isn't actually running.
The anonymous block is declaring a collection of type NUM_ARR1. Your procedure is accepting a collection of type selected_pkg.NUM_ARRAY. Those are two different collection types. If you want to use a collection in SQL, it needs to be defined in SQL not in a PL/SQL package. If NUM_ARR1 is defined in SQL, that would explain why those collections can be used in SQL while collections of type selected_pkg.NUM_ARRAY cannot. But that wouldn't explain the error you say you're getting in your procedure which is referring to a problem resolving the identifier not that the identifier is of the wrong type.
Justin -
TABLE operator is SQL, not PL/SQL operator and only works for collections of SQL type. You can't use it against PL/SQL declares types. Create type in SQL, not in package:
CREATE OR REPLACE TYPE NUM_ARRAY IS TABLE OF NUMBER / create or replace PACKAGE selected_pkg IS FUNCTION get_selected_kml( in_layer IN NUMBER, in_id IN NUMBER, in_feature_ids IN NUM_ARRAY, in_lx IN NUMBER, in_ly IN NUMBER, in_ux IN NUMBER, in_uy IN NUMBER ) RETURN CLOB; END selected_pkg;
And in working example you posted what is NUM_ARR type? I has to be SQL type, otherwise it wouldn't work.
SY. -
Thanks Justin, Sorry I missed a line in the anonymous block, Please find the code below:--Running function query from passing array for IDsThanks,
CREATE TYPE num_arr1 IS TABLE OF NUMBER;
declare
myarray num_arr1 := num_arr1(23466,13396,14596);
BEGIN
FOR i IN (select a.id, a.geom from Table_FIELD a where a.id in (select * from table (in_feature_ids)) and >sdo_filter(A.GEOM,mdsys.sdo_geometry(2003,4326,NULL,mdsys.sdo_elem_info_array(1,1003,3), mdsys.sdo_ordinate_array(0,57,2.8,59)),'querytype= window') ='TRUE'
loop
dbms_output.put_line(i.id);
end loop;
end;
Alan -
Please top'n'tail your source code with {noformat}
{noformat} tags. They make it so much easier to read your code. Cheers, APC
-
It still refers to something called 'in_feature_ids' that is not declared anywhere. My guess is this would have been an IN parameter passed into some function, and you have copied and pasted it into a test block but missed the argument list.
There is also a bracket missing at the end of your FOR cursor (before 'loop'), and an unexplained ">" character before 'sdo_filter'.
Please usetags for code and {quote} or '>' for quotations.
-
Hi Alan,
If you are calling this function thr another PLSQL subblock, then please check if you r able to add ref cursor as in parameter. It is same as passing array.
http://docs.oracle.com/cd/E11882_01/win.112/e23174/featRefCursor.htm
Thanks,
Avinash.
This discussion has been closed.