473,765 Members | 2,047 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic Execution of Stored Procedure

ayanmitra2007mindtree
4 New Member
Consider I have five stored procedures viz.

pr_sp1 (int_num1 IN number, int_num2 IN Number, v_cur OUT s_pkg.s_cur)
pr_sp2 (int_num1 IN number, int_num2 IN Number, v_cur OUT s_pkg.s_cur)
pr_sp3 (int_num1 IN number, int_num2 IN Number, v_cur OUT s_pkg.s_cur)
pr_sp4 (int_num1 IN number, int_num2 IN Number, v_cur OUT s_pkg.s_cur)
pr_sp5 (int_num1 IN number, int_num2 IN Number, v_cur OUT s_pkg.s_cur)


If you see, all these SPs are of same signature, but actually they queries different tables. For example pr_sp1 queries tblA, whereas the pr_sp2 queries tblB and so forth. The returns different resultsets with differnt range and number of columns in the Cursor, as defined in v_cur.

However, the int_num1 and int_num2 will be same for all the five SPs. All of them stores output as a cursor in v_cur variable which is a OUT parameter in all the SPs. We use this out paramter and apply some business logic.

Till date we were following an approach, where use to call these SPs one after one from a .net based application. But, we noticed a severe performance degradation as we are hitting the database everytime from the application to call the SP. So, we moved the call to a new oracle SP from where we will call these five SPs. Something like this:

create or replace my_new_sp
(
int_num1 in number,
int_num2 in number,
v_cur1 OUT s_pkg.s_cur,
v_cur2 OUT s_pkg.s_cur,
v_cur3 OUT s_pkg.s_cur,
v_cur4 OUT s_pkg.s_cur,
v_cur5 OUT s_pkg.s_cur
)
as
begin
pr_sp1(int_num1 , int_num2, v_cur1);
pr_sp2(int_num1 , int_num2, v_cur2);
pr_sp3(int_num1 , int_num2, v_cur3);
pr_sp4(int_num1 , int_num2, v_cur4);
pr_sp5(int_num1 , int_num2, v_cur5);
end;


Like this if we call the new SP (my_new_sp), we will get all the results back in one shot.

But, as you can see, the way I am managing the call is absolutely not good (at least I don't like). Here I have shown only five SPs for illustration, but in actual scenario there is some 80+ SPs[/u]. So, declaring cursor for individual SP is absolutely not a good idea.

Apart from this, the name of the SPs (here pr_sp1, pr_sp2, ... etc.) which I will be executing is stored in a table called tblSPList, which can be used to dynamically execute the procedures. Now my questions is:

1) How can declare a variable which will give me a list of cursors (accessible from .NET). I mean Instead of declaring 5 cursors in the example shown above, can I declare a variable which stores the list of cursors. I have tried VARRAY, TABLES etc. but failed.

2) How can I execute, a stored procedure dynamically. I mean, in my example where I am exclusively calling :

pr_sp1(int_num1 , int_num2, v_cur1);

can I have a way to call it dynamically, something like

execute immediate 'begin ‘ || var_spname || ‘(:2); end;' using out cur_result;

where var_spname will contain the name of SP i.e. pr_sp1 and the out put I will store in cur_result. Please note, I have tried the above statement, but it is failing and Oracle is showing some cryptic error message which says... "Error while trying to retrieve text for error ORA-03113"

Any Ideas
Aug 7 '07 #1
4 3775
debasisdas
8,127 Recognized Expert Expert
for your situation the best solution would be to write a single stored procedures having a ref-cursor as the output. you need to declare the ref-cursor in a package so that its scope would be global. enen you can declare the procedure in side the package it self.
Aug 7 '07 #2
debasisdas
8,127 Recognized Expert Expert
An ORA-03113 end-of-file on communication channel error is a very generic error that indicates that the connection has been lost.
ORA-3113 is reported by the oracle client processes due to many reasons. ORA 3113 by itself does not indicate the cause of the issue and is accompanied by other messages that are either displayed on the client side or in the oracle database alertlog.

