Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8087581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:49:21+00:00 2026-06-05T18:49:21+00:00

I have thousands of rows that contain a zipcode attribute with four integers in.

  • 0

I have thousands of rows that contain a zipcode attribute with four integers in.
Some rows contain five integers, and some other contain two, or three integers.

What I want to do is to add a 0 before rows that contain only four integers.
The tablename is zipcode and the attribute too.

I want to update the rows and not show them !

I tried this code with no luck (no row affected) :

UPDATE zipcode
SET zipcode = CONCAT('0', zipcode)
WHERE CHAR_LENGTH(zipcode) = 4

Btw, I can use CHAR_LENGTH in a simple select, and it works :

SELECT *
FROM zipcode
WHERE CHAR_LENGTH(zipcode) = 4

So, seems that the CHAR_LENGTH doesn’t work in my WHERE clause.

EDIT: zipcode is an int.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T18:49:23+00:00Added an answer on June 5, 2026 at 6:49 pm

    It sounds like you are storing the zipcode as an int, but you really want to treat it as a char.

    In that case you have a couple of options:

    1) Change the datatype of the column and then execute your update to left pad with 0:

    alter table zipcode
      modify column zipcode char(5) not null;
    
    update zipcode
    set zipcode = lpad(zipcode,5,'0')
    where char_length(zipcode) < 5;
    

    2) Leave the datatype as is, and just format the data on retrieval by left-padding with 0 in the select statement:

    select lpad(zipcode,5,'0')
    from zipcode;
    

    Demo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have hundreds of thousands of rows with four date columns that were imported
I have many tens of thousands of rows of data that need to be
Assume that I have thousands of rows to update. And I plan to do
I have some data consisting of 2 columns and thousands of rows. The first
What I have: two columns of text data, that are given to contain only
I have a table that contains several thousand rows, having a Varchar column that
I have a table (table variable in-fact) that holds several thousand (50k approx) rows
I have a database table with thousands of rows. I would like to run
I have a table with a few thousand rows. The table contains two columns,
I have thousands of jpg files that are all called 1.jpg, 2.jpg, 3.jpg and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.