Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have table Like This

ID | Propinsi | Kota |
_________________________
 1 | Aceh     | Denpasar
 2 | Aceh     | Banda Aceh
 3 | Sumatera | Asahan

This table have many rows

The Problem is I want Replace the Space berfore text on column Kota for All ROw like this

ID | Propinsi | Kota |
_________________________
 1 | Aceh     |Denpasar
 2 | Aceh     |Banda Aceh
 3 | Sumatera |Asahan

I search on Googel the function replace on mysql only effect to one rows

SELECT REPLACE(string_column, 'search', 'replace') as Kota

can Someone fix my problem?

Iam Very Appreciated your answer.

Thanks

share|improve this question
1  
you could use LTRIM to remove all leading whitespaces: java2s.com/Code/PostgreSQL/String-Functions/ltrimname.htm –  cptPH Dec 3 '13 at 10:18
    
@Patrick Thanks :) –  Uchsun Dec 4 '13 at 1:13

1 Answer 1

up vote 1 down vote accepted

Try this:

To show without space:

select trim(kota) from yourtable

To change your data:

update yourtable set kota = trim(kota);

TRIM function is different to REPLACE. REPLACE substitutes all occurences of a string, instead TRIM remove only the space at the start and at the end of your string

If you want remove only from the start you can use LTRIM instead about the end you can use RTRIM

share|improve this answer
    
Thanks, it Work Great. –  Uchsun Dec 4 '13 at 1:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.