Re: LENGTH function and trailing spaces
Posted in 1995
Topics: Data Types & Schema Design, Jobs, Consulting & Announcements
Well.. shapes of objects do/can change over time. I could easily write an application that allocates 'buffers' and then would expect the database to tell it how much data just got fetched. I'm pretty sure Informix does this. It sure sounds like a couple of things are true: 1) nobody thinks they are wasting space by storing trailing blanks in VARCHAR fields. That means that all applications that put data into the database must strip the trailing spaces (or perhaps the API does it under the covers) but the doc indicates that trailing spaces ARE stored for VARCHAR so there must be someway to get em in 2) assuming the trailing spaces are stored (in at least some cases) there appears to be no application need to know that. I have no problem with either or both of those possibilities but I just couldn't deduce from the manuals what the deal was. Graeme Sargent (graeme@pyramid.com) wrote: : Kirk Bradley - Mainframe and Integration Technologies (kbradley@130.35.1.6) wrote: : : Maybe I'm not phrasing this right. If I store 10 characters : : into a column and 3 of them are trailing spaces and ask : : for the LENGTH of the column via SQL I get 7. This is because : : LENGTH() will not include the trailing spaces in the returned : : value. When I fetch that same column into a 20 byte host variable : : (say the database column was defined as 15 bytes) I will (I hope) : : get an indication that only 10 bytes were stored into my application : : program. The question is, how can I get the number 10 in a SQL : : statement? Is it possible? This would represent the size I would : : need to allocate for this 1 column/row (let's make it easy and : : assume a 1 row 1 column table) in my host program. : But if the database column is 15 bytes, why would you want to make your : host variable anything other than 15 bytes? : There's no way you could know in advance that the column only contains : 10 characters, unless you know that they all do, in which case why the : heck are you using VARCHAR and padding them with spaces??? : : Is that clearer? Is it something anybody ever needs/wants to do? : Your words are clearer, but your intent is not. I can't see why anybody : would need/want to do it. : : -- : : Kirk Bradley : : Oracle Corporation : : Mainframe and Integration Technologies Group : -- : graeme : -- : Disclaimer: The author's opinions are his own, and not necessarily : those of Pyramid Technology Ltd. or Pyramid Technology Inc. : --------------------------------------------------------------------------- : -m------- Graeme Sargent Voice: +44 (0)252 373035 : ---mmm----- Senior Database Consultant Fax : +44 (0)252 373135 : -----mmmmm--- Pyramid Technology Ltd. Telex: Tell who??? : -------mmmmmmm- Farnborough, Hants GU14 7PL Email: graeme@pyra.co.uk : --------------------------------------------------------------------------- : We have the technology. The tricky bit is learning how to use it. -- Kirk Bradley Oracle Corporation Mainframe and Integration Technologies Group