473,834 Members | 2,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can I overload stored procedures based on param type?

aj
DB2 LUW 8.1 FP11

Can't I overload SPs based on param types rather than
just number of params?

If I do:
CREATE PROCEDURE FOO(
P_DATE_OLD DATE,P_DATE_NEW DATE)
then
CREATE PROCEDURE FOO(
P_INT_OLD INTEGER,P_INT_N EW INTEGER)
then
CREATE PROCEDURE FOO(
P_TEXT_OLD VARCHAR(500),P_ TEXT_NEW VARCHAR(500))

I get
SQL0454N The signature provided in the definition for
routine "FOO" matches the signature of some other routine
that already exists in the schema or for the type.
LINE NUMBER=8. SQLSTATE=42723
for the 2nd and 3rd CREATE PROCEDURE calls..

I guess its some sort of promotability issue? I've tried
switching the order of the CREATEs around, but no help.

Can I do this sort of thing?

TIA

aj
May 24 '06 #1
6 9874
The documentation <URL:http://tinyurl.com/zm653> explicity states:

No two identically-named procedures within a schema are permitted to
have exactly the same number of parameters. A duplicate signature
raises an SQL error (SQLSTATE 42723).

For example, given the statements:

CREATE PROCEDURE PART (IN NUMBER INT, OUT PART_NAME CHAR(35)) ...
CREATE PROCEDURE PART (IN COST DECIMAL(5,3), OUT COUNT INT) ...

the second statement will fail because the number of parameters in the
procedure is the same, even if the data types are not.
B.

May 24 '06 #2
aj
OK - guess I need a knock on the head w/ the RTFM hammer.

thanks

aj

Brian Tkatch wrote:
The documentation <URL:http://tinyurl.com/zm653> explicity states:

No two identically-named procedures within a schema are permitted to
have exactly the same number of parameters. A duplicate signature
raises an SQL error (SQLSTATE 42723).

For example, given the statements:

CREATE PROCEDURE PART (IN NUMBER INT, OUT PART_NAME CHAR(35)) ...
CREATE PROCEDURE PART (IN COST DECIMAL(5,3), OUT COUNT INT) ...

the second statement will fail because the number of parameters in the
procedure is the same, even if the data types are not.
B.

May 24 '06 #3
Aj,

It wasn't the case but just the let you know :

You can do this in UDFs. # of parameters might be same given that
their data types are different.

But then you may want to use,

SPECIFIC "some_unique_ud f_identifier" in the function creation.

smthg like :

CREATE PROCEDURE PART (IN NUMBER INT, OUT PART_NAME CHAR(35)) SPECIFIC
my_unique_udf_i dentifier ............... ...

It will help you to distinguish the functions.

example:

drop specific function my_unique_udf_i dentifier

Regards,

Mehmet Baserdem

May 24 '06 #4
AJ,

As noted by others it's only possible for functions, not procedures.
This is, in fact, the first time I see such a question, so I'm curious
whether you are porting of another product (which one).
AFAIK no other vendor supports overloading procedures by parameter type
and very few support function overloading by type to begin with.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
May 25 '06 #5
aj
Hi Serge

No, not porting from another product.

Just trying to implement the audit trail from hell. My
insert/update/delete triggers CALL a SP.

The insert/delete triggers are easy - they call a SP,
passing (TABLE, PK, OPERATION, USER)

However, the update trigger is more. It calls the SP with
TABLE, PK, OPERATION, USER, COLUMN, OLDVAL, NEWVAL)
where the COLUMN type and OLD/NEW values can be DATE,
CHAR/VARCHAR, or INTEGER.

I wanted to overload the SP by type, using wrapper SPs to
call the one that actually does the audit trail work. This
seemed better than clouding my triggers up w/ a bunch of
dummy SP params, or trying to CAST(), or using different SPs.
I'm also a Java developer, so overloading by type makes
sense to me.

I wound up CALLing different SPs from the update triggers
based on type.

Why is overloading by type in SP a big deal? DB2 is so
strongly typed I would think its easy.

thanks

aj

Serge Rielau wrote:
AJ,

As noted by others it's only possible for functions, not procedures.
This is, in fact, the first time I see such a question, so I'm curious
whether you are porting of another product (which one).
AFAIK no other vendor supports overloading procedures by parameter type
and very few support function overloading by type to begin with.

Cheers
Serge

May 25 '06 #6
aj wrote:
Hi Serge

No, not porting from another product.