Cause: The connection between Client and Server process was broken
Action: There was a communication error that requires further investigation. First, check for network problems and review the SQL*Net setup. Also, look in the alert.log file for any errors. Finally, test to see whether the server process is dead and whether a trace file was generated at failure time.
Aug 7 '07 #3
ayanmitra2007mindtree
4 New Member
I think it will be better that you people read my question carefully and then answer. My problem is not with network or channel specific. I have asked something related to PL/SQL programming approach. I request you to please go through the scenario once again..
Aug 7 '07 #4
ayanmitra2007mindtree
4 New Member
Any Ideas about the approach. Has anybody done this before...
Aug 8 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2390
by: Guinness Mann | last post by:
When you guys talk about "dynamic SQL," to what exactly are you referring? Is dynamic SQL anything that isn't a stored procedure? Specifically, I use ASP.NET to communicate with my SQL Server 2000, using an SqlConnection object to open the database and an SqlCommand object to transfer my SQL text to the database. Is this the "dynamic SQL" that is such a bad thing? What is my alternative? Wait until after my program is working and...
1
34976
by: Todd Peterson | last post by:
I'm a newbie to DB2 and am trying to figure out how to write a stored procedure, using dynamic SQL statements to return a result set. I believe the majority of the hurdles I have been facing might be due to the fact that the samples and postings I have read have been related to the UDB... I believe our company is on some version of MVS or OS/390, but I am not sure which one, at the time of this posting. I have an example, below, of a...
1
9713
by: Raquel | last post by:
This is a stored procedure that resides on Mainframe and gets executed on the client by connecting to the mainframe through DB2 connect. It was executing fine till yesterday when I executed a table change and successfully Rebound the package associated with the stored procedure. Since then, it is giving a strange problem. When the client executes the program that calls the stored procedure SP1, the stored procedure does not get executed...
6
2671
by: MattC | last post by:
Hi, I'm implementing a new Business Layer in one of our applications. I'm toying with the idea of placing all the Create, Read, Update and Delete SQL in the object in question and build a dynamic SQL string using a class builder. The pros I can see are: It reduces the number of stored procs to admin. Changes to the underlying table schema does not require massive changes to
5
12262
by: alingsjtu | last post by:
Hello, every body. When execute dynamic generated multiple OPENQUERY statements (which linkes to DB2) in SQLServer, I always got SQL1040N The maximum number of applications is already connected to the database. SQLSTATE=57030. Background: I created a linked server to DB2 8.1 database which called GRR_DB2Server. In my stored procedure p_FetchRawData, I need to read some data from this linked server GRR_DB2Server and insert them into
4
6966
by: TheRealPawn | last post by:
I'm trying to get the execution plan for a single stored procedure from Profiler. Now, I've isolated the procedure but I get all execution plans. Any ideas on how to connect the SPIDs so that I only get the execution plan for the procedure I'm watching and not the whole of the server?
7
3027
by: Ronald S. Cook | last post by:
I've always been taught that stored procedures are better than writing SQL in client code for a number of reasons: - runs faster as is compiled and lives on the database server - is the more proper tier to put it since is a data function But then I've heard that writing SQL in my client .NET code might run just as fast? Dynamic SQL or something? And then there's LINQ on the horizon. Is it a successor to everything
5
1109
by: Ronald S. Cook | last post by:
I've read a few posts on the stored procedure vs dynamic sql debate. I ran a few performance test for myself and it appears to be a wash. Given that, I'm leaning toward dynamic sql mostly because it would mean one fewer place to have things. But, before we go that route we wanted to ask the question: Is there any compelling reason why we shouldn't abandon all of our stored procs and just write the SQL inside inside our functions in...
5
10759
by: sqlgirl | last post by:
Hi, We are trying to solve a real puzzle. We have a stored procedure that exhibits *drastically* different execution times depending on how its executed. When run from QA, it can take as little as 3 seconds. When it is called from an Excel vba application, it can take up to 180 seconds. Although, at other times, it can take as little as 20 seconds from Excel.
23
1421
by: valentin tihomirov | last post by:
Hello, -=PREHISTORY=- Occasionally, I wanted to rewrite my UPDATE code to prevent SQL injection. I generated the SQL query UPDATE tt SET @p1_name = @p1_val
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9399
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9957
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9835
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.