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
Requires Free Membership to View
Register today to access targeted resources from our editorial writers and independent industry experts including news, tips, and advice to help you do your job more efficiently and effectively. Stay informed on the hottest topics and biggest challenges faced by IT professionals working with iSeries products and services.
- forums.
- Best Web Links: DB2 tips, tutorials, and scripts from around the Web.
This was first published in December 2002