Arrays in oracle
There are some query's to be executed by java code that return more than one rows, but i want this query to be executed by a stored procedure. I am looking for a solution which will return this multiple rows using a parameter in a procedure/Package.
e.g I have emp table that has 10 records, I create a proedure emp_data which will have select * from emp, I want this procedure to return 10 rows.
> there is VARRAY in Oracle - is it different than the array?
A VARRAY is a fixed size (static) array in the SQL Engine. When defining and using arrays in PL/SQL Engine,
these are dynamic (can be extended) arrays (aka PL/SQL "tables").
There are also other differences. The SQL Engine "knows" the VARRAY SQL type and can use it - it has access
to the array's type definition.
The SQL Engine cannot however (directly) use a PL/SQL array - as the type has been defined in the
PL/SQL (and can include non-SQL data types like BOOLEAN). This requires PL/SQL arrays to be casted to
a structure that the SQL Engine can understand (and array data copied from the PL/SQL Engine to
the SQL Engine). Only then can the SQL Engine use a PL/SQL array.
Personally, I do not like using VARRAYs as that does not fit with my views of a relational design. It is
IMO dealing with a bad case of 2nd normal form when using VARRAYs in a SQL table.
Nested tables in a SQL table however can be justified in my view - especially when the child rows of one
parent row have absolutely nothing in common with the child rows from another parent row.
The question as to HOW to use these arrays depend on the requirements - and then selecting the best tool
for the job. Arrays have the same basic data structure, and serve the same basic purpose, irrespective
of the programming language.
Similar Messages
-
Conversion of java Array to oracle SQL Array while calling Stored Procedure
How java Array can be converted to oracle SQL array while calling Stored procedure with callable statement.
i.e java Array ---> Sql Array in Oracle while setting the datatypes to callable statement arguments.Look at:
http://forum.java.sun.com/thread.jsp?forum=48&thread=376735&tstart=0&trange=15
Paul -
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. -
Can any one help me to use an Array in oracle.Also i want to search whether an element is already existing in the array
One possible approach
SQL> create or replace type array as table of number;
2 /
Type created.
SQL> select case when count(*) = 1 then 'found' else 'not found' end
2 from dual
3 where exists (
4 select null from table(array(1,2,3,4,5))
5 where column_value = 3);
CASEWHENC
found
SQL> edi
Wrote file afiedt.sql
1 select case when count(*) = 1 then 'found' else 'not found' end
2 from dual
3 where exists (
4 select null from table(array(1,2,3,4,5))
5* where column_value = 1)
SQL> /
CASEWHENC
found
SQL> edi
Wrote file afiedt.sql
1 select case when count(*) = 1 then 'found' else 'not found' end
2 from dual
3 where exists (
4 select null from table(array(1,2,3,4,5))
5* where column_value = 6)
SQL> /
CASEWHENC
not found -
Sharing in Symetrics Array an Oracle datawerehouse and oracle database 9i
I
i want to know if someone have an sharing in Symetrics Array an Oracle
datawerehouse and oracle database 9i, or any array for high
availability. This because i have to do implement an installation
datawarehouse and db9i on the same arrary. Just know any comment if
whichever with share with me your expertise from any situation with
this, please.
ThanksThanks for the reply.
Actually I thought that the OCCI forum was for Object oriented OCI, so while I'm using C++, I'm not using the object oriented side of OCI, just using the normal OCI calls. Guess I should have been a little clearer in my original post.
But my main question really concerned the version of the client and the version of the database which you answered.
Thanks,
Nick -
Pass array in Oracle 9i procedure
I would like to pass an array in a procedure. I would like to know how can we use array in Oracle 9i.
I would like to use sp's to insert data from frontend. For this i need an array to pass the values of master and transactions. Is there any other way to do this plz let me know. All suggestions are welcome.This is the Oracle9i Lite forum. Please post your message on teh Oracle9i forum
-
Passing arrays to Oracle Stored procedure.
Have any body passed arrays to Oracle stored procedures while the app is running in Weblogic app server. I am able to pass the arrays with regular JDBC connection. If I run the same piece of code using a connection recieved from the datasource of weblogic server, its not working. I am getting serialization errors with the ArrayDescriptor class. Looks like the ArrayDescriptor is not serializable.
Does anybody know solution/workaround to pass arrays ?
Thanks in advanceyou could write a wrapper class that extends ArrayDescriptor and implements serializable...
for example your class would look something like this.
public class MyArrayDescriptor extends ArrayDescriptor
implements Serializable
in your regular code use the wrapper class in place of the ArrayDescriptor (it will contain all the same methods as the real ArrayDescriptor) and you should be able to toss your wrapper class anywhere you please. -
How to configure hw disk array for ORACLE VM SERVER 2.1.1?
ORACLE VM SERVER 2.1.1 ON DISK SATA ARRAY R0. AFTER A INSTALLATION ORACLE VM SERVER DON;T LOAD
No reason to shout, buddy... Turn CAPS LOCK off, please.
Some more information might come in handy also. Like what kind of hardware you're using.
Otherwise it's going to be a shot in the dark.
In the meantime: try some GRUB-parameters to boot from the right device. That's all I can think of right now. -
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,
VinayHi!
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 -
Passing array to oracle stored procedure in VC++ 2005
Hi,
I am try to send an array of integers to a stored procedure via ODBC 10.2.0.3 on VC++2005 enviornment. I get the below error
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'MYPROC1'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored ... Error Code = 6550
[]E R R O R
The same code works if I use an INSERT statement.
SQLUSMALLINT* rowsProcessed = new SQLUSMALLINT;
RETCODE nRetCode;
const int arraySize = 200;
long ptrVal[arraySize];
long ptrInd[arraySize];
long ptrStatus[arraySize];
for (int i = 0; i < arraySize; i++)
ptrVal = i;
ptrInd = 0;
nRetCode = SQLSetStmtAttr(m_hstmt, SQL_ATTR_PARAM_BIND_TYPE, SQL_PARAM_BIND_BY_COLUMN, 0);
// assign the number of sets of parameters that are to be inserted
nRetCode = SQLSetStmtAttr(m_hstmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER)iSizeOfArray, 0);
// assign an array to retrieve status info for each row of parameter values
nRetCode =SQLSetStmtAttr(m_hstmt, SQL_ATTR_PARAM_STATUS_PTR, (SQLPOINTER)ptrStatus, 0);
// assign a buffer to store the number of sets of parameters that have been processed
nRetCode = SQLSetStmtAttr(m_hstmt, SQL_ATTR_PARAMS_PROCESSED_PTR, (SQLPOINTER)rowsProcessed, 0);
nRetCode = SQLBindParameter(m_hstmt, nParamIndex, nDirection, SQL_C_LONG, SQL_INTEGER, 0, 0, ptrVal, 0, ptrInd);
//suceeds
SQLPrepare(m_hstmt, (SQLCHAR*)"INSERT INTO my_table VALUES (?)", SQL_NTS);
//fails
SQLPrepare(m_hstmt, (SQLCHAR*)"{CALL mypackage.myproc1(?)}", SQL_NTS);
SQLExecute(m_hstmt);
package is
create or replace package mypackage
as
type mytable is table of binary_integer;
procedure myproc1( l_tab in mytable);
end;
show errors
create or replace package body mypackage
as
procedure myproc1( l_tab in mytable)
as
begin
insert into my_table values (100);
commit;
FORALL i IN l_tab.first .. l_tab.last
INSERT into my_table values( l_tab(i) );
end;
end;
any ideas?I believe when you're doing it with an insert, you're saying "execute this insert statement a bunch of times, here's all the values in advance", which is different than passing an array to a stored procedure where you want it to execute once.
Oracle's ODBC driver doesnt support Associative Arrays (aka index-by tables).
Hope it helps,
Greg -
Problem passing oracle.sql.ARRAY to Oracle
I am having ClassCastException when I try to pass a oracle.sql.ARRAY to a Oracle Package.
Here is my code:
PreparedStatement stmt = null;
String strArray[] = { "1,2,3,4,5" };
ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor( "TEST_PAC_1.TEST_COLL_2", dbConnection );
//encounter Exception on the line below.
ARRAY array_to_pass = new ARRAY( descriptor, dbConnection, strArray );
String queryStr = "begin TEST_PAC_1.TEST_PROC_2(?); end;";
stmt = dbConnection.prepareStatement(queryStr);
stmt.setArray( 1, array_to_pass );
stmt.execute();
I understand that oracle.sql.ARRAY has been replaced by weblogic.jdbc.vendor.oracle.OracleArray in Weblogic.
MY QUESTION IS: HOW DO I INSERT MY STRING ARRAY INTO THE OracleArray and pass it to the plsql.
Really frustrated searching through the forums for the whole day,
Thanks,Try this if you are at weblogic 8.1:
Connection con = getConnectionFromDataSource();
Connection vendorConnection = ((WLConnection)con).getVendorConnection();
// use direct oracle connection.
ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor( "TEST_PAC_1.TEST_COLL_2", dbConnection );
vendorConnection.close();
Beware that you should be very careful as you are going to use a direct vendor
connection.
The better aproach is to pass the string array as a delimited string to your storad
procedure and parse it in the SP - then you don't have to mess up with vendor-specific
handling.
Hope this helps.
Regards,
Slava Imeshev
"Daddy Daddy" <[email protected]> wrote in message news:24349835.1097143668312.JavaMail.root@jserv5...
I am having ClassCastException when I try to pass a oracle.sql.ARRAY to a Oracle Package.
Here is my code:
PreparedStatement stmt = null;
String strArray[] = { "1,2,3,4,5" };
ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor( "TEST_PAC_1.TEST_COLL_2", dbConnection );
//encounter Exception on the line below.
ARRAY array_to_pass = new ARRAY( descriptor, dbConnection, strArray );
String queryStr = "begin TEST_PAC_1.TEST_PROC_2(?); end;";
stmt = dbConnection.prepareStatement(queryStr);
stmt.setArray( 1, array_to_pass );
stmt.execute();
I understand that oracle.sql.ARRAY has been replaced by weblogic.jdbc.vendor.oracle.OracleArray in Weblogic.
MY QUESTION IS: HOW DO I INSERT MY STRING ARRAY INTO THE OracleArray and pass it to the plsql.
Really frustrated searching through the forums for the whole day,
Thanks, -
Pass string array to Oracle function from Web page
Hi. I need to pass a two-dimensional array of string values to an Oracle function from an ASP.NET page. Is there an efficient way to accomplish this? I'm thinking I'll have to create a long string with special delimiters,
|12345^4.000|67890^3.670|.....
I'd parse the string on Oracle and break it into its component parts. In this example, each "record" is separated by the bar "|" and each field is separated by the up arrow "^". So each record has two fields.
Is this a good approach? Your input is much appreciated. Thanks.In PL/SQL, it is easy enough to define a record type with two attributes and declare a store procedure that takes in an array of those parameters. I know that from Java it is possible to create and pass in such an array. I would suspect that the same is possible from .Net but I am not a competent .Net developer.
Justin -
Problem with database control returning multiple rows as Array using Oracle
Has anybody using Oracle gotten a Database control that
returns multiple rows to work returning an array?
The only way I can seem to return multiple rows is by returning
a RowSet. Returning an array gives me a NullPointerException
(when called within a pageFlow). When calling a database control
that returns an array from a web service I get a
"java.sql.SQLException: ResultSet has no more data." error.
The samples using the pointbase database seem to work, but when I
converted the CustomerDBClient web service to use Oracle, it starts
failing on calling the database control that returns an array
with: "java.sql.SQLException: ResultSet has no more data."
Has anybody gotten this to work using Oracle?
I'm also having some problem returning an Iterator. It seems
to work when called from a web service, but returns nothing
if called from a page flow.
I'm using Oracle 8.1.7 and WebLogic 8.1.
EricDo you need a particular service pack installed to return an array of custom object?
I am getting a ResultSet contained no data error when trying.
Thanks,
-Thomas
"Robin Karlin" <[email protected]> wrote:
>
Eddie O'Neil <[email protected]> wrote:
All--
Unfortunately, returning an Iterator to a JPF (or JSP) from a
database control is broken in WLW 8.1, though it will work inside of
a
JWS or JCS.
There shouldn't be a problem with returning an array of objects out
of Oracle to the JPF, and if you need an Iterator specifically, youcan
wrap the array in an Iterator implementation.
Sorry for the inconvenience.
Eddie
Lenny wrote:
I have gotten it to work on Oracle using Array:)
However, I haven't gotten it to work on Oracle using Iterator:( Itis so
simple, but doesn't work:(
"Eric Dokken" <[email protected]> wrote in message
news:[email protected]...
Has anybody using Oracle gotten a Database control that
returns multiple rows to work returning an array?
The only way I can seem to return multiple rows is by returning
a RowSet. Returning an array gives me a NullPointerException
(when called within a pageFlow). When calling a database control
that returns an array from a web service I get a
"java.sql.SQLException: ResultSet has no more data." error.
The samples using the pointbase database seem to work, but when I
converted the CustomerDBClient web service to use Oracle, it starts
failing on calling the database control that returns an array
with: "java.sql.SQLException: ResultSet has no more data."
Has anybody gotten this to work using Oracle?
I'm also having some problem returning an Iterator. It seems
to work when called from a web service, but returns nothing
if called from a page flow.
I'm using Oracle 8.1.7 and WebLogic 8.1.
Eric
I get the same error that Eric reported when trying to return an Array
of objects.
It is really frustrating because I can't use much of the built-in control
logic
that WLW provides. All I did was create a data pool for Oracle and a
datasource.
I modified the sample app in C:\bea81\weblogic81\samples\workshop\SamplesApp\WebApp\callJavaControl
to point to that datasource and I get the error that Eric reports above.
Can
anyone help me out????
Thanks,
Robin -
Hello
I'm using .net 4.0 (C#) with oracle 11g.
I wrote a SP that insert data into some tables and I need to send to it two parameters which are arrays of decimals (I don't know in advance how many items will be in the array), I searched the net for a solution but couldn't find an answer...
I tried to use varrays (although they are not dynamic) but still no success, I recieved the following exception when running the C# code:
Unknown datatype System.Decimal[] for parameter value of type Object.
Here is the SP I wrote:
create type varrayFE as varray(1000) of varchar(decimal);
create type varrayBE as varray(1000) of varchar(decimal);
create or replace
PROCEDURE CI_INSERT_HISTORY_REPORT
Report_Name_Param IN VARCHAR2 , User_ID_Param IN NUMBER , Report_Type_Param IN NUMBER
, RootFE_Param IN NUMBER , Time_Period_Param IN NUMBER , Hours_Param IN NUMBER
, SW_Param IN NUMBER , FE_Param IN varrayFE , BE_Param IN varrayBE
) AS
BEGIN
INSERT INTO CI_History_Reports
VALUES (Report_Name_Param,User_ID_Param, Report_Type_Param,
RootFE_Param, Time_Period_Param, Hours_Param, SW_Param);
FOR i IN FE_Param.first .. FE_Param.last
LOOP
INSERT INTO CI_History_Reports_FE
VALUES (FE_Param(i));
END LOOP;
FOR i IN BE_Param.first .. BE_Param.last
LOOP
INSERT INTO CI_History_Reports_BE_TYPE
VALUES (BE_Param(i));
END LOOP;
END;
END CI_INSERT_HISTORY_REPORT;Helios- Gunes EROL wrote:
Hi;
For your issue i suggest close your thread here as changing thread status to answered and move it to Forum Home » Database » SQL and PL/SQL which you can get more quick responseMoved.
Nicolas. -
How to achieve Multi Dimensional array in Oracle
Hi,
Pls give me a solution to achieve the Multi dimensional Array concept in Oracle.
I've used Nested table concept in which I did not find any Equivalent for the array structure in COBOL given below
01 customer_record.
   03 telephone_number occurs 3 times.
      05 country_code pic 999.
      05 area_code pic 999.
      05 local_number occurs 2 times.
          08 prefix pic 999.
          08 subscriber_number pic 999.
Thanks in Advance
Regds,
ArkumarWhat about VARRAYs and user defined objects?
Maybe you are looking for
-
I have two screens on my PC Adobe always opens on the second screen. How do I change this to open on the first screen.
-
How long do you need to charge a new iPhone 5 for before trying to turn it on?
I received a new iphone 5 in the post today to replace the ne I had smashed the screen on. I was told that I would need to charge the phone and then insert my SIM and it would be good to go. The phone has been on charge since 14:00 and still wont tur
-
SURLError 1005? What's That All About?
Howdy folks, fairly new mac user here. Everything's been just dandy for the last month but tonight Safari took a few attempts to get going: giving me this error code of 1005. After I finally got it running it seems slower than normal and I'm having a
-
USB port is not working,
I have HP Pavillion p6230in purchased on 30/4/2010 in New Delhi, India. In my PC USB Port and DVD drive is not working. I have loged complaint with Service Centre 4/3/2011 but in vain no one has visited my place for repair. I do my self system rec
-
Vbscript, change page size
So I have folder with numerous word/excel files that need to be converted to PDF on Legal Size "paper". We have the "Save As PDF" plugin for Office so converting the files to PDF is no problem, however, using that plugin you cannot specify a "Print S