How to remove blank spaces in SQL

Written by stephen byron cooper Google
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to remove blank spaces in SQL
Data entry usually needs to be cleaned up. (Jupiterimages/ Images)

SQL stands for “Structured Query Language.” It is the standard language for querying relational databases. Entire programs can be written in SQL and different flavours of the language evolved. These include SQL*Plus, T-SQL, MySQL and PL/SQL. Fortunately, all types of SQL have very simple methods for removing blank spaces.

Skill level:


  1. 1

    Use the replace function, which is available in SQL*Plus, PL/SQL, MySQL and T-SQL. Format output by using replace in a select statement. For example, to strip all blank spaces from the contents of a variable called “avar”: SELECT replace(avar, ‘ ‘,’’) avar FROM dual; The replace function can replace any character or string of characters with another character or string of characters. It will replace every instance of the match pattern.

  2. 2

    Strip out all spaces in a variable while inserting it into the database by embedding the replace function into the insert statement. Again, the example uses a variable called “avar”: INSERT INTO atable (acolumn) VALUES(replace(avar,’ ‘,’’);

  3. 3

    Remove spaces from a variable before comparing it to a constant or another variable value if you can’t be sure that the two do not have spaces: IF replace(avar,’ ‘,’’) == ‘Tuesday’ THEN ...

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.