How to pass an array in Oracle Procedure
If I have to pass an array as an argument in Oracle Procedure/function. How to do that ??
For example, I have to pass the names of employess and then for these employess I have to do something in Oracle Procedure.
Thanks & Regards,
Vinay
Hi!
Here is an example:
create or replace procedure test
is
type v2_itt is table of varchar2(2000) index by binary_integer;
l_v2 v2_itt;
procedure test2( pi_v2 v2_itt ) is
begin
for i in 1 .. pi_v2.count loop
dbms_output.put_line( pi_v2(i) );
end loop;
end;
begin
l_v2(1) := 'name1';
l_v2(2) := 'name2';
test2( l_v2 );
end;
Regards,
Andrew Velitchko
BrainBench MVP for Developer/2000
http://www.brainbench.com
Similar Messages
-
How to pass an array to a procedure & how to use array in IN clause in SQL
Hi all,
how do i pass an array of varchar2[10] in an procedure and i want to use this array in the IN caluse of the SQL statement inside the procedure. Can anyone please help me on this.
Thanks & regards
shyam~There are multiple ways. For example:
SQL> create or replace
2 type str10_tbl_type is table of varchar2(10)
3 /
Type created.
SQL> -- Using TABLE operator
SQL> create or replace
2 procedure p1(
3 p_str10_tbl str10_tbl_type
4 )
5 is
6 begin
7 for rec in (
8 select ename,
9 sal
10 from emp,
11 table(p_str10_tbl)
12 where ename = column_value
13 ) loop
14 dbms_output.put_line(rpad(rec.ename,10) || rec.sal);
15 end loop;
16 end;
17 /
Procedure created.
SQL> set serveroutput on format wrapped
SQL> exec p1(str10_tbl_type('KING','ALLEN','SMITH'));
KING 5000
ALLEN 1600
SMITH 800
PL/SQL procedure successfully completed.
SQL> -- Using MEMBER OF method
SQL> create or replace
2 procedure p1(
3 p_str10_tbl str10_tbl_type
4 )
5 is
6 begin
7 for rec in (
8 select ename,
9 sal
10 from emp
11 where ename member of p_str10_tbl
12 ) loop
13 dbms_output.put_line(rpad(rec.ename,10) || rec.sal);
14 end loop;
15 end;
16 /
Procedure created.
SQL> set serveroutput on format wrapped
SQL> exec p1(str10_tbl_type('KING','ALLEN','SMITH'));
SMITH 800
ALLEN 1600
KING 5000
PL/SQL procedure successfully completed.
SQL> SY. -
How to pass int array as an IN parameter to PLSQL Procedure
Hi,
How to pass int array in java to a stored procedure througn jdbc
and what type of data type I should declare to this IN parameter
in PLSQL Procedure.
Thanks,
SimiHi,
The best way to do what you want depends on what you want. Start by describing what you need to do. It's best to post some sample data (CREATE TABLE and INSERT statments) and what results you want from that sample data. (See the forum FAQ: https://forums.oracle.com/message/9362002)
If you have ideas about how to do the job (e.g., populating a temporary table) it can be helpful to include those, too, but distinguish clearly between WHAT you need to do and HOW you might do it.
As Bencol suggested, a SYS_REFCURSOR might be the best way to pass back the results.
Since you didn't post your table, or even describe what you wanted to do with it, I'll illustrate using scott.emp, which is probably on your system.
Say you wanted a procedure that took a DATE as an argument, and returned a some designated columns (empno, ename and hiredate in the example below) for all employees hired on or after the given DATE. You might write a procedure like this:
CREATE OR REPLACE PROCEDURE hired_since
( start_date IN DATE
, out_data OUT SYS_REFCURSOR
AS
BEGIN
OPEN out_data FOR
SELECT empno, ename, hiredate
FROM scott.emp
WHERE hiredate >= start_date;
END hired_since;
SHOW ERRORS
You can test it in SQL*Plus like this:
VARIABLE c REFCURSOR
EXEC hired_since (DATE '1982-01-01', :c);
PRINT :c
The output I got from this test was:
EMPNO ENAME HIREDATE
7788 SCOTT 19-APR-87
7876 ADAMS 23-MAY-87
7934 MILLER 23-JAN-82 -
How to pass an array to a stored procedure
create or replace package demo_pkg
as
type cityArray is table of city%rowtype index by binary_integer;
procedure city_report( p_inputs in cityArray );
end;
CREATE OR REPLACE PACKAGE BODY demo_pkg
AS
PROCEDURE city_report (p_inputs IN cityarray)
IS
BEGIN
FOR i IN 1 .. p_inputs.COUNT
LOOP
DBMS_OUTPUT.put_line ( 'citycode = '
|| p_inputs (i).city_code
|| ' CITYDESCRIPTION = '
|| p_inputs (i).city_description
INSERT INTO testing
(city_code, city_description
VALUES (p_inputs (i).city_code, p_inputs (i).city_description
commit;
END LOOP;
END;
END;
to call that procedure ia m using this
declare
my_data demo_pkg.cityArray;
begin
my_data(1).city_code := 1234;
my_data(1).CITY_DESCRIPTION := 10;
my_data(2).city_code := 4567;
my_data(2).CITY_DESCRIPTION := 20;
my_data(3).city_code := 4321;
my_data(3).CITY_DESCRIPTION := 30;
demo_pkg.city_report( my_data );
end;
but actually the procedure (demo_pkg.city_report)is called from front end(.net).how they will call this procedure in .net invironmentHi,
Your exact question has been asked before, see: http://asktom.oracle.com/pls/ask/search?p_string=How+to+pass+an+array+to+a+stored+procedure
or do a search on this forum.
And please use this tag => (yes, just the 4 characters forming the word 'code' between curly brackets)
*before* and *after* your example to maintain formatting and indentation, it's hard to read now.... -
I am ussing a DLL created by another party. I have the list of the C declaretions. I have been able to write a seq that can turn the comport ON/OFF or select a different port but I have not been able to send or recieved any data. I have created an array of bytes(unsigned 8-bit integers)to send and recieved data but nothing goes out or in.
Hi Toro,
There is an example in your \Examples\AccessingArrays\PassingArrayParametersToDLL directory that illustrates exactly how to pass TestStand arrays as arguments to dll functions. The source files for the .dll are located in the same directory.
For more information on passing arrays as parameters to modules you should read the "DLL Flexible Prototype Adapter" section of Chatper 13 in the TestStand User Manual, and pay special attention to the subsection entitled "Array Parameters". You can access the User Manual from the TestStand Start Menu group, the TestStand Sequence Editor's Help menu, the \Doc directory, or online at the following link:
http://digital.ni.com/manuals.nsf/websearch/50B69DA356B8D38C86256A0000660E6B?OpenDocumen
t&node=132100_US
Jason F.
Applications Engineer
National Instruments
www.ni.com/ask -
How to pass an Array to jsp:param
Hi,
I am trying to find out how to pass an array to a jsp:param tag abnd then retrieve
the values in the next page. Please help soon. Thanks
Here's my code - Assume the books array has more than 1 value
String[] books = request.getParameterValues("book");
<jsp:include page="<%=contentPage%>" flush="true">
<jsp:param name="bookSelected" value="<%= books %>" />
</jsp:include>
The 'contentPage' takes me to the next page where I have the following to retrieve
the value of 'bookSelected'
String[] bookSelected = request.getParameter("bookSelected");
I tried accessing the array like this
if(bookSelected.equals("book1"))
but did not succeed.
I tried accessing the array in a loop but it did not work. Here's what I tried.
<jsp:include page="<%=contentPage%>" flush="true">
<%for (int i = 0; i<books.length; i++){
%>
<jsp:param name="bookSelected" value="<%= books %>" />
<% } %>
</jsp:include>
Hi
tell me how you redirect from __confirmdelete.jsp:__ to deleteServlet.java..
and post detail code of __confirmdelete.jsp:__ -
How to pass ARRAY to Oracle Procedure
Hi
We are using BC4J with JSP in our project. We need to send an Array to the procedure.
Could somebody provide some info as how this can be achieved.A while back, I used a SQLJ client to call a Java (also SQLJ) stored procedure and I needed to pass an array of strings to the procedure. I did something like this:
Java Class that was loaded in DB:
public class MyClass
// method that the stored procedure uses
public static void CALL_DOSTUFF(String a,
oracle.sql.ARRAY b,
oracle.sql.ARRAY c)
String[] bb = (String[])b.getArray();
String[] cc = (String[])c.getArray();
doStuff(a,bb,cc);
public static void doStuff(String a,
String[] b,
String[] c)
// process the input
In the database I added the type:
create or replace type STR_ARRAY as table of varchar2(20);
and the procedure:
create or replace procedure CALL_DOSTUFF(a varchar2,
b STR_ARRAY,
c STR_ARRAY)
as
language java
name 'MyClass.CALL_DOSTUFF(java.lang.String,
oracle.sql.ARRAY,
oracle.sql.ARRAY)';
I then used jpub to publish a STR_ARRAY.java file. I compiled this and used it with my SQLJ client to call to the stored procedure. The STR_ARRAY constructor takes a String[], so you do something like this in the SQLJ client:
String x = "X";
String y = {"y1","y2"};
String z = {"z1","z2"};
STR_ARRAY y1 = new STR_ARRAY(y);
STR_ARRAY z1 = new STR_ARRAY(z);
#sql {CALL CALL_DOSTUFF(:x,:y1,:z1)};
Hope this helps. -
How to pass a array of object to oracle procedure using callable
Hi,
I am calling a oracle stored procedure using callable statement which has IN and OUT parameter of same type.
IN and OUT are array of objects. (ie) IN parameter as Array of Objects and OUT parameter as Array of Objects
here are the steps i have done as advised from oracle forum. correct me if i am in wrong direction
ORACLE types and Stored Procedure
CREATE OR REPLACE
TYPE APPS.DEPARTMENT_TYPE AS OBJECT (
DNO NUMBER (10),
NAME VARCHAR2 (50),
LOCATION VARCHAR2 (50)
CREATE OR REPLACE
TYPE APPS.DEPT_ARRAY AS TABLE OF department_type;
CREATE OR REPLACE package body APPS.insert_object
IS
PROCEDURE insert_object_prc (d IN dept_array, d2 OUT dept_array)
IS
BEGIN
d2 := dept_array ();
FOR j IN 1 .. d.COUNT
LOOP
d2.EXTEND;
d2 (j) := department_type (d (j).dno, d (j).name, d(j).location);
END LOOP;
END insert_object_prc;
END insert_object;
JAVA CODE
Value Object
package com.custom.vo;
public class Dep {
public int empNo;
public String depName;
public String location;
public int getEmpNo() {
return empNo;
public void setEmpNo(int empNo) {
this.empNo = empNo;
public String getDepName() {
return depName;
public void setDepName(String depName) {
this.depName = depName;
public String getLocation() {
return location;
public void setLocation(String location) {
this.location = location;
to call stored procedure
package com.custom.callable;
import com.custom.vo.Dep;
import oracle.jdbc.OracleCallableStatement;
import oracle.jdbc.OracleConnection;
import oracle.jdbc.OracleTypes;
import oracle.jdbc.pool.OracleDataSource;
import oracle.sql.ARRAY;
import oracle.sql.ArrayDescriptor;
import oracle.sql.Datum;
import oracle.sql.STRUCT;
import oracle.sql.StructDescriptor;
public class CallableArrayTryOut {
private static OracleDataSource odcDataSource = null;
public static void main(String[] args) {
OracleCallableStatement callStatement = null;
OracleConnection connection = null;
try {
odcDataSource = new OracleDataSource();
odcDataSource
.setURL("......");
odcDataSource.setUser("....");
odcDataSource.setPassword("....");
connection = (OracleConnection) odcDataSource.getConnection();
} catch (Exception e) {
System.out.println("DB connection Exception");
e.printStackTrace();
Dep[] dep = new Dep[2];
dep[0] = new Dep();
dep[0].setEmpNo(100);
dep[0].setDepName("aaa");
dep[0].setLocation("xxx");
dep[1] = new Dep();
dep[1].setEmpNo(200);
dep[1].setDepName("bbb");
dep[1].setLocation("yyy");
try {
StructDescriptor structDescriptor = new StructDescriptor(
"APPS.DEPARTMENT_TYPE", connection);
STRUCT priceStruct = new STRUCT(structDescriptor, connection, dep);
STRUCT[] priceArray = { priceStruct };
ArrayDescriptor arrayDescriptor = ArrayDescriptor.createDescriptor(
"APPS.DEPT_ARRAY", connection);
ARRAY array = new ARRAY(arrayDescriptor, connection, priceArray);
callStatement = (OracleCallableStatement) connection
.prepareCall("{call insert_object.insert_object_prc(?,?)}");
((OracleCallableStatement) callStatement).setArray(1, array);
callStatement.registerOutParameter(2, OracleTypes.ARRAY,
"APPS.DEPT_ARRAY");
callStatement.execute();
ARRAY outArray = callStatement.getARRAY(2);
Datum[] datum = outArray.getOracleArray();
for (int i = 0; i < datum.length; i++) {
oracle.sql.STRUCT os = (oracle.sql.STRUCT) datum[0];
Object[] a = os.getAttributes();
for (int j = 0; j < a.length; j++) {
System.out.print("Java Data Type :"
+ a[j].getClass().getName() + "Value :" + a[j]
+ "\n");
connection.commit();
callStatement.close();
} catch (Exception e) {
System.out.println("Mapping Error");
e.printStackTrace();
THE ERROR
Mapping Errorjava.sql.SQLException: Inconsistent java and sql object types
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:1130)
at oracle.sql.StructDescriptor.toOracleArray(StructDescriptor.java:823)
at oracle.sql.StructDescriptor.toArray(StructDescriptor.java:1735)
at oracle.sql.STRUCT.<init>(STRUCT.java:136)
at com.custom.callable.CallableArrayTryOut.main(CallableArrayTryOut.java:48)You posted this question in the wrong forum section. There is one dedicated to Java that was more appropriate.
Anyway here is a link that describes what you should do.
http://download.oracle.com/docs/cd/B19306_01/java.102/b14355/oraarr.htm#i1049179
Bye Alessandro -
How to Pass String array from Java to PL/SQL and this use in CURSOR
hi,
I cant understand how to pass Array String as Input Parameter to the Procedure and this array use in Cursor for where condition like where SYMPTOM in( ** Array String **).
This array containing like (SYMPTOM ) to be returned from the java to the
pl/sql (I am not querying the database to retrieve the information).
I cannot find an example on this. I will give the PL/SQL block
create or replace procedure DISEASE_DTL<*** String Array ***> as
v_SYMPTOM number(5);
CURSOR C1 is
select distinct a.DISEASE_NAME from SYMPTOM_DISEASE_RD a
where ltrim(rtrim(a.SYMPTOM)) in ('Fever','COUGH','Headache','Rash') ------- ***** Here use this array element(like n1,n2,n3,n4,n5..) ******
group by a.DISEASE_NAME having count(a.DISEASE_NAME) > 3 ----------- ***** 3 is no of array element - 1 (i.e( n - 1))*****
order by a.DISEASE_NAME ;
begin
for C1rec IN C1 loop
select count(distinct(A.SYMPTOM)) into v_SYMPTOM from SYMPTOM_DISEASE_RD a where A.DISEASE_NAME = C1rec.DISEASE_NAME;
insert into TEMP_DISEASE_DTLS_SYMPTOM_RD
values (SL_ID_SEQ.nextval,
C1rec.DISEASE_NAME,
(4/v_SYMPTOM), --------**** 4 is no of array element (n)************
(1-(4/v_SYMPTOM)));
end loop;
commit;
end DISEASE_DTL;
Please give the proper solution and step ..
Thanking you,
AsishI've haven't properly read through your code but here's an artificial example based on a sql collection of object types - you don't need that, you just need a type table of varchar2 rather than a type table of oracle object type:
http://orastory.wordpress.com/2007/05/01/upscaling-your-jdbc-app/ -
How to pass an array to a function from a SELECT statement
Hi all. I have a problem with passing an array to a function directly from a SELECT statement.
Here is what I want. If I have a function
function AAA(arrayVar <ArrayType>) return number;
I want to be able to call this function this way
select AAA((2,3,4))
from dual
or this way
select AAA((10,12))
from dual
In other words I want to be able to pass an arbitrary number of numbers to the function. And I want this to work in a SELECT statement.
Does anyone have any ideas how to implement this? What <ArrayType> should I use?(I've read about VARRAY, nested tables in the Oracle documentation but as far as I've understood these array types are meant to be used within PL/SQL blocks).
I found only this http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:208012348074 through Google but it didn't help me.
Thank you in advance.> What <ArrayType> should I use?
SQL data types - as 3360 showed above. You cannot use PL/SQL structures and user types in the SQL Engine.
You can however use all SQL structures and types in PL/SQL.
Arrays in SQL is created as collection type - basic o-o. The collection type (or class) serve as a container for instantiated objects or scalar type.
This is covered in detail in [url http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14260/toc.htm]
Oracle® Database Application Developer's Guide - Object-Relational Features -
How to pass an array which in the jsp to a javascript file
now i have 2 files: jsp and js(javascript)
i want pass an array which in the jsp to another file--> js file
how can i do it ???
can u give me some related links or some source codes as the references???
thxbcos ....my senior has resigned!!! so i take over his job !!!!!
depend on the talent and the project ....only that way to implement to whole project !!!!
but , i had settled it already ....
it is very simple
in the middle.jsp
Collection result = menuManager.getUserRoleMenu(webSessionUser.getGnuserId());
String menuname[]=new String[110];
int menucounter=0;
Iterator vi = result.iterator();
while(vi.hasNext())
HashMap hm=(HashMap)vi.next();
menuname[menucounter]=hm.toString();
menucounter++;
int i;
String tempstr="";
for(i=0;i<menuname.length;i++)
tempstr+=menuname[i]+",";
session.setAttribute("menuname",tempstr);
%>
<script language="javascript">
menu123("<%=tempstr %>");
</script>
in the body,js
function menu123(string123)
//doing
so ....through the script --menu123
i can get the string from jsp to the js!!!!!
is it very simple, but it spends my 2 days!!!
i just learn javascript ....about 1 month !!! -
How to pass an array to a subroutine in FXscript?
Hi,
I am having problems trying to pass an array to a subroutine in FXscript. Code segment:
on TestSub(value x)
// do stuff
end
float i, testarray[256];
for i = 0 to 255
testarray[i] = i;
next
TestSub(testarray);
FXscript returns the error "missing close parenthesis". If TestSub(testarray) is replaced with TestSub(testarray[0]) no error, i.e. if a single value is passed.
Trying to define the subroutine differently doesn't help, e.g. "on TestSub(value x[255])" or "on TestSub(float x[255])" yields the same error.
How do you pass an array to an FXscript subroutine? Or is it not possible?
Thanks for any clues...You are not being quite clear. If the next frame expects a pointer to a buffer, it cannot be a vi. Labview has no pointer types. You must be referring to a Call Library Node which is set up to call a DLL function. If this is the case, you need to configure the Call Library Node to accept an array of the data type. Then you can wire the array into the call library node.
Is this the case, Call Library Node?
- tbob
Inventor of the WORM Global -
How to pass bind variable into oracle reports 6i - Parameter form
Hello All,
I want to pass bind variable into Oracle Reports 6I - Parameters.
I have tried out that but got the below error :-
rep-0781 : Bind variables are not allowed in the select statement
Kindly help me is there any option which allow me to pass bind variables into Oracle reports 6I.
Thanks
HARSH SHAHHi,
may be its not possible to use :P_PARAM1 in user parameter of oracle 6i reports
but u can full fill user requirement using oracle forms
create a form as like as report parameter window
then create parameter list and run report
PROCEDURE Run_Emp_Report IS
pl_id ParamList;
BEGIN
pl_id := Get_Parameter_List('tmpdata');
IF NOT Id_Null(pl_id) THEN
Destroy_Parameter_List( pl_id );
END IF;
pl_id := Create_Parameter_List('tmpdata');
Add_Parameter(pl_id, 'PARAMFORM', TEXT_PARAMETER, 'NO');
Run_Product(REPORTS, 'empreport', SYNCHRONOUS, RUNTIME, FILESYSTEM, pl_id, NULL);
END;
thanks
mostafiz mitul
Dhaka Bangladesh -
How to pass an array of values to a view criteria
Hi all,
How to pass mutiple values as array into a view criteria.I want to search
based on mutiple values.
Please help.
ThanksSwapna wrote:
I have a search panel with mutilselect combobox for attributes "a","b", & "c".
Based on selction"a" ,I need to filter the comboboxes "b" and "c".
This's the requirement.I'm not sure that I understand your question. Are you saying that you have three different controls in your UI? Or one control that has three possible values?
Assuming that you have one control with three possible values, if "a" is selected, does that mean that you want all rows where some column has a value of "a"? Or does that mean that you want all rows where that column does not have a value of "a"? Or does that mean that you want all rows where that column has a value of "b" or "c" (note that the last two may be different if the column allows NULL values).
What language is your application written in? What framework/ library are you using to access the database? Are you passing a PL/SQL collection of selected values?
Justin -
Passing multidimensional array to plsql procedure
hi ,
is there any way to pass a two dimensional array of different data types to plsql procedure as a parameter?
In other words, is it possible to pass a set or records or a datatable as a single parameter to plsql procedure?
Because I am using a dataset selected with odp.net in my client and I am modifying the data in different datatables contained in the dataset.At the moment, the modified datatables are saved by seperating each column as a sepearate array and passing each column array as a seperate parameter to a stored procedure. But, I would like to change it in a way to pass each datatable as a single parameter to the stored procedure.
I would appreciate any solution/suggestion/hint in regard to this problem
thanks in advance,
Prabhakar.If your Java array is of a base type (String, int, etc.) and you are using the OCI driver, you can use OracleCallableStatement.setPlSqlTable(). (I'm doing this from memory so the method name may be slightly different.)
The method takes a Java array and converts it to a PL/SQL table before passing it to the stored procedure.
Maybe you are looking for
-
Can't connect to the internet with my iPod touch 4th gen.
So I have an iPod touch 4th gen. and have been able to get wifi from my computer with no problem but now it's not working. When I choose the network I've always used I see the 3 lines on top of the screen that show when it's connected to the internet
-
System setting does not allow changes to be made to object LSYS
Hi Im trying to create the process chain in BW-Production System . Like im trying to delete the PSA data for one datasource in BI7.0 . Im using the 'Delete requests from the PSA' process type in the process chain . When i try to give the datasource n
-
i dont have one of these yet, but im going to probably get one from my grandma for christmas, and i was wondering, does the new ipod classic 80GB have a visualizer like itunes?
-
My Z10 no longer switches to a horizontal screen when typing texts, email, etc. or for viewing videos. How do I fix this?
-
How to migrate iTunes to new Windows install
Hello friends! I am pretty good with computers but terrible at iTunes! So my SSD crashed & took down my C drive. Luckily, everything is backed up. My iTunes was installed on my C drive and the library is on my Z drive. I would like to keep my li