URGENT : Return Bulk data from Stored Procedure
Hi,
Tell me, how do I return a bulk of data which
does not exist in the data base
but is concluded while the Stored Procedure is executed
from the Stored procedure
to the C++ program.
For Example:
Table ABC
Field1 Field2 Field3
A 1 3
B 1 5
C 2 10
Table DEF
Field1 Field2 Field3
D 10 24
E 3 16
F 8 19
SP_TESTING
Depending on the values in both the tables
for some range of conditions,
a conclusion X is derived for each range value of the
condition range.
Now I need to return this bulk of data X with the
condition they belong to
back to the C++ code calling it....
NOTE : A stored procedure is requited as there is a lot
of processing
required before we conclude the result X for each value
in the condition range.
If I execute this code from C++ instead of Stored
procedure
it is very slow and speed is a prime requirement of my
system.
Also i'm not using any MFC class to access database.
I'm using ConnectionPtr, RecordsetPtr and _CommandPtr
from msado15.dll for database access...
One solution to this could be use of Temp tables.
As this process is used by a lot of different stored
procedures having a common
temp table to all will need something like 50 NUMERIC
fields, 50 VARCHAR fields
and so on, which doesn't seem like a very good solution
to this problem.
Sounds like something I would have done while in school,
implement a dumb solution.
So, please suggest me a solution as to how do I return
bulk data in the form
of recordsets from stored procedure.
Regards
Shruti
Use Out parameter mode
SQL> CREATE OR REPLACE procedure a1 (x OUT NUMBER, y OUT NUMBER) AS
2 BEGIN
3 x:= 1;
4 y:= 2;
5 END;
6 .
SQL> /
Procedure created.
SQL> SET SERVEROUTPUT ON
SQL> DECLARE
2 a NUMBER :=3;
3 b NUMBER :=4;
4 BEGIN
5 a1 (a,b);
6 DBMS_OUTPUT.PUT_LINE( 'a = ' || a );
7 dbms_output.put_line( 'b = ' || b );
8 END;
9 .
SQL> /
a = 1
b = 2
PL/SQL procedure successfully completed.By default parameters are copied to the OUT parameter mode .
COPY hint in PLSQL don’t send a pointer to calling program unit but NOCOPY
does.
Khurram
Similar Messages
-
What is the best approach to return Large data from Stored Procedure ?
no answers to my original post, maybe better luck this time, thanks!
We have a stored proc (Oracle 8i) that:
1) receives some parameters.
2)performs computations which create a large block of data
3) return this data to caller.
compatible with both ASP (using MSDAORA.Oracle), and ColdFusion (using Oracle ODBC driver). This procedure is critical in terms of performance.
I have written this procedure as having an OUT param which is a REF CURSOR to a record containing a LONG. In order to make this work, at the end of the procedure I have to store the working buffer (an internal LONG variable) into a temp table, and then open the cursor as a SELECT from the temp table.
I have tried to open the cursor as a SELECT of the working buffer (from dual) but I get the error "ORA-01460: unimplemented or unreasonable conversion requested"
I suspect this is taking too much time; any tips about the best approach here? is there a resource with REAL examples on returning large data?
If I switch to CLOB, will it speed the process, be compatible with callers, etc ? all references to CLOB I saw use trivial examples.
Thanks for any help,
Yoram AyalonCreate a new farm in the secondary Data Center at the same patch level with the desired configuration. Replicate the databases using the method of choice (Mirroring, AlwaysOn, etc.). Create a downtime window where you can then attach the databases to the
new farm's Web Application(s)/Service Application(s).
Trevor Seward
Follow or contact me at...
  
