473,766 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exception handling in db2 UDF

Hi,
Can someone tell me how to perform exception handling in DB2 UDFs(not
procedures).
ALso, while usin the SIGNAL statement in one of my UDFs I encountered
an error message which is as below

DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0104N An unexpected token "HANDLER" was found following "E INT;
DECLARE
EXIT". Expected tokens may include: "CONDITION" . LINE NUMBER=12.
SQLSTATE=42601
The code that i used in my UDF is
DECLARE EXIT HANDLER FOR SQLSTATE VALUE '23503'
SIGNAL SQLSTATE '75002'
SET MESSAGE_TEXT = 'Customer number is not known';
So, Can anyone help me with this?

Thanks and regards
mailar

Nov 12 '05 #1
3 11357
SQL UDFs cannot contain any commands that are outside the scope of the
SQL reference. DB2 will take an SQL UDF and stick it directly into the
calling SQL, so that when it's executed it's indistinguishab le from the
rest of the statement, as far as the engine is concerned.

An SQL Procedure, on the other hand, is completely separate entity,
which contains it's own set of information specific to it's execution.
As such, the SQL/PL language has directives that are NOT found in the
SQL reference, as they are specific to the procedur processing. I
believe "DECLARE EXIT HANDLER" is one of them.

ma****@gmail.co m wrote:
Hi,
Can someone tell me how to perform exception handling in DB2 UDFs(not
procedures).
ALso, while usin the SIGNAL statement in one of my UDFs I encountered
an error message which is as below

DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0104N An unexpected token "HANDLER" was found following "E INT;
DECLARE
EXIT". Expected tokens may include: "CONDITION" . LINE NUMBER=12.
SQLSTATE=42601
The code that i used in my UDF is
DECLARE EXIT HANDLER FOR SQLSTATE VALUE '23503'
SIGNAL SQLSTATE '75002'
SET MESSAGE_TEXT = 'Customer number is not known';
So, Can anyone help me with this?

Thanks and regards
mailar

Nov 12 '05 #2
Hi amurchis,
But does it mean that we cannot do error handling in UDFs?
Meanwhile I found a function RAISE_ERROR which raises an SQL state and
displays my error message
but the format of the message is like this

SQL0438N Application raised error with diagnostic text: "Invalid
customer number".
SQLSTATE=70001
but I just want 'Invalid customer number" to be displayed instead of
the whole message. So, could you help me with this

Thanks for the reply
mailar

amurchis wrote:
SQL UDFs cannot contain any commands that are outside the scope of the SQL reference. DB2 will take an SQL UDF and stick it directly into the calling SQL, so that when it's executed it's indistinguishab le from the rest of the statement, as far as the engine is concerned.

An SQL Procedure, on the other hand, is completely separate entity,
which contains it's own set of information specific to it's execution. As such, the SQL/PL language has directives that are NOT found in the SQL reference, as they are specific to the procedur processing. I
believe "DECLARE EXIT HANDLER" is one of them.

ma****@gmail.co m wrote:
Hi,
Can someone tell me how to perform exception handling in DB2 UDFs(not procedures).
ALso, while usin the SIGNAL statement in one of my UDFs I encountered an error message which is as below

DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0104N An unexpected token "HANDLER" was found following "E INT;
DECLARE
EXIT". Expected tokens may include: "CONDITION" . LINE NUMBER=12.
SQLSTATE=42601
The code that i used in my UDF is
DECLARE EXIT HANDLER FOR SQLSTATE VALUE '23503'
SIGNAL SQLSTATE '75002'
SET MESSAGE_TEXT = 'Customer number is not known';
So, Can anyone help me with this?

Thanks and regards
mailar


Nov 12 '05 #3
Even in a stored procedure, you'd still get a message similar to what
you see below. I believe it's something like "procedure <name>,
specific name <specname> returned sqlstate <your state> with message
text "<your text>", but don't hold me to that.

Error handling in an SQL UDF must be done strictly with SQL commands.

FYI: I am NOT an expert in SQL. The only thing I can suggest is that
you check the SQL reference for CREATE FUNCTION (SQL) for what commands
are available.

ma****@gmail.co m wrote:
Hi amurchis,
But does it mean that we cannot do error handling in UDFs?
Meanwhile I found a function RAISE_ERROR which raises an SQL state and
displays my error message
but the format of the message is like this

