← Back to list

How to format Zipcode / Postal Code in Oracle

Sometimes , in the applications , zipcodes are stored as numbers . That means , the leading zeros for some of the postal codes will not be…

Zahir Mohideen · 2026-08-09 22:20 · 0 claps · 0.7 min read
#oracle-database #sql #oracle-pl-sql #database-development #formatting
Open on Medium ↗

How to format Zipcode / Postal Code in Oracle

Sometimes , in the applications , zipcodes are stored as numbers . That means , the leading zeros for some of the postal codes will not be displayed in the applications / reports. This may not be desirable to the end user.

As an example , in New Jersey , all the zip codes starts with leading zero. But , if you look at the database , the leading zero will be missing .

SQL> SELECT *
 2 FROM
 3 (SELECT u.*
 4 FROM uszipcode u
 5 WHERE state = ‘NJ’
 6 )
 7 WHERE rownum < 5;

POSTALCODE CITY ST
 - - - - - - - - - - - - - - - - - - - - - - - - - - 
 7001 Avenel NJ
 7002 Bayonne NJ
 7003 Bloomfield NJ
 7004 Fairfield NJ

To format the postal code , you may want to use the following SQL.

SQL> SELECT *
 2 FROM
 3 (SELECT u.* ,
 4 TO_CHAR(postalcode ,’fm00000') formatted_zipcode
 5 FROM uszipcode u
 6 WHERE state = ‘NJ’
 7 )
 8 WHERE rownum < 5;

POSTALCODE CITY         ST      FORMAT
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 7001      Avenel        NJ     07001
 7002      Bayonne       NJ     07002
 7003      Bloomfield    NJ     07003
 7004      Fairfield     NJ     07004

Originally published at https://zahirmohideen.blogspot.com/2012/02/how-to-format-zipcode-postal-code-in.html


메타데이터
post_id
d3cfc115536d
slug
how-to-format-zipcode-postal-code-in-oracle-d3cfc115536d
url
https://medium.com/@zahirmohideen/how-to-format-zipcode-postal-code-in-oracle-d3cfc115536d
canonical_url
https://medium.com/@zahirmohideen/how-to-format-zipcode-postal-code-in-oracle-d3cfc115536d
author_url
https://medium.com/@zahirmohideen
status
ok
fetched_at
2026-08-12 13:14:57