Morning all,
Unless you're doing math on it, make it a character
I [respectfully] disagree!
An excellent rule to follow.
For certain values of 'excellent'?
Ok, I shall explain. I used to write COBOL programs. Numeric fields in
files could be DISPLAY (ie character) or various forms of binary. (COMP,
COMP-N, COMP-SYNC etc).
A number is a number. It makes not a jot of difference whether it is an
ID, a salary, an age or a telephone number - although they do need
special consideration. So, the correct storage for a number is a numeric
data type.
Phone numbers, even in Excel, have leading zeros. They can cause
problems when the STORAGE format 'loses' them. However, the DISPLAY
format must re-create these leading zeros. So, for example, a phone
number such as 0779 666 6166 can still be stored as a numeric data type,
but displayed as to_char(phone_number, '09999999999').
If I really want the 0779 666 6166 format, I can use
NLS_NUMERIC_CHARACTERS and a format of '0999g999g999' instead:
ALTER SESSION set NLS_NUMERIC_CHARACTERS='. '; -- There's a trailing
space there.
SELECT to_char(07796666166, '0999g999g9999') FROM dual;
0779 666 6166
ALTER SESSION set NLS_NUMERIC_CHARACTERS='.,'; -- Or whatever you
normally use/have saved previously.
Ok, much mucking around just to get a phone number to format correctly.
However, what about international phone numbers +44 (0)779 666 6166 and
it becomes obvious, that a phone number isn't actually a number. So,
character data it is and the data input screen will (won't it?) have
proper phone number format validation - if required.
Other than phone numbers, I cannot think of any other numeric data that
should be stored as a character string. Your US style SSNs may be
different, but in the UK our NI Numbers are formatted as AA999999A and
are thus, text. For example WK196163A.
My rule, since my very early COBOL days is "always use the correct data
type for all data" and this implies that a number is a number in the
same way that a data is a date and not a string.
Besides, storing data in the "wrong" format can seriously throw the CBO
off the best path.
Cheers,
Norm. [TeamLastDayAtWorkBefore2010]
Information in this message may be confidential and may be legally privileged. If you have received this message by mistake, please notify the sender immediately, delete it and do not copy it to anyone else. We have checked this email and its attachments for viruses. But you should still check any attachment before opening it. We may have to make this message and any reply to it public if asked to under the Freedom of Information Act, Data Protection Act or for litigation. Email messages and attachments sent to or from any Environment Agency address may also be accessed by someone other than the sender or recipient, for business purposes. If we have sent you information and you wish to use it please read our terms and conditions which you can get by calling us on 08708 506 506. Find out more about the Environment Agency at www.environment-agency.gov.uk
Information in this message may be confidential and may be legally privileged. If you have received this message by mistake, please notify the sender immediately, delete it and do not copy it to anyone else.
We have checked this email and its attachments for viruses. But you should still check any attachment before opening it.
We may have to make this message and any reply to it public if asked to under the Freedom of Information Act, Data Protection Act or for litigation. Email messages and attachments sent to or from any Environment Agency address may also be accessed by someone other than the sender or recipient, for business purposes.
If we have sent you information and you wish to use it please read our terms and conditions which you can get by calling us on 08708 506 506. Find out more about the Environment Agency at www.environment-agency.gov.uk