Remove extra space from column values - sql

I have a column in Oracle database, where I had stored concatenated values. For example,
/uk/letters/default?/uk/letters/funny_letters?
/uk/letters/letters?/library/conditionalstyle?o=3&f=11/uk/letters/funny_letters?
/uk/workinglife/viewarticle_93?/library/conditionalstyle?/uk/financialcentre/car_tax_calculator?
/uk/job-hunting/default?/partners/msn/i-resignfinctr?/uk/letters/letters?/
In between the urls, there are some spaces in between. How can I remove them?

UPDATE YourTable
SET YourColumn = REPLACE(YourColumn, ' ', '')

This is too late but will help some one.
select regexp_replace(column_name, '[[:space:]]+', chr(32)) from table_name;
After verification , you can update the table as follows;
UPDATE table_name
SET column_name = REGEXP_REPLACE (column_name ,'[[:space:]]+',' ');

Related

Replacing all doubles quotes from SQL table

Im trying to remove all instances of double quotes from an entire SQL table, and replace these double quotes " " with signle quotes ' '.
Is there an efficient way to do this? thanks!
If you want to change the column names, you would need to update the table:
update tablename
select column_name = replace(column_name, '"', '')
where column_name like '%"%';
To replace double quotes with single quotes, simply do
Update table
set column=replace('"','''')
where column like '%"%'
If you just want to select that column without any double quote in it:
SELECT *,REPLACE(columnname, '"','') FROM tableName
If you want to update you column by replacing all the double quote(") then Gordon provided you the right answer.
update tablename select columnname = replace(columnname, '"', '') WHERE charindex('"',columnname)>0

How to remove newline from column values in Sybase

i have a table in sybase that has 7 columns.
The sixth column has a new line as the last character in all the values. This newline is messing up the output when i export the table. How can i remove the newline character from all values in this column ?
this did the trick
update tableName
set column_name =str_replace(column_name, char(13), null)
Depending on whether the newline is in windows or unix format, one of the below should work:
UPDATE tableName SET column_name = str_replace(column_name, char(13), null)
or
UPDATE tableName SET column_name = str_replace(column_name, CHAR(13) + CHAR(10), '')

Oracle Update Column LTRIM and RTRIM

I am wish to update my database data in SQL Developer using
UPDATE TABLE_NAME SET COLUMN_NAME = LTRIM(RTRIM(COLUMN_NAME))
But it does not take any effect even the msg of "rows updated" is displayed. The leading and trailing white spaces still exist behind every strings.
Any ideas?
Do you commit after update?
update tableName set col1 = trim(col1);
commit;
I had the same problem on two different tables. One the first table trim was ok, on the second no effect, the spaces were still there!
The difference was that in the first table I was using varchar2(30) and in the second table (where trim didn't work) I had char(30)
After modifying the second table from char(30) to varchar2(30) trim worked as expected.
Try this
UPDATE TABLE_NAME SET COLUMN_NAME = TRIM(COLUMN_NAME);
Trim Reference
Have you tried REGEXP_REPLACE(your column name, '\s*', '') ?
ex: UPDATE TABLE_NAME SET COLUMN_NAME = REGEXP_REPLACE(COLUMN_NAME, '\s*', '')
You get a message saying that n rows are updated because there are n rows in your table and you are applying the update to all of them.
To limit the update to only those rows where the update will have an effect, use:
UPDATE TABLE_NAME
SET COLUMN_NAME = LTRIM(RTRIM(COLUMN_NAME))
WHERE COLUMN_NAME != LTRIM(RTRIM(COLUMN_NAME));

Replace every comma in a column with a dot

Could someone tell me a query to replace every comma from a column 'myColumn' with a dot, without messing up with the numbers?
You would use an update statement:
update t
set myColumn = replace(myColumn, ',', '.')
where myColumn like '%,%'
Pruebe con:
UPDATE prices SET pvp = REPLACE(pvp, ',', '.');

Update column to insert spaces in one of the columns in sql server table

How do I achieve the following by a stored procedure or sql script in sql server?
Say for example, I have a-b in one of the columns and I need to update that column to a - b instead.
How do I insert spaces before and after the dash in existing data in my database.
UPDATE YourTable
SET YourColumn = REPLACE(YourColumn, '-', ' - ')
update TableName set ColumnName = Replace(ColumnName, '-', ' - ') where SomeCondition ...