This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs. -
Ora-06550 returning data from Stored Procedure and Entity Data Model
Hi.
I'm creating an application that uses a WCF Service to return data. I also created a proyect with the EDMX design and mapped most of my DBModel to a classes context. I have added some of the procedures as well. One of them receive some parameters and return a Sys_RefCursor, that is populated according to the parameters.
I have declared the "<add >" tags in the Web.Config and imported the function of the Procedure. When I call the Asyncronous function I get different exceptions:
1. If I call the function, with all of the parameters i get:
Oracle.DataAccess.Client.OracleException: ORA-06550: línea 1, columna 8:
PLS-00306: número o tipos de argumentos erróneos al llamar a
'SP_HECHOSJURITER'
ORA-06550: línea 1, columna 8:
(wrong number or types of arguments in call to 'SP_HECHOSJURITER')
2. If i just set 1 parameter in the SP, returning the same type of data, I get:
Error al recibir la respuesta HTTP a
http://localhost/Procalculo.CGFM.SIGOC.DatosServices/ServiceDatos.svc.
(failed to receive http response. error 12152)
3. If I don't set any parameters in the procedure, it works fine, and return correct data.
It exclusively happen with one entity.
Any clue?
I appreciate any help.When you return result sets from stored procedures to Entity Framework, you are very likely using implicit result sets. Implicit result sets don't need to be declared as a parameter in code, only in the <add> tags to define the metadata in the .NET config file.
For example, in the EF Oracle By Example, you'll see that the stored procedure in the function import has three parameters, but only two are declared in the code. The third one was defined in the config file.
http://download.oracle.com/oll/obe/EntityFrameworkOBE/EntityFrameworkOBE.htm -
Returning SQL cursor from Stored Procedure
Hi,
I have a query regarding returning sql cursor from stored procedure to java in oracle 11g.
I want to query some data ex: my query returns A, B, C. Also, now I want to query some other data ex: D, E, F. Now I want to return this data as an sql cursor as a single row . Example: A,B,C,D,E,F. Is it possible to return/create a cursor in stored procedure?
assume both query returns equal number of rows.. however both are not related to each other..RP wrote:
Hi,
I have a query regarding returning sql cursor from stored procedure to java in oracle 11g.
I want to query some data ex: my query returns A, B, C. Also, now I want to query some other data ex: D, E, F. Now I want to return this data as an sql cursor as a single row . Example: A,B,C,D,E,F. Is it possible to return/create a cursor in stored procedure?
assume both query returns equal number of rows.. however both are not related to each other..It sounds like what you need is a ref cursor.
First thing to remember though is that cursors do not hold any data (see: {thread:id=886365})
In it's simplest form you would be creating a procedure along these lines...
SQL> create or replace procedure get_data(p_sql in varchar2, p_rc out sys_refcursor) is
2 begin
3 open p_rc for p_sql;
4 end;
5 /
Procedure created.
SQL> var rc refcursor;
SQL> exec get_data('select empno, ename, deptno from emp', :rc);
PL/SQL procedure successfully completed.
SQL> print rc;
EMPNO ENAME DEPTNO
7369 SMITH 20
7499 ALLEN 30
7521 WARD 30
7566 JONES 20
7654 MARTIN 30
7698 BLAKE 30
7782 CLARK 10
7788 SCOTT 20
7839 KING 10
7844 TURNER 30
7876 ADAMS 20
7900 JAMES 30
7902 FORD 20
7934 MILLER 10
14 rows selected.
SQL> exec get_data('select deptno, dname from dept', :rc);
PL/SQL procedure successfully completed.
SQL> print rc
DEPTNO DNAME
10 ACCOUNTING
20 RESEARCH
30 SALES
40 OPERATIONS
50 IT SUPPORTWhich takes an SQL statement (as you said that both your queries were unrelated), and returns a ref cursor, and then your Java code would fetch the data using that cursor.
Now, as for getting your rows to columns and combining two queries that do that... something along these lines...
SQL> select * from x;
C
A
B
C
SQL> select * from y;
C
D
E
F
SQL> ed
Wrote file afiedt.buf
1 select x.col1, x.col2, x.col3
2 ,y.col1 as col4
3 ,y.col2 as col5
4 ,y.col3 as col6
5 from (
6 select max(decode(rn,1,col1)) as col1
7 ,max(decode(rn,2,col1)) as col2
8 ,max(decode(rn,3,col1)) as col3
9 from (select col1, rownum rn from (select * from x order by col1))
10 ) x
11 cross join
12 (
13 select max(decode(rn,1,col1)) as col1
14 ,max(decode(rn,2,col1)) as col2
15 ,max(decode(rn,3,col1)) as col3
16 from (select col1, rownum rn from (select * from y order by col1))
17* ) y
SQL> /
C C C C C C
A B C D E F... will do what you ask. For further information about turning rows to columns read the FAQ: {message:id=9360005} -
Thank you for your help!!!
I've created a stored procedure to return results as xml. I'm having trouble figuring out why I'm getting the error message "Conversion failed when converting the nvarchar value '<tr>.....'
to data type int. It seems like the system doesn't know that I'm returning a string... Or, I'm doing something that I just don't see.
ALTER PROCEDURE [dbo].[p_getTestResults]
@xml NVARCHAR(MAX) OUTPUT
AS
BEGIN
CREATE TABLE #Temp
[TestNameId] int,
[MaxTestDate] [DateTime],
[Name] [nvarchar](50),
[Duration] [varchar](10)
DECLARE @body NVARCHAR(MAX)
;WITH T1 AS
SELECT DISTINCT
Test.TestNameId
, replace(str(Test.TotalTime/3600,len(ltrim(Test.TotalTime/3600))+abs(sign(Test.TotalTime/359999)-1)) + ':' + str((Test.TotalTime/60)%60,2)+':' + str(Test.TotalTime%60,2),' ','0') as Duration
,MaxTestDate = MAX(TestDate) OVER (PARTITION BY TM.TestNameId)
,TestDate
,TM.Name
,Test.TotalTime
,RowId = ROW_NUMBER() OVER
PARTITION BY
TM.TestNameId
ORDER BY
TestDate DESC
FROM
Test
inner join TestName TM on Test.TestNameID = TM.TestNameID
where not Test.TestNameID in (24,25,26,27)
INSERT INTO #Temp
SELECT
T1.TestNameId
,T1.MaxTestDate
,T1.[Name]
,T1.Duration
FROM
T1
WHERE
T1.RowId = 1
ORDER BY
T1.TestNameId
SET @body ='<html><body><H3>TEST RESULTS INFO</H3>
<table border = 1>
<tr>
<th> TestNameId </th> <th> MaxTestDate </th> <th> Name </th> <th> Duration </th></tr>'
SET @xml = CAST((
SELECT CAST(TestNameId AS NVARCHAR(4)) as 'td'
, CAST([MaxTestDate] AS NVARCHAR(11)) AS 'td'
, [Name] AS 'td'
, CAST([Duration] AS NVARCHAR(10)) AS 'td'
FROM #Temp
ORDER BY TestNameId
FOR XML PATH('tr'), ELEMENTS ) AS NVARCHAR(MAX))
SET @body = @body + @xml +'</table></body></html>'
DROP TABLE #Temp
RETURN @xml
END
closlYour dont need RETURN inside SP as you've declared @xml already as an OUTPUT parameter. Also you can RETURN only integer values using RETURN statement inside stored procedure as that's default return type of SP.
so just remove RETURN statement and it would work fine
To retrieve value outside you need to invoke it as below
DECLARE @ret nvarchar(max)
EXEC dbo.[P_gettestresults] @ret OUT
SELECT @ret
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Displaying data from stored procedure into textbox fields based on user input.
I have a stored procedure that is selecting data from a table called "Vendor" in my database. The data that is being returned are vendor names, vendor addresses, vendor Id's, etc...In my stored proc, I have one parameter that allows
the user to enter a vendor name and then return all the data for that specific vendor. The report that I'm building is going to look like a basic form with a bunch of textboxes on the screen labeled Vendor Address, Vendor Id, Vendor City, Vendor State,
etc...In the report I'm trying to build, the user will enter in a vendor name and then it will return all of the vendor's data based on what the user searches for. However, the report will only return ONE vendor's data at a time.
The problem is that some of the data in the database has very similiar vendor names, but different vendor addresses, vendor Id's, etc...In some instances the vendor name is actually
exactly the same, but the vendor address, vendor city, vendor Id, is all different. So what I did was added another parameter in my report that shows a drop down list of vendor names based on the wildcard search the user just did and
allows the user to select the exact vendor name that he/she is looking for based on what they searched. The problem I'm having is that I don't know what expression I need to put in each one of my textboxes to retrieve the correct data from
the vendor table that the user selects from the drop down list. So what I want to do is return the exact data from the vendor table based on the selection that the user makes from that drop down list. It's like I somehow have to compare the
drop down list parameter directly to the dataset but I don't know what expression needs to go in the textbox. I've tried...=First(Fields!VendorName.Value, "DataSet1").EqualsParameters!DropDownList.Value(0) but I keep getting an error message.
--Here is an example of the kind of thing the user might search for...when the user searches the word "sprint" it returns three different vendor names to the drop down list.
1. sprint
2. sprint
3. sprint co
Each one of those three vendor names has a different vendor address, vendor city, vendor ID, etc...but the vendor names are extremely similar and in some cases
exactly the same. In my report now I can't get the textboxes to return the correct data based on what the user selects. Any advice at all is greatly appreciated.
P.S. I didn't even know what SQL Server was a month ago and had zero knowledge of SSRS at all. I've learned a lot recently, but if you could explain a solution in the easiest way possible I would appreciate it. Thanks!Hi Jrcowles,
If I understand you correctly, you wnat to list all the Vendor Name which like the user typed Vendor Name on a drop-down list, right? If in this case, we can use a cascading parameters to achieve your requirement. I have tested it on my local environment,
the steps below are for you reference.
Create an other stored procedure using the query below.
CREATE PROCEDURE GetVendorName
@VendorName NVARCHAR(50)
AS BEGIN
exec( 'SELECT * FROM Vendor WHERE VendorName LIKE ''%'+@VendorName+'%''')
END
Create another dataset DataSet2 and using the new created procedure.
Create another parameter VendorName2 and check "Allow Multiple Values" for this parameter.
On the Available Values tab, check "Get values from a query". Select corresponding dataset and field.
On the Default Values tab, check "Get values from a query". Select corresponding dataset and field.
The screenshots below are for you reference.
Reference
http://technet.microsoft.com/en-us/library/aa337169(v=sql.100).aspx
http://www.msbiguide.com/2012/02/adding-cascading-parameters-to-ssrs-reports/
Regards,
Charlie Liao
TechNet Community Support -
Web Service receives no data from Stored Procedure call.
Issue: When calling a Stored Procedure from a Web Service no data is returned.
Lead up: I can call the SP 100 times a day for 3-4 days then for some reason the Web Service no longer get the data from SQL. I have ran a trace and I can see the SP running though all of its steps and returning the data, but the Web Service
is not getting it.
Fix: None yet.
Work around: Before the Web Service calls the SP, I am sending an SP_Recompile to the SP in question. For now this seems to have resolved the issue.
Detail:
1. SP is querying data from another DB on the same server.
2. SP is storing query data in Temp Tables.Hello,
Does your Stored Procedure have parameters? If so, the issue may be cause by parameter sniffing. Please refer to the following blog about Paraemeter Sniffing:
http://www.sommarskog.se/query-plan-mysteries.html
The recommended fix for most situations is to not use parameters directly in queries, but rather store them into local variables and then use those variables in the queries.
Regards,
Fanny Liu
If you have any feedback on our support, please click here.
Fanny Liu
TechNet Community Support -
JDBC - How to Get Data from Stored Procedure?
Gurus,
I am using Oracle Thin JDBC driver. A stored procedure has an IN parameter and an OUT parameter. The type of OUT parameter is TABLE of RECORD which is defined in the PL/SQL package in which the stored procedure is included. My question is if there is any way to call this stored procedure and process the data returned by the OUT parameter in my Java code.
Thanks.
Larrydefine in the pl/sql block as a cursor
register the out parameter as an oracle.cursor
on the java program get an object (from the statement), casting it to an resultset and then you can work on it -
Accessing Data from Stored Procedure using CallableStatement
I have created a Stored Procedure as shown , IS it possible to access these data inside my JDBC Program ??
CREATE or replace PROCEDURE getEmpName(EMP_NUM IN NUMBER)
is
CURSOR C1 is select from emp ;*
C2 c1%rowtype;
BEGIN
open c1;
loop
fetch c1 into c2;
exit when c1%NOTFOuND;
end loop;
END ;
*CallableStatement cs = conn.prepareCall("{call getEmpName(?)}");*What do you mean by :
IS it possible to access these data inside my JDBC Program ??JDBC provide/helps to execute a stored proc. when we say executing a proc, it actually executes on DB. So if a proc is written which has in and out parameter. and if does some work based on in parameter and returns the result in out parameter. Here if you mean, like can i read the out parameter and check what it has returned, then yes you can access this data from JDBC.
CREATE or replace PROCEDURE getEmpName(EMP_NUM IN NUMBER)
is
CURSOR C1 is select from emp ;*
C2 c1%rowtype;
BEGIN
open c1;
loop
fetch c1 into c2;
exit when c1%NOTFOuND;
end loop;
END ;
/But in your above proc it has only in parameter, no out parameter and has only select. so you could execute the proc using JDBC. -
OIM: Retrieve data from stored procedure, pre populate it in Resource form
Hi,
I need to retrieve data form a stored procedure that i have created . This data needs to be per populated in the Iplanet resource from. The stored procedure will have one input string and one output string.
Thankz,
Sanjay Rulez1. Prepare OIM Admin Console to interact with an Oracle Database, by adding jdbc jar files in the lib Directory of OIM Console.
2. Restart OIM Console and Create a database Resource
3. Create an Pre-populate adapter Task with a "Stored Procedure" Type
4. Invoke you Procedure.
The main problems can be around datatype conversion between Java and Oracle database.
For instance, all Oracle NUMBER type are mapped on java LONG type, and you need to deal every time with conevsrion between INTEGER and LONG in the adapter task. -
SSRS 2008 not returning correct dataset from Stored Procedure
Hi,
I have a stored proc which returns different no. of columns as output based on the input parameter. The issue I am facing is that the SSRS 2008 is always populating the column list of the dataset with the first select list irrespective of the input
parameter.
How can I have the SSRS populate the column list based on the input parameter I am passing?
eg.
IF @type
=
'test'
BEGIN
SELECT 1 AS Col1,2 AS Col2
END
ELSE
IF @type
=
'test1'
BEGIN
SELECT 1 AS Col1,2 AS Col2,3 AS Col3
END
SSRS always populates the dataset with two columns viz col1 & col2 even when I pass
'test1' as input parameter.
Thanks for the help in advance.
SherinFrom my experiences, your dataset must return the same number of column and same name in both select statement.
IF
@type =
'test'
BEGIN
SELECT 1 AS Col1,2 AS Col2,
null AS Col3
END
ELSE
IF @type
=
'test1'
BEGIN
SELECT 1 AS Col1,2 AS Col2,3 AS Col3
END -
Returning rowcount and resultset from stored procedure
Hello,
In SQL Server you can return multiple resultsets from stored procedure by simple SELECT statement. But in Oracle, you have to use SYS_REFCURSOR.
Sample code:
CREATE OR REPLACE PROCEDURE sp_resultset_test IS
t_recordset OUT SYS_REFCURSOR
BEGIN
OPEN t_recordset FOR
SELECT * FROM EMPLOYEE;
END sp_resultset_test;
Is there any other way in Oracle 10 or 11 ?
Thank You.What is the requirement? Oracle is far more flexible than SQL-Server... with numerous features that do not exist in SQL-Server. (Fact)
One of the biggest mistakes you can make is to treat Oracle like SQL-Server... trying to match feature A1 in SQL-Server to feature B3 in Oracle.
Does not work that way.. rather then stick to SQL-Server as SQL-Server does SQL-Server specific features far better than Oracle.
So instead of trying to map what a T-SQL stored proc to do to an Oracle ref cursor (even to the extent of using that very silly sp_ prefix to name the proc), tell us the problem and requirements... That way we can tell you what Oracle features and options are best used to solve that problem - instead of competing in some unknown feature comparison event with SQL-Server. -
Return a parameter through stored procedures
Hello Experts
I want to return parameter through stored procedures so as to ensure that the application has been executed properly.
My source message format is
<StatementName5>
<storedProcedureName action=u201D EXECUTEu201D>
<table>Summarize_prc</table>
<empid [isInput=u201Dtrueu201D] [isOutput=true] type=SQLDatatype>val1</empid>
</storedProcedureName >
</StatementName5>
Do i need to put some extra parameters for return values from the stored procedures?
What would be the response message format to return the parameters from stored procedure.
Thanks
SabyasachiHi,
If you wants to read the return values from stored procedure, the scanario should be designed as Sync.
The format looks like thsi
<Message Type Name>
<STATEMENTNAME_response>
<Field1> </Field1>
</STATEMENTNAME_response>
</Message Type Name> -
How to get return values from stored procedure to ssis packge?
Hi,
I need returnn values from my stored procedure to ssis package -
My procedure look like and ssis package .Kindly help me to oget returnn value to my ssis package
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [TSC]
-- Add the parameters for the stored procedure here
@P_STAGE VARCHAR(2000)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
--SELECT <@Param1, sysname, @p1>, <@Param2, sysname, @p2>
truncate table [INPUTS];
INSERT
INTO
[INPUTS_BASE]
SELECT
[COLUMN]
FROM [INPUTS];
RETURN
END
and i am trying to get the return value from execute sql task and shown below
and i am taking my returnn value to result set variableYou need to have either OUTPUT parameters or use RETURN statement to return a value in stored procedures. RETURN can only return integer values whereas OUTPUT parameters can be of any type
First modify your procedure to define return value or OUTPUT parameter based on requirement
for details see
http://www.sqlteam.com/article/stored-procedures-returning-data
Once that is done in SSIS call sp from Execute SQL Task and in parameter mapping tabe shown above add required parameters and map them to variables created in SSIS and select Direction as Output or Return Value based on what option you used in your
procedure.
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Best method to transfer large strings (XML data) to/from stored procedure
Hi!
I'm trying to call a PL/SQL procedure from Java. The procedure inputs a string (XML) that is parsed, and returns a result string (also XML).
Typical size of the string is 5kb -> 1mb.
I can see two possible solutions:
1) String / LONG
2) CLOB (Using DMBS_LOB.createTemporary and getting a CLOB locator and passing the locator to the stored procedure)
Does anyone have other suggestions?
What is the fastest method for transferring XML structures from to and from stored procedures?
AndersAnders,
I would say it depends on your requirement. Both the methods have some advantages and disadvantages.
Using a CLOB means that you have to use vendor specific libraries but this is more extendible and I fast too.
Using String/Long will be more portable in the long run but again you lose on speed/performance.
Just a doubt of mine... If I got it correct, you are transforming one XML to another XML based on some conditions. Why dont you use XSL and XSL StyleSheet Processor packaged with XDK for this? I think this would be the fastest way.
Hope this helps.
Maybe you are looking for
-
Workbooks : Save as and Save
Hi, we have read a lot of message about workbooks authorizations and how to allow users to save in their favorites. Also we have found differents message where some collegues try to avoid users to save workbooks, not in a role neither in their favori
-
How do i find how much free space my iMac has? Its running MAC OS v10.6.8
I can't see anywhere where I can find out how much free soace my iMac has, any help much appreciated!
-
Hey guys, In an essbase application, I need users to read and load data to a specific country, while the rest location dimension is closed off to them. I need users to be able to read all the different scenarios but only load to Forecast (for that co
-
Adobe Pro 8 Forms return as blanks
Hello; I have created an adobe form using Acrobat 8. I then posted in on my web page, and am testing it. When I fill out the information, and click submit, it opens email, sends the email. When I rec'd the form, it was blank. Nothing I put in there s
-
When I film public speakers, I give them a small digital recording device that plugs into a lapel mic, to augment their voice. However, the device records at 44.1 khz. How can I convert the files I get from it to 48khz, so I can mix it with my DV, an