I would like to update the column value as '12345,123456'. Earlier it was '12345123456'. I am using the following query
UPDATE TABLE_NAME
SET COLUMN_NAME = '12345,123456'
WHERE TC_ID = 'ABCD'
But it is showing error as Error converting data type varchar to float.
Please help.
Unless your internationalization settings say otherwise, commas are not allowed in numeric values. And apparently, they are not on your machine.
Use a period:
UPDATE TABLE_NAME
SET COLUMN_NAME = 12345.123456
WHERE TC_ID = 'ABCD';
Note that no single quotes are needed for a number.
If you are passing in a string, you can replace the comma with a .:
UPDATE TABLE_NAME
SET COLUMN_NAME = REPLACE(:val, ',', '.')
WHERE TC_ID = 'ABCD';
The database should convert the value automatically.
Or, divide by 1,000,000:
UPDATE TABLE_NAME
SET COLUMN_NAME = COLUMN_NAME / 1000000
WHERE TC_ID = 'ABCD';
Related
I'm having difficulty with a simple issue.
I have a number column a typical value is say 192.123.
I want to add/subtract a single value to it, say -100.123.
I assume it is
Update table_name
SET column_name = (the original value - 100.123)
How should I go about this?
You need to use '+' instead of '-'. So that it will add or subtract based on the input value.
Update table_name SET column_name = (column_name + Value_to_add_subtract)
use the column_name in original_value
Update table_name SET column_name = (column_name - 100.123)
use columnName instead of original value
update table_name
SET column_name = (column_name - 100.123)
I am using oracle 11g DB and in one of the table having varchar column has data which has trailing spaces. I have tried TRIM function to update the column but still the space at the end of the string prevails. What can be the reason for the trailing space? and how to fix this issue.
Column contents are displayed as below.
select '<'||mycol||'>' from mytab
Output : <mysamplestring >
select DUMP(mycol) from mytab
Output : Typ=1 Len=28: 67,114,117,100,101,32,80,101,116,114,111,108,101,117,109,32,69,120,116,114,97,99,116,105,111,110,194,160
Thanks
Using UNISTR did the trick for me. It removed the characters 160 and 194
update mytab set mycol = REPLACE(mycol,unistr('\00A0'),'')
trim() should work as expected! Sure it is a varchar2 column not a char column?
update hr.countries t
set t.country_name = t.country_name || ' ';
update hr.countries t
set t.country_name = trim(t.country_name);
Change the column type from char to varchar2, char column blank-pads the value with spaces to fill up the size of the field. So for a char(10) column, when you insert 'abc', it will automatically be inserted as 'abc '
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));
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:]]+',' ');
I have a table (SQL Sever) which references paths (UNC or otherwise), but now the path is going to change.
In the path column, I have many records and I need to change just a portion of the path, but not the entire path. And I need to change the same string to the new one, in every record.
How can I do this with a simple update?
It's this easy:
update my_table
set path = replace(path, 'oldstring', 'newstring')
UPDATE [table]
SET [column] = REPLACE([column], '/foo/', '/bar/')
I tried the above but it did not yield the correct result. The following one does:
update table
set path = replace(path, 'oldstring', 'newstring') where path = 'oldstring'
UPDATE CustomReports_Ta
SET vchFilter = REPLACE(CAST(vchFilter AS nvarchar(max)), '\\Ingl-report\Templates', 'C:\Customer_Templates')
where CAST(vchFilter AS nvarchar(max)) LIKE '%\\Ingl-report\Templates%'
Without the CAST function I got an error
Argument data type ntext is invalid for argument 1 of replace function.
You can use this query
update table_name set column_name = replace (column_name , 'oldstring' ,'newstring') where column_name like 'oldstring%'
all answers are great but I just want to give you a good example
select replace('this value from table', 'table', 'table but updated')
this SQL statement will replace the existence of the word "table"
(second parameter) inside the given statement(first parameter) with the third parameter
the initial value is this value from table but after executing replace function it will be this value from table but updated
and here is a real example
UPDATE publication
SET doi = replace(doi, '10.7440/perifrasis', '10.25025/perifrasis')
WHERE doi like '10.7440/perifrasis%'
for example if we have this value
10.7440/perifrasis.2010.1.issue-1
it will become
10.25025/perifrasis.2010.1.issue-1
hope this gives you better visualization
select replace(ImagePath, '~/', '../') as NewImagePath from tblMyTable
where "ImagePath" is my column Name. "NewImagePath" is temporery
column Name insted of "ImagePath" "~/" is my current string.(old
string) "../" is my requried string.(new string)
"tblMyTable" is my table in database.
you need to replace path with the help of replace function.
update table_name set column_name = replace(column_name, 'oldstring', 'newstring')
here column_name refers to that column which you want to change.
Hope it will work.
If target column type is other than varchar/nvarchar like text, we need to cast the column value as string and then convert it as:
update URL_TABLE
set Parameters = REPLACE ( cast(Parameters as varchar(max)), 'india', 'bharat')
where URL_ID='150721_013359670'
You also can replace large text for email template at run time, here is an simple example for that.
DECLARE #xml NVARCHAR(MAX)
SET #xml = CAST((SELECT [column] AS 'td','',
,[StartDate] AS 'td'
FROM [table]
FOR XML PATH('tr'), ELEMENTS ) AS NVARCHAR(MAX))
select REPLACE((EmailTemplate), '[#xml]', #xml) as Newtemplate
FROM [dbo].[template] where id = 1