Just trying to implement the audit trail from hell. My
insert/update/delete triggers CALL a SP.

The insert/delete triggers are easy - they call a SP,
passing (TABLE, PK, OPERATION, USER)

However, the update trigger is more. It calls the SP with
TABLE, PK, OPERATION, USER, COLUMN, OLDVAL, NEWVAL)
where the COLUMN type and OLD/NEW values can be DATE,
CHAR/VARCHAR, or INTEGER.

I wanted to overload the SP by type, using wrapper SPs to
call the one that actually does the audit trail work. This
seemed better than clouding my triggers up w/ a bunch of
dummy SP params, or trying to CAST(), or using different SPs.
I'm also a Java developer, so overloading by type makes
sense to me.

I wound up CALLing different SPs from the update triggers
based on type.

Why is overloading by type in SP a big deal? DB2 is so
strongly typed I would think its easy.

Yes, it would be easy. But the customer base has shown little interest.
Few use function overloading. Need to follow the money....
But what you are looking for seems more to be implicit casting.
After allI take it your audit doesn't care what the source type was. You
log everything as varchar. So if DB2 would cast the integer to varchar
when passing the argument you'd be happy right?

Cheers
Serge

PS: that's the opposite of strong typing ;-)

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
May 25 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4238
by: Ryan | last post by:
I have two similar stored procedures which I'm running. One runs and one doesn't. I can run both with no problems in SQL Enterprise (7.0 standard) and have checked the permissions and am happy with them. Whilst the statements in each sp are different, I'm calling them in exactly the same way (using Delphi 5 Windows 2000). I don't get any trappable errors. I ran a trace on what was happening and I get two different set of results. This...
3
1645
by: tekanet | last post by:
Hello folks, I usually use this way to store more procedures inside a single SP: CREATE PROCEDURE usp_MyProc (@usp_mode int) AS IF @usp_mode = 1 BEGIN END
4
3196
by: Rhino | last post by:
Is it possible for a Java Stored Procedure in DB2 V7.2 (Windows) to pass a Throwable back to the calling program as an OUT parameter? If yes, what datatype should I use when registering the Throwable as an OUT parameter and what datatype should I use in the CREATE PROCEDURE and DROP PROCEDURE statements? Here's what I tried: - the method signature for the stored procedure included: Throwable throwable
2
4652
by: Ann Marinas | last post by:
Hi, all! I would like to ask a favor regarding ADO.NET... I would like to know how I can access programmatically stored procedures in a SQL Server. I've been pulling my hair up all weekend, and it seems that I couldn't get it. Thanks!
5
2257
by: Rob Wire | last post by:
For the code below, how could I add an item in the drop down lists for both company and location to be an "All" selection that would send to the stored proc. spRptAttachments a value of "%" so that it would bring back all attachments at all companies or all locations at a company? Thank you, Rob. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IsPostBack Then
1
1424
by: Lars Erik Thorsplass | last post by:
I have recently ventured into the exciting world of stored procedures, but I have now become lost. Background: Am currently working on access control in a web application. My goal is to process access control on the SQL level. This way if a row is in the result set, you have access to it, if not, you dont.
3
23708
by: Sirisha | last post by:
Hi, I am inserting values into databse using sqlserver stored procedures. i wrote stored preocedure,but in codebehind file(.vb file) i dont know how to pass the parameters, i got error message like this "System.Data.SqlClient.SqlException: Procedure or Function 'sp_insert' expects parameter '@TestId', which was not supplied. at System.Data.SqlClient.SqlConnection" I wrote Stored Procedure Like this:
0
1870
by: Sirisha | last post by:
Hi, I am inserting values into databse using sqlserver stored procedures. i wrote stored preocedure,but in codebehind file(.vb file) i dont know how to pass the parameters, i got error message like this "System.Data.SqlClient.SqlException: Procedure or Function 'sp_insert' expects parameter '@TestId', which was not supplied. at System.Data.SqlClient.SqlConnection"
0
5890
debasisdas
by: debasisdas | last post by:
This thread contains some of the sample code showing the method of executing Oracle stored procedures and functions from VB . Hope the user finds them useful. Oracle Procedure with only IN type as parameter mode. ======================================== CREATE OR REPLACE PROCEDURE DEPTINS ( DNO DEPT.DEPTNO%TYPE, DN DEPT.DNAME%TYPE,
0
9799
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
9646
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,...
1
10550
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
10220
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
7760
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
5627
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5796
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4427
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
3
3083
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.