I get an error when i try to do this using SQL. ftp.server is the key whose value i would like to change:
UPDATE OL_PREF SET ftp.server='dev.isinet.com'
If the column name is really ftp.server, then the correct Oracle syntax for updating it should be
UPDATE OL_PREF SET "ftp.server" ='dev.isinet.com'
In Oracle, double quotes are the correct way to handle column names that have non-standard characters, including lower-case letters and the period. Note that you must have the exact correct column name for this to work, including case.
You can verify the column name with:
SELECT column_name FROM user_tab_columns WHERE table_name='OL_PREF' ORDER BY column_name;
If what you really mean is that you have a table that stores key-value pairs, and that 'ftp.server' is a key, then you probably want an update like the one in Mark Wilkins' answer.
UPDATE OL_PREF SET [ftp.server]='dev.isinet.com'
or
UPDATE OL_PREF SET [ftp].[server]='dev.isinet.com'
if ftp is a schema and server is the fieldname.
You can't put the column name in quotes.
You could use brackets, which have the same functionality as quotes.
UPDATE OL_PREF SET [ftp.server] ='dev.isinet.com'
Also, it's a good idea to use "two part naming", specifying the schema as well:
UPDATE dbo.OL_PREF SET [ftp.server] ='dev.isinet.com'
UPDATE OL_PREF
SET ftp.server ='dev.isinet.com'
no '' for column names
SQL Update
'ftp.server' is in quotes. (and that should not be)
Are you getting the error ORA-00904 string : invalid identifier?
If so read this
I did a quick test on this
SQL> create table t_tab_1 ( tname varchar2(3), "ftp.service" varchar2(20) );
Table created.
SQL> insert into t_tab_1(tname,"ftp.service") values('21','ftp://fila');
1 row created.
SQL> update t_tab_1 set "ftp.service"='fila.real.com';
1 row updated.
If there is more than I row in your table remember to use the where clause in your update statement.
Related
We have Oracle table having default keyword(i.e in as field name) field name.Now i am querying table but unable to extract specific field data.
select a.filename,a.in from table a
Following error appears "invalid field name.
Try using double quotes.
select a."IN" from table a
You can use default (oracle reserved) keywords as the name of the columns but yes it is not advisable to use it.
Anyway, If you want to use oracle reserved keywords then you must have to enclose them in the double-quotes.
Note that oracle is case insensitive in terms of its object names until and unless it is wrapped in the double-quotes. it means if you enclose any object name in double-quotes then you must have to use them anywhere in the entire DB as case sensitive manner.
So if your table definition is:
CREATE TABLE YOUR_TABLE ("IN" NUMBER);
Then you need to use "IN" wherever you want to refer the column but if your table definition is:
CREATE TABLE YOUR_TABLE ("in" NUMBER);
Then you need to use "in" wherever you want to refer the column. -- case sensitive names.
I hope it will clear all your doubts.
Cheers!!
I have a SQL table with a column named "FileLink" and I need to add the domain name at the end of the server name for all the existing records in the table. So it would be like this:
Before:
\\ServerName\SharedFolder\Test.PDF
After:
\\ServerName.domain.net\SharedFolder\Test.PDF
So I need to add ".domain.net" to the link. Is there a sql statement to do this?
TIA
If you need to modify only one domain and this value is unique you can use REPLACE:
update Table
set Column = REPLACE(Column, 'ServerName', 'ServerName.domain.net')
If you don't want to use the replace statement you can do it like this:
Declare
#SrvName as varchar(50)
Set #SrvName = '\\ServerName'
Select
'\\ServerName.domain.net'+Substring(FileLink,Len(#SrvName)+1,Len(FileLink)-Len(#SrvName))
If the servername is the same for each record you could do it with the replace statement. Otherwise you might want to use patindex to find the first occurence of a '\' starting from position 3 to determin the place you need to insert the extra text.
If you want to prevent any issue if you run the query against old and new records, you should use
REPLACE(FileLink, '\\ServerName\', '\\ServerName.domain.net\')
Which gives:
SELECT
SELECT REPLACE(FileLink, '\\ServerName\', '\\ServerName.domain.net\') AS FileLinkUpdated
FROM MyTable
UPDATE
UPDATE MyTable
SET FileLink = REPLACE(FileLink, '\\ServerName\', '\\ServerName.domain.net\')
Note that this is assuming you don't have a link with only \\ServerName
I want to update a column value. But my Update procedure statement updates even the value of the this column is the same.
UPDATE TableName
SET ColumName=#ParameterName
WHERE Id=#ParameterId
Any Idea?
Thank you.
From what I get from your post, you are wondering why MySQL is updating even when the value is not changed. Well, you don't check beforehand if the value is really different, so that's just what an update statement with an ID does...
You can add additional condition AND (COALESCE(ColumName,'')<>COALESCE(#ParameterName,'')
so you're only updating when those are different.
UPDATE TableName
SET ColumName=#ParameterName
WHERE (Id=#ParameterId) AND (COALESCE(ColumName,'')<>COALESCE(#ParameterName,''))
The coalsece in my example assumes that ColumnName is of type varchar if is a numeric value use AND (COALESCE(ColumName,0)<>COALESCE(#ParameterName,0) instead.
I'm trying to add a column named order to my table. I realize that order is a reserved word in SQL. So, how do I do it?
My command:
alter table mytable add column order integer;
I've also tried:
alter table mytable add column 'order' integer;
PostgreSQL 9.1.
Use this:
alter table mytable add column "order" integer;
But, you might want to consider using a non-reserved name instead, like sort_order or something similar that reflects what the column is used for (and isn't a reserved word).
I think you don't need "column". Plus "order" is a keyword in SQL, so you should use a different name for your column. Follow this syntax:
ALTER TABLE table_name ADD column_name datatype
Source: W3Schools
ALTER TABLE table_name
ADD COLUMN "order" integer
You are using order which is a reserved keyword you should consider renaming that to something like orders. And the problem should go away.
I have a set of json format stored in a column and now i need to replace a particular word. How to use the replace query. Every time i use it, i'm getting token exception. please advise. Its a DB2 i'm using
I have 3 columns
Name Age Data
ABD 15 [{"Name":"ABC","type":"Regular","Math":18}]
In the Data column, I need to do a replace for "type", It should be StudentType.
REPLACE(Data,'type','StudentType');
This did not work. How to do it?
Thanks much in advance
Just like #mustaccio pointed out, if you use REPLACE in select statement it will just return your data with 'StudentType' instead of 'type'. This does not actually change data in your database. If you want to update your data you need UPDATE statement
UPDATE MyTable
SET MyColumn = REPLACE(MyColumn,'OldString','NewString')