• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

number replaced by char

 
Greenhorn
Posts: 18
IBM DB2 Oracle MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,

I have to store a account no which is 12(112345678900) digit in length. so in create statement can i use CHAR instead or NUMBER.

PKS
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't need a CHAR for that. Oracle's NUMBER can store up to 38 significant digits:
 
Praveen Kumar Singh
Greenhorn
Posts: 18
IBM DB2 Oracle MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks but when i am writing a select statement the Zero(0). when i inserted i pass the value with Zero.


 
Martin Vashko
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So the problem is that you inserted 012345678912, but select gives you 12345678912?

When you store a number, the exact formatting (leading zeroes, trailing zeroes, superfluous plus sign and so on) are not stored. You'll have to format the number (either in the database using the TO_CHAR function, or in the client application) to convert it to the format you specify. The format can be constructed so that it provides the leading zeroes, eg.:(The FM modifier in Oracle format ensures there won't be a leading space).

There might still be a valid requirement to store the account number as a text, and not as a number (for example, if you envision different account number formats that would include non-numerical characters, such as dashes or slashes). Ultimately, the decision is on you, because no one else can know your exact situation. But even if you decide to store the account number as text, use a VARCHAR2 column, not CHAR. VARCHAR2 is much easier to expand if, all of sudden, you find that you need to store account numbers longer than 12 digits/characters. And if I was storing account number as text, I'd put constraints in place that would prevent invalid account numbers from ever been stored in the database.
reply
    Bookmark Topic Watch Topic
  • New Topic