SQL0438N Application raised error with diagnostic text: "Invalid
customer number".
SQLSTATE=70001
but I just want 'Invalid customer number" to be displayed instead of
the whole message. So, could you help me with this

Thanks for the reply
mailar

amurchis wrote:
SQL UDFs cannot contain any commands that are outside the scope of


the
SQL reference. DB2 will take an SQL UDF and stick it directly into


the
calling SQL, so that when it's executed it's indistinguishab le from


the
rest of the statement, as far as the engine is concerned.

An SQL Procedure, on the other hand, is completely separate entity,
which contains it's own set of information specific to it's


execution.
As such, the SQL/PL language has directives that are NOT found in the


SQL reference, as they are specific to the procedur processing. I
believe "DECLARE EXIT HANDLER" is one of them.

ma****@gmail. com wrote:

Hi,
Can someone tell me how to perform exception handling in DB2
UDFs(not
procedures ).
ALso, while usin the SIGNAL statement in one of my UDFs I
encountered
an error message which is as below

DB21034E The command was processed as an SQL statement because it
was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0104N An unexpected token "HANDLER" was found following "E INT;
DECLARE
EXIT". Expected tokens may include: "CONDITION" . LINE NUMBER=12.
SQLSTATE=426 01
The code that i used in my UDF is
DECLARE EXIT HANDLER FOR SQLSTATE VALUE '23503'
SIGNAL SQLSTATE '75002'
SET MESSAGE_TEXT = 'Customer number is not known';
So, Can anyone help me with this?

Thanks and regards
mailar


Nov 12 '05 #4

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

Similar topics

11
2885
by: adi | last post by:
Dear all, This is more like a theoretical or conceptual question: which is better, using exception or return code for a .NET component? I had created a COM object (using VB6), which uses return code (not generating error/exception) so it is more compatible with other programming language.
6
2341
by: Daniel Wilson | last post by:
I am having exception-handling and stability problems with .NET. I will have a block of managed code inside try...catch and will still get a generic ..NET exception box that will tell me which assemblies are loaded before shutting down. In one case, some of my DB-accessing code didn't handle a NULL value properly. But try...catch wouldn't catch the exception and keep going. I'd just get the error message and then it would shut the...
7
6007
by: Noor | last post by:
please tell the technique of centralize exception handling without try catch blocks in c#.
3
2751
by: Master of C++ | last post by:
Hi, I am an absolute newbie to Exception Handling, and I am trying to retrofit exception handling to a LOT of C++ code that I've written earlier. I am just looking for a bare-bones, low-tech exception handling mechanism which will allow me to pass character information about an error and its location from lower-level classes. Can you please critique the following exception handling mechanism in terms of my requirements ?
2
2595
by: tom | last post by:
Hi, I am developing a WinForm application and I am looking for a guide on where to place Exception Handling. My application is designed into three tiers UI, Business Objects, and Data Access Layer. My questions is where should I put exception handling: 1) Should it be put in all significant methods in all layers? 2) Should I create an exception base class that will handle the errors and pass useful error messages to the user?
9
2538
by: C# Learner | last post by:
Some time ago, I remember reading a discussion about the strengths and weaknesses of exception handling. One of the weaknesses that was put forward was that exception handling is inefficient (in the way of CPU usage), compared to the "normal" practise returning values. How true is this? Will using using exception handling, in general, be much less efficient than returning values, or less efficient at all? Just curious...
44
4226
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level user tasks should always be included in a try/catch block that actually handles any exceptions that occur (log the exception, display a message box, etc.). 2. Low-level operations that are used to carry out the high level tasks
4
5136
by: Ele | last post by:
When Exception handling disabled compiler still spits out "C++ exception handler used." Why is that? Why does it ask for "Specify /EHsc"? Thanks! c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xstring(1453) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
41
3070
by: Zytan | last post by:
Ok something simple like int.Parse(string) can throw these exceptions: ArgumentNullException, FormatException, OverflowException I don't want my program to just crash on an exception, so I must handle all of them. I don't care about which one happened, except to write out exception.Message to a log file. It seems verbose to write out three handlers that all do the same thing. So, I could just catch Exception. But, is that...
1
3109
by: George2 | last post by:
Hello everyone, Such code segment is used to check whether function call or exception- handling mechanism runs out of memory first (written by Bjarne), void perverted() { try{
0
9571
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
9404
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
10168
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...
0
10009
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9838
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...
0
8835
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
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.