How to treat a CHAR like a VARCHAR

Use this procedure to get the length of actual text (not spaces) of a row in a CHAR column returned in CHAR format.

If you need to have the length of actual text (not spaces) of a row in a CHAR column returned in char format. This...

is particularly handy when concatinating data together with a value containing its length. I found it useful for writing from a trigger to a table including the length of the data. It has been tested on DB2 V7 for OS/390. This tip is based upon work by David Corrigan.


For More Information

  • Feedback: E-mail the editor with your thoughts about this tip.
  • More tips: Hundreds of free DB2 tips and scripts.
  • Tip contest: Have a DB2 tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize -- submit your tip today!
  • Ask the Experts: Our SQL, database design, Oracle, SQL Server, DB2, metadata, and data warehousing gurus are waiting to answer your toughest questions.
  • Forums: Ask your technical DB2 questions--or help out your peers by answering them--in our active forums.
  • Best Web Links: DB2 tips, tutorials, and scripts from around the Web.

This was last published in December 2002

Dig Deeper on DB2 UDB (universal databases)



Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: