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:
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.
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,’ ‘,’’);
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 ...
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for