Multiple row return in Procedure
I am trying to convert a SQL Server to Oracle 8i. They have a bunch of procedures that return multiple rows. How can this be handled in Oracle?
In Oracle this is done by using collections. It is really only viable if you are creating packages out of the procedures since you will need to define the type definitions prior to defining the procedure. Here are some hints and a link:
TYPE rec IS RECORD OF something ;
TYPE tab IS TABLE OF rec ;
PROCEDURE getTable (
p_table_output OUT tab )
http://technet.oracle.com/doc/oracle8i_816/appdev.816/a77069/04_colls.htm#1059
Similar Messages
-
Question:
There is a scenario that users want to send multiple rows returned by Execute SQL Task as Email content to send to someone. With Execute SQL Task, the Full result set is used when the query returns multiple rows, it must map to a variable of the Object data
type, then the return result is a rowset object, so we cannot directly send the result variable as Email content. Is there a way that we can extract the table row values that are stored in the Object variable as Email content to send to someone?
Answer:
To achieve this requirement, we can use a Foreach Loop container to extract the table row values that are stored in the Object variable into package variables, then use a Script Task to write the data stored in packages variables to a variable, and then set
the variable as MessageSource in the Send Mail Task.
Add four variables in the package as below:
Double-click the Execute SQL Task to open the Execute SQL Task Editor, then change the ResultSet property to “Full result set”. Assuming that the SQL Statement like below:
SELECT Category, CntRecords
FROM [table_name]
In the Result Set pane, add a result like below (please note that we must use 0 as the result set name when the result set type is Full result set):
Drag a Foreach Loop Container connects to the Execute SQL Task.
Double-click the Foreach Loop Container to open the Foreach Loop Editor, in the Collection tab, change the Enumerator to Foreach ADO Enumerator, then select User:result as ADO object source variable.
Click the Variable Mappings pane, add two Variables as below:
Drag a Script Task within the Foreach Loop Container.
The C# code that can be used only in SSIS 2008 and above in Script Task as below:
public void Main()
// TODO: Add your code here
Variables varCollection = null;
string message = string.Empty;
Dts.VariableDispenser.LockForWrite("User::Message");
Dts.VariableDispenser.LockForWrite("User::Category");
Dts.VariableDispenser.LockForWrite("User::CntRecords");
Dts.VariableDispenser.GetVariables(ref varCollection);
//Format the query result with tab delimiters
message = string.Format("{0}\t{1}\n",
varCollection["User::Category"].Value,
varCollection["User::CntRecords"].Value
varCollection["User::Message"].Value = varCollection["User::Message"].Value + message;
Dts.TaskResult = (int)ScriptResults.Success;
The VB code that can be used only in SSIS 2005 and above in Script Task as below, please note that in SSIS 2005, we should
change PrecompileScriptIntoBinaryCode property to False and Run64BitRuntime property to False
Public Sub Main()
' Add your code here
Dim varCollection As Variables = Nothing
Dim message As String = String.Empty
Dts.VariableDispenser.LockForWrite("User::Message")
Dts.VariableDispenser.LockForWrite("User::Category")
Dts.VariableDispenser.LockForWrite("User::CntRecords")
Dts.VariableDispenser.GetVariables(varCollection)
'Format the query result with tab delimiters
message = String.Format("{0}" & vbTab & "{1}" & vbLf, varCollection("User::Category").Value, varCollection("User::CntRecords").Value)
varCollection("User::Message").Value = DirectCast(varCollection("User::Message").Value,String) + message
Dts.TaskResult = ScriptResults.Success
End Sub
Drag Send Mail Task to Control Flow pane and connect it to Foreach Loop Container.
Double-click the Send Mail Task to specify the appropriate settings, then in the Expressions tab, use the Message variable as the MessageSource Property as below:
The final design surface like below:
References:
Result Sets in the Execute SQL Task
Applies to:
Integration Services 2005
Integration Services 2008
Integration Services 2008 R2
Integration Services 2012
Integration Services 2014
Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.Thanks,
Is this a supported scenario, or does it use unsupported features?
For example, can we call exec [ReportServer].dbo.AddEvent @EventType='TimedSubscription', @EventData='b64ce7ec-d598-45cd-bbc2-ea202e0c129d'
in a supported way?
Thanks! Josh -
How to run a select count(*) with multiple rows returned
Hi,
I have to run a select count(*) for different reports.
1) Select count(*) from table
where state = 'CA'
2) Select count(*) from table
where state = 'NY'
3) Select count(*) from table
where state = 'NV'
Instead of running this query again for 50 times, is there a way for me to just put it in one query and get multiple row returns? Thank you.Samantha wrote:
Hi,
I have to run a select count(*) for different reports.
1) Select count(*) from table
where state = 'CA'
2) Select count(*) from table
where state = 'NY'
3) Select count(*) from table
where state = 'NV'
Instead of running this query again for 50 times, is there a way for me to just put it in one query and get multiple row returns? Thank you.select state, count(*) from table group by state order by 1; -
Datatype-Name for multiple rows return
Hi
If I return multiple rows says ex:100 rows then what will be data type for that return values...Using PL/SQL Collections and Records
Using Ref Cursors To Return Recordsets -
Retreiving multiple rows with stored procedures
Hi,
I'm having a little problem over here. I need to retreive some data (from an oracle db) via stored procedures. But I don't know how I can retreive multiple rows because when I execute a stored procedure which gives more dan 1 row back, Jave throws an exception.
If someone could show me an example (or url) from how it should be done, it will be very much appreciated :-)
Thanks in advance.A collection of (mostly) fully working example programs is provided by Oracle.
http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/index.html
I think what you're looking for it the RefCursor example, under "JDBC Basic Samples" -
DB get step: managing multiple row returned from a table
Hi,
please can someone tell me if it is possible to manage multiple row when returned in a db get step?
For example, I execute a SELECT in db read step to read an SQL table which returns two rows. From each row I get two string variables, let's say: "Var1", "Var2".
Assigning them to local variables, I am able to assign just the 2 variables of the first row, not the variables of the second row.
I tried to use array as local variables with not success, how can I do?
Thanksmmaddalena,
You have two options, you can pre populate, or work row by row.
Prepopulate:
String[] Var1
int row
DBGet Loop:
DBGet
Successful:
save to Var1[row]
increment row
Goto DBGet Loop
No data:
/* this is the last row */
Goto After DB Get Loop
After DB Get Loop:
/* do whatever with the data */
Conversely:
Row by row:
String Var 1
int row
DBGet Loop:
DBGet
Successful:
/* do whatever with the data */
Increment row
Goto DBGet Loop
No data:
/* no more data (last row) */
Goto After DB Get Loop
After DB Get Loop:
/* do whatever after your done with the data */ -
Cursor error,multiple rows returned
I am having error as given below.
please guide me
===================================================================
anonymous pl/sql block for table 'gpn_change' & for column 'gpn_id'
declare
cursor cur_gpn_change is
select * from gpn_change for update;
m number(20);
n number(20);
begin
for r1 in cur_gpn_change
loop
select unique_id into n from geographic_place_name;
if r1.gpn_id=n then
select max(r1.unique_id) into m from gpn_change;
update geographic_place_name set change_id=m where current of cur_gpn_change;
end if;
end loop;
end;
ERROR at line 1:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at line 9select max(r1.unique_id) into m from gpn_change;M is a scalar (single value) while SELECT returns 2 or more values & therefore the error
-
Passing multiple rows from one action to another
Hi,
I've build a Guided Procedure Process with two actions. Both actions call a Visual Composer Model (deployed as Flex).
The Processdesign is:
Process
---Block
Action 1
CO 1 as VC Model (Flex)
Action 2
CO 2 as VC Model (Flex)
From the first vc model I want to pass multiple rows (its a vc table) to the second vc model. Therefor I've group the out-going parameters from model 1 with the in-coming parameters from model 2 at the block-level.
Now, when I start my process I have two results in the table of vc model 1 and will pass them to model 2. But only one record (always the first) is shown at model 2.
Can you say me the reason for this? Have I configured the parameter-grouping false? Or isn't it possible to pass multiple rows at guided procedures?
I'm using Visual Composer 7.0 and Guided Procedures 7.0 technology.
Thanks in advance
Claudiahi,
Do structure mapping to pass row values
Thanks
Gopal -
Single Update command to update multiple rows with multiple rows
Hi Gurus!
Can I update table A with a result set of table b (multiple rows returns) where a.c1 = b.c1
regards,
SHAs Joel mentioned this update will update all rows in a table based on another one:
update tableA set seq_no = (select seqno from tableB where tableA.ID = tableB.ID)
Also, any rows that don't match the select criteria will get updated to null. This could be very bad depending on what you want to do.
To update a subset of tableA with data from tableB:
update tableA set seq_no = (select seqno from tableB where tableA.ID = tableB.ID)
where exists (select 1 from tableB where tableA.ID = tableB.ID) -
The simplest way for plsql procedure to return multiple rows
Hi,
What is the simplest way for plsql procedure to return multiple rows (records). There are many combination of ways to do it but I am looking for a solution that is appropriate for plsql beginners. Many solutions use cursors, cursor variables, collections and more that kind of things that are complex on the face of it. Is it somehow possible to achieve the same with less effort?
Sample query would be: SELECT * FROM EMPLOYEES;
I want to use returned rows in APEX to compose APEX SQL(in that context plsql) report.
It is enough to use just SELECT * FROM EMPLOYEES query in APEX but I want to use plsql procedure for that.
Thank you!Hi,
It depends :-).
With +...that is appropriate for plsql beginners...+ in mind... it still depends!
The list of techniques (ref cursors, cursor variables, collections, arrays, using explict SQL) you have referenced in your post can be made to work. but...
+Is it somehow possible to achieve the same with less effort?+ Less effort : That needs to be defined (measured). Especially in the context of pl/sql beginners (who is a beginner?) .
What is the level of "programming experience" ?
What is the level of understanding of "Relational Result set" as processible in Oracle?
If you are looking for
Process_the_set_of rows_in APEX () kind of capabilitywhich "abstracts/hides" relation database from developers when working on relation database, it may not be the best approach (at least strategically). Because I believe it already is abstracted enough.
I find REF CUROSOR most effective for such use, when the "begginer" has basic understanding of processing SQL result set .
So in a nut shell, the techniques (that you already are familiar with) are the tools available. I am not aware of any alternative tools (in pure Oracle) that will simplify / hide basics from develpers.
vr,
Sudhakar B. -
Procedure from PowerBuilder returning multiple rows
In want to call a procedure from PowerBuilder which return multiple rows. I would like to know how to write the procedure and also how to call it. I tried using REFCURSOR , but i heard that Powerbuilder doesnot support REFCURSOR . Please help
Thanks in advanceThis is not a PL/SQL qustion, but a Powerbuilder question.
Just what SQL constructs does Powerbuilder supports? And if there is no support for ref cursors, then the choice of using a client language that lacks basic core SQL support is questionable. -
Multiple rows to be returned from a procedure without a cursor?
We can return multiple rows using ref cursor as the return type in a procedure/function but I want to avoid processing a cursor. I would like to use the select statement on the returned multiple rows. I believe pl/sql table can not be used here also as select are not permitted on it. Is there some way to get around this defficiency in oracle?? Please help out!! My email is [email protected]
nullOracle 8i has temporary tables. As far as I know, this is your only option.
I, too, would like to be able to return a true "relation" (or "table") from a pl/sql function. Why can't I just specify the return type of the function as a "table" of "records"?
Note that if pl/sql is completely orthogonality (neat word, huh?) I should be allowed to use this function that returns a "relation" as a table in the "from" clause of a sql query.
Speaking of complete orthogonality, why can't I treat a pl/sql table just like any other table -- I should be able to query it, "insert" into it, "update" it, join it to other "tables", etc.
How about this for a slogan, "tables everywhere"? Anything, from arrays scalars to functions to arrays of classes to pl/sql tables should be able to participate in a sql statement as a "relation/table."
Anyone from Oracle listening out there? :-) -
Stored Procedure Returning Multiple Rows
Hello. Where can I find sample code from a class that calls a stored procedure that returns multiple rows?
I have a servlet that calls the DB directly from the servlet & loops through the result set. I want to put that code into a stored procedure, but I'm not sure how to loop through the results.
Your help is greatly appreciated!Surely you would call the stored procedure and loop
through the resultset as usual.
all that is different is the method by which you obtain the resultSet .
assuming CallableStatement, Connection have been
instantiated.
cstmt=con.prepareCall("{call sp_NewOfficeSurgery (?,?)}");
cstmt.setString(1,"first");
cstmt.setString(2,"second");
rs = cstmt.executeQuery();
while (rs.next())
String nme = rs.getString(1)
etc,etc
Hope this helps , Sorry If I have misinterpreted this
please let me know if my thinking is floored or you need
further clarification ect.
[email protected] -
Returning Multiple Rows From DBAdapter Calling PL/SQL Procedure
Oracle XE 10g Express Edition
JDeveloper 11.1.1.2.0
WebLogic Server 11g
Guys,
I have a table of orders, which I need to interrogate, and pass back any matching rows which meet certain criteria (e.g. status = 'OPEN').
However, rather than create a DBAdapter using an Operation Type of "Peform an Operation on a Table/Select", I need to use an Operation Type of "Call a Stored Procedure or Function".
I therefore need the procedure to return all the matching rows, rather than a single row.
I have looked at declaring return parameters for the procedure of the following types:
RECORD - is good because it allows me to return the elements of the row with their correct datatypes, but does not meet my needs because it will only support the return of a single row.
VARRAY - good because it can contain many row elements, but not good because it only supports a single row return, and also because all elements of the VARRAY must be of the same data type.
TABLE - good because it can contain many rows, but bad because each row can contain only two elements - the index element and the data element.
I think I could first define a RECORD (to hold a row), and then define a TABLE, with the data element being the RECORD, but I have found JDeveloper very fussy indeed when dealing with 'non-standard' data types in the DBAdapter.
Apologies if I am missing something obvious, but can anyone suggest a way of doing this?
Many thanks in advance.
Edited by: user2541290 on 17-Feb-2010 02:48Hi, I've been able to create process that seems to work. My platform is a but different but I don't think this is important for your question.
Here is the PL/SQL code. Just make Db Adapter for Calling stored procedure and it returns all rows!
Be aware of possible limitations on how manyrows you could return in one select! This can have severe impact on performance.
Succes.
Jos Baan
CREATE OR REPLACE PACKAGE lab2_multiple_rows IS
-- Author : 801455
-- Created : 18-2-2010 8:05:52
-- Purpose :
-- Public type declarations
TYPE rrows IS RECORD(
mutdat DATE,
opmerking VARCHAR2(20));
TYPE trows IS TABLE OF rrows INDEX BY BINARY_INTEGER;
-- Public constant declarations
-- Public variable declarations
-- Public function and procedure declarations
FUNCTION retrows RETURN trows;
END lab2_multiple_rows;
CREATE OR REPLACE PACKAGE BODY lab2_multiple_rows IS
-- Private type declarations
-- Private constant declarations
-- Private variable declarations
-- Function and procedure implementations
FUNCTION retrows RETURN trows IS
lrows trows;
lidx binary_integer := 1;
BEGIN
FOR rsql IN (SELECT t.* FROM jba_transactions t ORDER BY t.mutdat)
LOOP
lrows(lidx).mutdat := rsql.mutdat;
lrows(lidx).opmerking := rsql.opmerking;
lidx := lidx + 1;
END LOOP;
RETURN(lrows);
END;
BEGIN
-- Initialization
NULL;
END lab2_multiple_rows;
Edited by: Baan, Jos on 18-feb-2010 8:53 -
Return Code - Query for Multiple Rows as XML
Hi,
I'm executing an MSSQL stored procedure through the "Query for Multiple Rows as XML" activity in LiveCycle ES. I do this through a call statement such as this:
{ call MyStoredProc(?) }
This works great, the stored procedure always returns a record set (with or without records). I use this activity rather than "Call Stored Procedure" because I can transform the record set into XML right away within this activity. Unfortunately any exception arising from invoking this stored procedure cannot be handled within the workflow as this activity does not have an exception handler (lightning bolt). In an attempt to handle at least some exceptions we have decided to use try/catches within the stored procedures and return different error codes. Now the problem I am faced with is that there is no way to retrieve the returned code within any of the SQL activities. We don't want to have to write an execute script for each of these SQL calls. Is there any way to do this? Seems like I'm 95% there.
Thanks
NicThanks for the offer, unfortunately we would need something certified by Adobe.
Nic
Maybe you are looking for
-
Cannot update my Ipad firmware. I have internet connection and can connect to itunes store etc but when I try to update I get error message: cannot connect to ipad update server. If I run Network diagnostics I get Network interface verified green Int
-
How to get this Airport Extreme base station to produce a wireless network?
I had this Airport Extreme base station working fine at the house that I moved from a couple of days ago. After my house move, however, it seems that the AE base station isn't producing a wireless network. My wireless laptop isn't detecting a wireles
-
Tried updating my daughters iPod touch and it just turned off. It now has a picture of a white lead and says iTunes. I don't have a computer to connect it to and just want it back to normal as it will not do anything. Can anyone help me?
-
The problem persists... Submit button grayed-out
Hello guys, I'm still not able to process my videos, Compressor refuses to process our batches. I've already repaired permissions many times, deleted the entire FCP suite twice, used Compressor repair and trashed preferences several times. I don't kn
-
Hey... When I attempt to resize photos in Preview... sometimes it works, but more often it doesn't. I can try to save the image after the resize, or I've tried closing the image and forcing the Preview Save dlg box... either way... sometimes it works