Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2004
    Location
    Ottawa, Canada
    Posts
    58

    Unanswered: 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.

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    How about a "BEFORE INSERT" trigger?

  3. #3
    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

  4. #4
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •