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.
'EMAIL ADDRESS IS '|| STRIP(CHAR(LENGTH(RTRIM(EMAIL_ADDR))),B) ' CHARACTERS LONG'
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.