Return a collection
I am having trouble coming up with a plan for search functionality for my UI. I have an application that talks to a middle teir in .NET, the middle tier accesses the Oracle database.
People are going to want to search by multiple fields that come from multiple tables. It was suggested on the .NET forums that I write a procedure that takes all possible search fields and then just check if they are null or not and come up with a dynamic query. Seems like a possible solution, but maybe not the best.
So, I am toying around with that idea, but cannot figure out how I can return a varibale length collection of IDs (number) from a function or procedure. Or at least what the best way to do that is.
My colleague came up with some code, but I don't understand it and neither does he, it was put together from some googled examples trial and error.
But rather than try to decypher what we came up with I thought I'd ask what the preferred method of doing this is and if someone is kind enough to write up an example?
From what I can tell, there are problems getting a varray back on the .NET side, but haven't played with it too much yet.
Ok, I didn't understand what it was doing fully. Now I do. Works nicely. I am having trouble with the bulk collect part though. I get an error when I change my current loop to
OPEN cursorPersonIDs FOR finalQuery USING firstName, lastName, phoneNumber, emailAddress;
FETCH cursorPersonIDs BULK COLLECT INTO results;
Error: "inconsistent datatypes: expected UDT got NUMBER"
Here is my current code: (Sorry the forum irradicated my formatting)
CREATE OR REPLACE FUNCTION NEWDB."F_FIND_PERSON"(firstName IN varchar2,
lastName IN varchar2,
phoneNumber IN varchar2,
emailAddress IN varchar2)
RETURN TBL_IDS
IS
TYPE RefCursor IS REF CURSOR;
selectPart varchar2(32) := 'SELECT PPL.PERSON_ID ';
fromPart varchar2(128) := 'FROM PEOPLE PPL ';
wherePart varchar2(1024) := 'WHERE 1=1 ';
finalQuery varchar2(1024);
cursorPersonIDs RefCursor;
result number;
results TBL_IDS := TBL_IDS();
counter integer := 0;
BEGIN
-- PEOPLE table already included
-- First Name
IF firstName IS NOT NULL THEN
wherePart := wherePart || 'AND (PPL.NAME_FIRST = :pFirstName OR PPL.NAME_FIRST IS NULL) ';
ELSE
wherePart := wherePart || 'AND :pFirstName IS NULL ';
END IF;
-- Last Name
IF lastName IS NOT NULL THEN
wherePart := wherePart || 'AND (PPL.NAME_LAST = :pLastName OR PPL.NAME_LAST IS NULL) ';
ELSE
wherePart := wherePart || 'AND :pLastName IS NULL ';
END IF;
-- PHONE_NUMBERS table requires join
IF phoneNumber IS NOT NULL THEN
fromPart := fromPart || ', PHONE_NUMBERS PHN ';
wherePart := wherePart || 'AND PPL.PERSON_ID = PHN.CONTACT_ID ';
-- Phone Number
IF phoneNumber IS NOT NULL THEN
wherePart := wherePart || 'AND (PHN.PHONE_NUMBER = :pPhoneNumber OR PHN.PHONE_NUMBER IS NULL) ';
ELSE
wherePart := wherePart || 'AND :pPhoneNumber IS NULL ';
END IF;
ELSE
wherePart := wherePart || 'AND :pPhoneNumber IS NULL';
END IF;
-- EMAIL_ADDRESSES table requires join
IF emailAddress IS NOT NULL THEN
fromPart := fromPart || ', EMAIL_ADDRESSES EML ';
wherePart := wherePart || 'AND PPL.PERSON_ID = EML.CONTACT_ID ';
-- Email Address
IF emailAddress IS NOT NULL THEN
wherePart := wherePart || 'AND (EML.ADDRESS = :pEmailAddress OR EML.ADDRESS IS NULL) ';
ELSE
wherePart := wherePart || 'AND :pEmailAddress IS NULL ';
END IF;
ELSE
wherePart := wherePart || 'AND :pEmailAddress IS NULL ';
END IF;
-- Execute the query
finalQuery := selectPart || fromPart || wherePart;
OPEN cursorPersonIDs FOR finalQuery USING firstName, lastName, phoneNumber, emailAddress;
LOOP
FETCH cursorPersonIDs INTO result;
EXIT WHEN cursorPersonIDs %NOTFOUND;
results.extend;
counter := counter + 1;
results(counter) := TYPE_ID(result);
END LOOP;
CLOSE cursorPersonIDs;
RETURN results;
END;
Edited by: brekehan on Mar 19, 2010 7:46 AM
Similar Messages
-
Returning VB collections through OLE
We are creating a Forte OLE automation server which must interface
with a VB Collection.
We have successfully passed a collection from VB to Forte. Forte
receives this parameter as type CDispatch (determined using
GetClassType().Name).
We want to add items of type ValueItem to this collection.
ValueItem was generated from another VB component using olegen,
so it has a CDispatch interface.
We don't seem to be able to use the CDispatch.InvokeMethodWithResult
to execute the method Collection.Add. This is due to the fact that
ValueItem is a subclass of CDispatch and we must pass an array of
variant to InvokeMethodWithResult.
Has anybody done something similar to this?
Thank you,
KeithI'm not sure why do you need a REMOTE interface for your Entity bean...
Anyway you never return a collection of entities from a finder, but coleection of primary keys (BMP).
public Collection ejbFindBySurname(String Apellido1) throws FinderException
ArrayList list = null;
try
Connection con = getConnection();
try
PreparedStatement pstmt = con.prepareStatement("select IDAbonado from Abonado where Apellido1 like ?");
try
pstmt.setString(1, Apellido1 + '%');
ResultSet rs = pstmt.executeQuery();
list = new ArrayList();
while(rs.next())
int index = rs.getInt(1);
list.add(new Integer(index));
finally { pstmt.close(); }
finally { con.close(); }
catch (Exception ex) { throw new FinderException(ex.getMessage()); }
return list;
ArrayList is Serializable
But I prefer to use a local interface to enty in pair with SlSB
public ArrayList findBySurname(String surname)
ArrayList list = null;
try
Collection c = abonadoHome.findBySurname(surname);
list = new ArrayList(c.size());
Iterator i = c.iterator();
while(i.hasNext())
list.add(((LocalAbonado)i.next()).getMyInformationMethod();
catch(Exception ex)
ex.printStackTrace(System.err);
throw new EJBException(ex);
return list;
Note, I do not use narrow, coz I do not use remote call.
Cheers -
Returning (bulk collect) clause with execute immediate
db version 11.1.0.7
trying to do a returning bulk collect but it is not working:
-- my test table
create table t as
with f as (select rownum rn from dual connect by rownum <= 10)
select
rn,
lpad('x',10,'x') pad
from f;
-- works as expected
declare
type aat is table of t%rowtype;
aay aat;
begin
delete from t returning rn,pad bulk collect into aay;
rollback;
end;
-- but the table I really want to do has many columns so I want to dynamically build list of columns for the
-- returning clause. This way if the table changes the stored proc will not have to be modified
-- fails PLS-00429: unsupported feature with RETURNING clause
declare
type aat is table of t%rowtype;
aay aat;
s varchar2(4000);
begin
s := 'delete from t returning rn,pad into :1';
execute immediate s returning bulk collect into aay;
rollback;
end;
-- tried a few other things:
create or replace type t_obj as object (rn number,pad varchar2(10));
-- PLS-00497: cannot mix between single row and multi-row (BULK) in INTO list
declare
nt t_obj;
s varchar2(4000);
begin
s := 'delete from t returning t_obj(rn,pad) into :1';
execute immediate s returning bulk collect into nt;
rollback;
end;
-- works, but would require store proc changes if the table changes
declare
type t is table of number;
type v is table of varchar2(10);
vt v;
nt t;
s varchar2(4000);
begin
s := 'update t set rn = 10 returning rn,pad into :1,:2';
execute immediate s returning bulk collect into nt,vt;
rollback;
end;
/basically I want to dynamically build the list of columns with all_tab_cols and put the list into the returning clause
but seems like I will have to hard code the column lists. This means whenever the table changes I will have to
modify the store proc .. Any way around this?
ThanksAnd with object type you were almost there. You forgot to create table of objects type:
SQL> create or replace type t_obj as object (rn number,pad varchar2(10));
2 /
Type created.
SQL> declare
2 type aat is table of nt;
3 aay aat;
4 s varchar2(4000);
5 begin
6 s := 'delete from t returning
SQL> declare
2 type aat is table of t_obj;
3 aay aat;
4 s varchar2(4000);
5 begin
6 s := 'delete from t returning t_obj(rn,pad) into :1';
7 execute immediate s returning bulk collect into aay;
8 rollback;
9 end;
10 /
PL/SQL procedure successfully completed.
SQL> SY. -
Get entity as return of collection in entity framework
how to get entity as return of collection in entity framework,,, i dont have any idea...
when i select entity and then get column information then no column return .....The way the Oracle provider works right now requires that you use a cursor, even if you want to map it to an entity. To map it to an entity, that cursor needs to contain the necessary columns to form the entity (ie: it's returning data from the same table).
Here's an example from one I have mapped:
CREATE OR REPLACE PROCEDURE ENVMSTR.P_ORG_UNIT_R_BY_STAFF
STAFF_ID_P IN NUMBER
, RESULT_CURSOR_P OUT SYS_REFCURSOR
) AS
BEGIN
OPEN RESULT_CURSOR_P FOR
select *
from dept_organizational_unit d
where deptorgunit_cd = (select deptorgunit_cd from staff where staff_id = STAFF_ID_P)
or deptorgunit_cd in ( select deptorgunitrel_parent_cd from dept_org_unit_relation
start with deptorgunitrel_child_cd = (select deptorgunit_cd from staff where staff_id = STAFF_ID_P)
connect by prior deptorgunitrel_parent_cd = deptorgunitrel_child_cd);
END P_ORG_UNIT_R_BY_STAFF;
web.config:
<add name="ENVMSTR.P_ORG_UNIT_R_BY_STAFF.RefCursor.RESULT_CURSOR_P" value="implicitRefCursor bindinfo='mode=Output'" />
With those things set up, I'm able to import the function and map it to the entity that represents the dept_organizational_unit table (that entity is called OrgUnit in the model, but it doesn't really matter what you call it). The interesting thing I found is that in this situation I didn't actually have to add config file entries for each column in the cursor, probably because it maps perfectly to the entity. If I was trying to use a complex type instead then I probably would (and the configuration required to do that gets horrific in a hurry). -
Why does iTunes U site manager log me out when returning to collection manager?
So here's the problem ... kind of a weird thing has been happening lately with Site Manager. When I click on the feed of a collection to interact with the actual content (change the order, correct a typo etc.) and then click to return to collections manager, the site logs me out. When I log back in, it won't let me go back into the collection and gives an error message saying that the collection is unavailable because someone is already logged in to it. When I wait an hour or so, I can access the collection feed again but once I return to collections manager, I get logged out. I have tried this on different versions of Safari and in Lion with the same results. It is just in the last couple of weeks that this has been happening. Any ideas?
You are welcome, WonderProfessor.
Updating iTunes may not be the reason at all. It could very well be the Support Team has fixed the problem, which i think is the case.
Also, I learned i should report EACH problem to iTunes U Support Team using its Report Form:
https://ssl.apple.com/support/itunes-u/public-site-manager/contact.html
I used the Report Form a couple of months ago to report a different problem. One tech support person responsded and I have been emailing to that individual via email about a few more issues since then. This, however, is NOT a good practice. Reporting each problem using the report form will help the iTunes Support Team to prioritize the work based on urgency.
Anyway, I am releaved it is working now. Thank you. And thanks to the iTunes U Support Team and iTunes U Editors.
Q. Wang -
Please help with an embedded query (INSERT RETURNING BULK COLLECT INTO)
I am trying to write a query inside the C# code where I would insert values into a table in bulk using bind variables. But I also I would like to receive a bulk collection of generated sequence number IDs for the REQUEST_ID. I am trying to use RETURNING REQUEST_ID BULK COLLECT INTO :REQUEST_IDs clause where :REQUEST_IDs is another bind variable
Here is a full query that use in the C# code
string sql = "INSERT INTO REQUESTS_TBL(REQUEST_ID, CID, PROVIDER_ID, PROVIDER_NAME, REQUEST_TYPE_ID, REQUEST_METHOD_ID, " +
"SERVICE_START_DT, SERVICE_END_DT, SERVICE_LOCATION_CITY, SERVICE_LOCATION_STATE, " +
"BENEFICIARY_FIRST_NAME, BENEFICIARY_LAST_NAME, BENEFICIARY_DOB, HICNUM, CCN, " +
"CLAIM_RECEIPT_DT, ADMISSION_DT, BILL_TYPE, LANGUAGE_ID, CONTRACTOR_ID, PRIORITY_ID, " +
"UNIVERSE_DT, REQUEST_DT, BENEFICIARY_M_INITIAL, ATTENDING_PROVIDER_NUMBER, " +
"BILLING_NPI, BENE_ZIP_CODE, DRG, FINAL_ALLOWED_AMT, STUDY_ID, REFERRING_NPI) " +
"VALUES " +
"(SQ_CDCDATA.NEXTVAL, :CIDs, :PROVIDER_IDs, :PROVIDER_NAMEs, :REQUEST_TYPE_IDs, :REQUEST_METHOD_IDs, " +
":SERVICE_START_DTs, :SERVICE_END_DTs, :SERVICE_LOCATION_CITYs, :SERVICE_LOCATION_STATEs, " +
":BENEFICIARY_FIRST_NAMEs, :BENEFICIARY_LAST_NAMEs, :BENEFICIARY_DOBs, :HICNUMs, :CCNs, " +
":CLAIM_RECEIPT_DTs, :ADMISSION_DTs, :BILL_TYPEs, :LANGUAGE_IDs, :CONTRACTOR_IDs, :PRIORITY_IDs, " +
":UNIVERSE_DTs, :REQUEST_DTs, :BENEFICIARY_M_INITIALs, :ATTENDING_PROVIDER_NUMBERs, " +
":BILLING_NPIs, :BENE_ZIP_CODEs, :DRGs, :FINAL_ALLOWED_AMTs, :STUDY_IDs, :REFERRING_NPIs) " +
" RETURNING REQUEST_ID BULK COLLECT INTO :REQUEST_IDs";
int[] REQUEST_IDs = new int[range];
cmd.Parameters.Add(":REQUEST_IDs", OracleDbType.Int32, REQUEST_IDs, System.Data.ParameterDirection.Output);
However, when I run this query, it gives me a strange error ORA-00925: missing INTO keyword. I am not sure what that error means since I am not missing any INTOs
Please help me resolve this error or I would appreciate a different solution
Thank youIt seems you are not doing a bulk insert but rather an array bind.
(Which you will also find that it is problematic to do an INSERT with a bulk collect returning clause (while this works just fine for update/deletes) :
http://www.oracle-developer.net/display.php?id=413)
But you are using array bind, so you simply just need to use a
... Returning REQUEST_ID INTO :REQUEST_IDand that'll return you a Rquest_ID[]
see below for a working example (I used a procedure but the result is the same)
//Create Table Zzztab(Deptno Number, Deptname Varchar2(50) , Loc Varchar2(50) , State Varchar2(2) , Idno Number(10)) ;
//create sequence zzzseq ;
//CREATE OR REPLACE PROCEDURE ZZZ( P_DEPTNO IN ZZZTAB.DEPTNO%TYPE,
// P_DEPTNAME IN ZZZTAB.DEPTNAME%TYPE,
// P_LOC IN ZZZTAB.LOC%TYPE,
// P_State In Zzztab.State%Type ,
// p_idno out zzztab.idno%type
// IS
//Begin
// Insert Into Zzztab (Deptno, Deptname, Loc, State , Idno)
// Values (P_Deptno, P_Deptname, P_Loc, P_State, Zzzseq.Nextval)
// returning idno into p_idno;
//END ZZZ;
//Drop Procedure Zzz ;
//Drop Sequence Zzzseq ;
//drop Table Zzztab;
class ArrayBind
static void Main(string[] args)
// Connect
string connectStr = GetConnectionString();
// Setup the Tables for sample
Setup(connectStr);
// Initialize array of data
int[] myArrayDeptNo = new int[3]{1, 2, 3};
String[] myArrayDeptName = {"Dev", "QA", "Facility"};
String[] myArrayDeptLoc = {"New York", "Chicago", "Texas"};
String[] state = {"NY","IL","TX"} ;
OracleConnection connection = new OracleConnection(connectStr);
OracleCommand command = new OracleCommand (
"zzz", connection);
command.CommandType = CommandType.StoredProcedure;
// Set the Array Size to 3. This applied to all the parameter in
// associated with this command
command.ArrayBindCount = 3;
command.BindByName = true;
// deptno parameter
OracleParameter deptNoParam = new OracleParameter("p_deptno",OracleDbType.Int32);
deptNoParam.Direction = ParameterDirection.Input;
deptNoParam.Value = myArrayDeptNo;
command.Parameters.Add(deptNoParam);
// deptname parameter
OracleParameter deptNameParam = new OracleParameter("p_deptname", OracleDbType.Varchar2);
deptNameParam.Direction = ParameterDirection.Input;
deptNameParam.Value = myArrayDeptName;
command.Parameters.Add(deptNameParam);
// loc parameter
OracleParameter deptLocParam = new OracleParameter("p_loc", OracleDbType.Varchar2);
deptLocParam.Direction = ParameterDirection.Input;
deptLocParam.Value = myArrayDeptLoc;
command.Parameters.Add(deptLocParam);
//P_STATE -- -ARRAY
OracleParameter stateParam = new OracleParameter("P_STATE", OracleDbType.Varchar2);
stateParam.Direction = ParameterDirection.Input;
stateParam.Value = state;
command.Parameters.Add(stateParam);
//idParam-- ARRAY
OracleParameter idParam = new OracleParameter("p_idno", OracleDbType.Int64 );
idParam.Direction = ParameterDirection.Output ;
idParam.OracleDbTypeEx = OracleDbType.Int64;
command.Parameters.Add(idParam);
try
connection.Open();
command.ExecuteNonQuery ();
Console.WriteLine("{0} Rows Inserted", command.ArrayBindCount);
//now cycle through the output param array
foreach (Int64 i in (Int64[])idParam.Value)
Console.WriteLine(i);
catch (Exception e)
Console.WriteLine("Execution Failed:" + e.Message);
finally
// connection, command used server side resource, dispose them
// asap to conserve resource
connection.Close();
command.Dispose();
connection.Dispose();
Console.WriteLine("Press Enter to finish");
Console.ReadKey();
} -
Invoking PL/SQL Stored Procedure and returning a collection
Hi...
I want to return from PLSQL stored procedure a collection (like bulk collections) .
TYPE tt_number IS TABLE OF NUMBER(20,2) INDEX BY BINARY_INTEGER;
procedure prueba( p_collection out tt_number )
is
begin
select code
bulk collection into p_collection
from myTable;
end
How I can do this? How can read this collections in java?
thanks..Hope this link will work for you:
http://www.onjava.com/pub/a/onjava/2003/08/13/stored_procedures.html
Answer provided by http://www.consultoriajava.com -
How do we call a function returning a collection from package
Dear Member,
i have a package spec whose code is as follows:
create or replace package c_test as
procedure main;
TYPE JOURNAL_HEADER_TYPE IS TABLE OF NUMBER;
l_header JOURNAL_HEADER_TYPE := JOURNAL_HEADER_TYPE();
TYPE JOURNAL_SOURCE_TYPE IS TABLE OF VARCHAR2(255);
l_source JOURNAL_SOURCE_TYPE := JOURNAL_SOURCE_TYPE();
FUNCTION JOURNAL_SOURCE_STRING(P_SOURCE_STRING IN VARCHAR2)
RETURN JOURNAL_SOURCE_TYPE;
FUNCTION JOURNAL_HEADER_STRING(P_HEADER_STRING IN VARCHAR2)
RETURN JOURNAL_HEADER_TYPE;
end main;
I have a package body in which i am trying to call the above functions in the procedure main:
SELECT COUNT(*)
INTO l_je_header_id_count
FROM ( select c_charge.je_header_id je_header_id
from dual)
WHERE je_header_id IN (select * from THE ( SELECT CAST(JOURNAL_HEADER_STRING(P_JOURNAL_HEADER_ID) AS JOURNAL_HEADER_TYPE ) FROM dual ))
if i try to compile the package its giving me ORA-00902: invalid datatype error. How do i remove this error.
If i create both "Type" and "Function" separately outside package then the above sql works perfectly.
Please correct me if am doing any thing wrong here.
ThanksHi,
The collection type that you declared local to the pl/sql procedure/ package and is not visible to SQL.
If you want to use the collection in your sql, you need to create it as a SQL Type and then use it in your queries.
Thanks.
Rajesh. -
Please help with the query (INSERT RETURNING BULK COLLECT INTO)
I am trying to write a query inside the C# code where I would insert values into a table in bulk using bind variables. But I also I would like to receive a bulk collection of generated sequence number IDs for the REQUEST_ID. I am trying to use RETURNING REQUEST_ID BULK COLLECT INTO :REQUEST_IDs clause where :REQUEST_IDs is another bind variable
Here is a full query that use in the C# code
INSERT INTO REQUESTS_TBL(REQUEST_ID, CID, PROVIDER_ID, PROVIDER_NAME, REQUEST_TYPE_ID, REQUEST_METHOD_ID, SERVICE_START_DT, SERVICE_END_DT, SERVICE_LOCATION_CITY, SERVICE_LOCATION_STATE, BENEFICIARY_FIRST_NAME,
BENEFICIARY_LAST_NAME, BENEFICIARY_DOB, HICNUM, CCN, CLAIM_RECEIPT_DT, ADMISSION_DT, BILL_TYPE,
LANGUAGE_ID, CONTRACTOR_ID, PRIORITY_ID, UNIVERSE_DT, REQUEST_DT, BENEFICIARY_M_INITIAL,
ATTENDING_PROVIDER_NUMBER, BILLING_NPI, BENE_ZIP_CODE, DRG, FINAL_ALLOWED_AMT, STUDY_ID, REFERRING_NPI)
VALUES
(SQ_CDCDATA.NEXTVAL, :CIDs, :PROVIDER_IDs, :PROVIDER_NAMEs, :REQUEST_TYPE_IDs,
:REQUEST_METHOD_IDs, :SERVICE_START_DTs, :SERVICE_END_DTs, :SERVICE_LOCATION_CITYs,
:SERVICE_LOCATION_STATEs, :BENEFICIARY_FIRST_NAMEs, :BENEFICIARY_LAST_NAMEs, :BENEFICIARY_DOBs,
:HICNUMs, :CCNs, :CLAIM_RECEIPT_DTs, :ADMISSION_DTs, :BILL_TYPEs, :LANGUAGE_IDs,
:CONTRACTOR_IDs, :PRIORITY_IDs, :UNIVERSE_DTs, :REQUEST_DTs, :BENEFICIARY_M_INITIALs,
:ATTENDING_PROVIDER_NUMBERs, :BILLING_NPIs, :BENE_ZIP_CODEs, :DRGs, :FINAL_ALLOWED_AMTs,
:STUDY_IDs, :REFERRING_NPIs) RETURNING REQUEST_ID BULK COLLECT INTO :REQUEST_IDs
However, when I run this query, it gives me a strange error ORA-00925: missing INTO keyword. I am not sure what that error means since I am not missing any INTOs
Please help me resolve this error or I would appreciate a different solution
Thank youYou cannot use (and do not want to in this case) the BULK COLLECT.
create table for_testing
the_id number not null primary key,
some_data number
declare
l_return_value for_testing.the_id%type;
begin
4
insert into for_testing
the_id,
some_data
values
1,
5
returning the_id into l_return_value;
dbms_output.put_line('the return values is ' || l_return_value);
end;
20 /
the return values is 1
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.02
TUBBY_TUBBZ?Is a simple example. In the future, please use the tags to preserve formatting on your code like i have so it remains readable . -
Fetch Data or Return as Collection
Hi ,
I have a Java interface which needs a large set of data ,say 7000 records at a time.All the details can be fetched by using a single query joining may be 6 tables with outer joins.
Is it good to write a stored procedure and return these data as collelction. or let the java program do the query and fetch this chunk of data from database.These has to be set to xml using JaxB.
The aspects which we have to think off are
1.Performance
2.Network Traffic
3.Mainainability.
Please advice,
Thanks in Advance
SSNThe following link may be useful as I think it pertains directly to your question:
[AskTom: Using Oracle collections and result sets|http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1058232381458]
HTH! -
Reply Output - how do you return a collection?
I have a simple BPEL process that accepts an id, uses that id to query a sql server db, get the result set (collection). I need this BPEL process or service to then pass back the collection. I am new to all this and do not see how I can set the reply output to be the collection (all fields in the query) not just a select field. Please give me some ideas on this, most likely simple question.
With BPEL and/or SOA Suite in a web services environment, you always return XML messages. You do not work with collections. You could query a list of records, that will be return as a XML message containg a list of records.
Think that you always work with XML messages.
Marc
http://orasoa.blogspot.com -
Returning a collection of data
Hi all,
Took me ages to finally post this cause the forum server seems to be having problems.
I want to do a query in a function then return a series of results back to the calling process. Can someone tell me what is the best method of doing this?
Nested table? Table of Records? VArray (even though I don't think I could use it due to its inability to dynamically increase in capacity).
Can someone also suggest which method is best for returning a one column series of data and more than one column?
And finally, does such a thing as a Table of Records actually exist as a storage method thats passable by functions/paramaters?
Many many thanks!I'll answer your original question.
If your return type is know beforehand then you can create a type for each row and for a table of that row.
(Declare these in your package spec so that the calling PL/SQL can reference the types!)
E.g.:
type ty_person is record
( person_id pls_integer
, first_name varchar2(100)
, last_name varchar2(100)
, date_of_birth date
Then create a table type
type ty_person_t is table of ty_person index by binary_integer;
Then you can reference this in your procedure
function f_get_people_older_than(X_age in pls_integer) return ty_person_t;
The calling proc would then be:
declare
X_people mods_people_package.ty_person_t;
begin
X_people := mods_people_package.f_get_people_older_than(30);
end;
Hope this helps..
Chris -
Hi All,
I'm hoping i have just made a simple error / change and not noticed, however at the moment and not for all Collections, i am having issues with Membership.
Problem:
Adding a Computer Object into an AD Group and using a Membership Query (Of the AD Group) to add members to a collection will not work.
Info:
I have added a PC to an AD Group "MS Office 2010", forced AD Group Discovery, made a Query and run it to test (Works, shows the member) and added the query to the Membership Rules Tab (Add Rule > Query Rule > Import Query)
If i then "Update Membership" and/or refresh the collection membership it still does not appear, thus not receiving the software i have advertised to it.
Any assistance would be greatly appreciated.
BrandonSince this is CM07, it will take a while for new groups to be populated. If I remember right you MUST do the following in the following order.
Create the group and add members
Wait for AD replication to happened
Reboot the computers
Force AD group discovery to happen
Force Heartbeat discovery to happen
Create/ force the collection membership to up
Run the machine policies
If you use direct membership rule of the security Group:
Create the group and add members
Wait for AD replication to happened
Force AD group discovery to happen
Create/ force the collection membership to up
Reboot the computers (anytime after step 2)
Machine policies should run automatically
BTW, in CM12 this process has change and it now take ~2 minutes an applciaiton to show on on the computer.
Create the group and add members
Wait for AD replication to happened
Force AD group discovery to happen
Create/ force the collection membership to up
Run the machine policies
Garth Jones | My blogs: Enhansoft and
Old Blog site | Twitter:
@GarthMJ -
Trying to retrieve list of rooms using EWS Managed API but it returned empty collection
Hi,
I'm trying to retrieve list of rooms using EWS Managed API. Before I have tried the following code I make sure our Administrator put all the rooms in a list following link https://technet.microsoft.com/en-us/library/ee633471%28v=exchg.141%29.aspx.
Here is the simple code I have used :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Exchange.WebServices.Data;
using System.Net;
using System.Security;
namespace ExchangeConsole1
class Program
static void Main(string[] args)
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.Credentials = new NetworkCredential("username", "Password1", "domain");
service.Url = new Uri("https://email.xxxx.com/ews/exchange.asmx");
EmailMessage email = new EmailMessage(service);
EmailAddressCollection listOfRoomList = service.GetRoomLists();
// Display the individual rooms.
foreach (EmailAddress address in listOfRoomList)
Console.WriteLine("Email Address: {0}", address.Address);
service.GetRoomLists() results "Enumeration yielded no results". Could anybody help me please ?
Thanks
SandipanEnable tracing and see what the response from the server looks like. Also depending on your setup and how long ago your administrator created the list, it may take some
time to replicate.
Administrator has done it one week ago. Here is the trace response I am getting
<Trace Tag="EwsResponse" Tid="9" Time="2015-04-10 15:36:37Z" Version="15.00.0847.030">
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo MajorVersion="15" MinorVersion="0" MajorBuildNumber="995" MinorBuildNumber="31" Version="V2_15" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<m:GetRoomListsResponse ResponseClass="Success" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:ResponseCode>NoError</m:ResponseCode>
<m:RoomLists />
</m:GetRoomListsResponse>
</s:Body>
</s:Envelope>
</Trace>
It's say no error. Any help ?
Thanks
Sandipan -
Should Collections be used as return types across threads?
I am wondering when, if ever, it is appropriate to use a Collection as the return type of a method in a multi-threaded environment. Here is our situation:
We have four classes -- Widget, WidgetManager, ClientA, and ClientB. ClientA and ClientB are running in different Threads from each other and from the WidgetManager.
The WidgetManager class that uses a Collection of Widgets internally, and passes the Collection (or an Iterator over it) out as a return value of a method to ClientA, which is running in another thread. ClientA would start to go through it using next() and hasNext() of the Iterator. If the WidgetManager were to get a request from ClientB running in another thread to eliminate a Widget, it would attempt to remove it from the Collection. If ClientA were still looping through the Iterator, this would throw an IllegalStateException b/c the system would be in an inconsistent state. The Iterator given to the ClientA is directly linked to the actual Collection in the WidgetManager (am I right so far?).
In my opinion, in most cases we don't want to synchronize Collections. In the example above, if we had passed out a synchronized Collection, then the WidgetManager couldn't touch the collection while the client was looping through the Iterator. If the client got hung up while looping, then the WidgetManager would be hung up. In this case, I think that it will be better to use the toArray() method of Collection to just dump out the contents to a plain array of Objects. Actually, the WidgetManager could convert this array of Objects to an array of Widgets before passing it out, which would give us the type checking that we don't get with Containers.
The condition where you would want to use a synchronized Collection would be when you actually want the client to do some writing or removing from the Collection. I would expect this to be pretty rare since you usually dont want to give clients access to an interal member (the Collection) of a class.
I think that it is also possible to have read-only Collections, but I think (don't know for sure) that you would still have the same IllegalStateException or synchronization probelms.
Can someone point out the errors in my thinking? Or should you generally only use Collections as internal members in a multi-threaded environment, and use toArray() whenever you want to pass the Collection's data outside of the class?
Thanks for any help.
KeithI haven't tested what happens when you synchronize the
Collection, but I think that you are right. But this
causes the problem that I mentioned in the first post.
That is, what happens if your client STARTS running
through the Iterator, and then stops or gets hung up
for some reason? I assume that you're still blocked.
And it's pretty important to me in this case to not
t be blocked -- WidgetManager is the highest level
class in the system.
I'd like to know if anyone has tested this.
The Iterator implementations used in java.util do not use any synchronization by itself, (which is what you would expect since synchronization over multiple method call will involve much more complications and slower performance) . With iterator, you have to provide the necessary synchronization yourself to maintain thread-safety like this
Iterator itr = get Iterator from collectionInstance ;
synchronized(collectionInstance) {
while(itr.hasNext())
process itr.next() ...
As long as your client code gracefully exits the synchronized block on a stop( or hangup, given that it is detected and handled fast enough), it will not be a problem.
Also, I'd like an example of when you WOULD want to
return a Collection. I'm specifically interested in
when you would want to return one in a multi-threaded
environment, but I'm beginning to wonder when you
would EVER want to return one from a method.
Collections are great for internal uses, but you lose
type-checking and you expose the internals of your
class to modification when you use them as return
types. And if you're returning a read-only
Collection, you might as well return an array, right?Using a read-only proxy will be much faster and space-efficient than toArray().
Maybe you are looking for
-
'Structure Changed' Error when running a query
Hi, I created a query with 2 structures. One structure for the time periods and one with Key figures (Calc and Restricted). The query ran fine and subsequently I put this into a workbook which had other queries and made a workbook type report. I modi
-
My time capsule will not connect to the internet.
Please help. Just purchased a brand new 2T airport time capsule for my MacBook Pro and my other apple devices. I have the ethernet cable plugged into the TC and into my Westell modem, in the correct jacks. There is a green light on the connection
-
My MBP has been acting odd since installing N wireless update.
Since installing the N wireless protocol on my MBP my machine has been acting weird. It fails to see wireless networks, the system preferences fails to open at times. OSX freezes, Force quit doesn't actually quit the programs after they have frozen.
-
Was working many mos. ago when I needed to use it but not now - so I know I'm overlooking something simple. If I remember correctly, I wasn't able to see the G3 from the G5, only the G5 from the G3 - but whatever, it worked. (May have that backwards,
-
From Sony Ericsson to iPhone 5 contacts data transfer.
Hello! I have a Sony Ericsson C905a. ATT client. Need to transfer phone book with every things related to each Phone number : address, DOB e mail address, etc. To iPhone 5. What would be the easy way to do that ? Thank you! Igor.