If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Collecting error fields during insert

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-01-09, 05:14
anirbanpal anirbanpal is offline
Registered User
 
Join Date: Nov 2009
Posts: 6
Collecting error fields during insert

Hi,

I am using a db2 " insert into ... values () " command within a script and is getting data compability mismatch due to some decimal values being trying to be inserted into INT fields. But the message that I am seeing is not explicitly specifying the field(s) which are encountering this issue. C
Can someone suggest me how to get the field names in this situation?

Thanks,
Anirban.
Reply With Quote
  #2 (permalink)  
Old 12-01-09, 05:28
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
what do you get??

i get
Quote:
C:\>db2 "create table t1(i int,j int) "
DB20000I The SQL command completed successfully.

C:\>db2 "insert into t1 values(1,'1')"
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0408N A value is not compatible with the data type of its assignment
target. Target name is "J". SQLSTATE=42821
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old 12-01-09, 06:50
anirbanpal anirbanpal is offline
Registered User
 
Join Date: Nov 2009
Posts: 6
I am sorry, this error was reported in another project and they were discussing this with me. They are basically executing a stored proc and within that they are storing certain values in variables. Then they are issuing the the insert statement within the proc with values of these variables. Now it just gives them the error code. I am getting the code and will post in here.

I want to know is there any special way to trap errors within stored procs ?

Thanks
Anirban.
Reply With Quote
  #4 (permalink)  
Old 12-01-09, 07:20
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
You can use exception handlers to react on errors in stored procs. Or you don't do anything special, then an exception in a stored proc results in termination of the procedure and the error of the nested statement is reported to the caller.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #5 (permalink)  
Old 12-01-09, 08:55
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Code:
Column                         Type      Type
name                           schema    name               Length   Scale Nulls
------------------------------ --------- ------------------ -------- ----- ------
I                              SYSIBM    INTEGER                   4     0 Yes
J                              SYSIBM    INTEGER                   4     0 Yes
Code:
create procedure p2(out txt1 char(254))
language sql
begin p1:

declare s1 char(254) ;
declare s2 char(254);
declare exit handler for sqlexception
begin
get diagnostics exception 1 txt1=  message_text ;
--set txt1='dd' ;
end ;

set s1='insert into  t1 values(1,''d'')' ;
execute immediate s1  ;
set txt1='10' ;


end @
Code:
  Value of output parameters
  --------------------------
  Parameter Name  : TXT1
  Parameter Value : SQL0408N  A value is not compatible with the data type of its assignment target.  Target name is "J".  SQLSTATE=42821                                                                                                                 

  Return Status = 0
or if you want just the column name, you can use DB2_TOKEN_STRING instead of MESSAGE_TEXT.

Also, you can write different exit handlers for different exceptions. Check the manual for more info
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.

Last edited by sathyaram_s; 12-01-09 at 08:57. Reason: additional info added
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On