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 > Column with automatic truncation?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-06-05, 09:59
ApoPen ApoPen is offline
Registered User
 
Join Date: Jul 2004
Location: Ottawa, Canada
Posts: 58
Column with automatic truncation?

Is it possible to define a column to automatically truncate data?

I have a column with length of 255, If i insert anything larger I naturally get an error (SQL0433N). The problem is sometimes (not often) there is data that will be longer.

Can I setup a column to automically truncate this data instead of having to code the trucate funtion on the inserts? Coding truncates on all the inserts on this table is time consuming, and if i change the column length in the future, I then have to go change all my code.
Reply With Quote
  #2 (permalink)  
Old 01-07-05, 09:39
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
How about a "BEFORE INSERT" trigger?
Reply With Quote
  #3 (permalink)  
Old 01-11-05, 07:12
Tank Tank is offline
Registered User
 
Join Date: Feb 2004
Location: Copenhagen
Posts: 220
Arrow Substr ?

How about simply inserting the substr(insertvariable,1,255) ??

BOW
__________________
Kristian K. Hansen
Project Supervisor
National Board of Health
Reply With Quote
  #4 (permalink)  
Old 01-11-05, 16:53
nidm nidm is offline
Registered User
 
Join Date: May 2003
Posts: 113
I don't think there is a solution for you. Column definition doesn't have such properties.
Apparentlly, You don't want to add func, such as substr/char/varchar/cast, in the insert stmt. Even a trigger need such functions to manipulate data.

Another way is truncate the data before insert inside APPLICATION. for example:

DECLARE HV VARCHAR(255)

:HV = truncate(source string...)

INSERT INTO T(COL_VARCHAR_255) VALUES(:HV)

Quote:
Originally Posted by ApoPen
Is it possible to define a column to automatically truncate data?

I have a column with length of 255, If i insert anything larger I naturally get an error (SQL0433N). The problem is sometimes (not often) there is data that will be longer.

Can I setup a column to automically truncate this data instead of having to code the trucate funtion on the inserts? Coding truncates on all the inserts on this table is time consuming, and if i change the column length in the future, I then have to go change all my code.
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