So what I need is to append a string in a column on a firebird database everytime I run the update, I'm trying:
update clients set cliobs = coalesce(cliobs, '') || 'newstring' where cod = 1
I get the 1 record(s) was(were) updated but the end result is:
coalesce(cliobs, ') || newstring
Any ideas how to do this?
Related
I have a table in which there is a column name associated_ids with datatype as varchar2(4000). It contains a value and i need to append the new value with existing value. Using below update query:
update ncl_getafix.service_graph
set Associated_ids = Associated_ids + ',' + '95d4980b-d12c-4854-97c6-bd9854f8f003'
where SERVICE_ID='075d7a58-7fad-4e1d-9822-83a2fa1a0d05';
I am getting below error:
Error starting at line : 5 in command - update
ncl_getafix.service_graph set
Associated_ids=Associated_ids+','+'95d4980b-d12c-4854-97c6-bd9854f8f003'
where SERVICE_ID='075d7a58-7fad-4e1d-9822-83a2fa1a0d05'
Error report - ORA-01722: invalid number.
Can anyone help to debug this.
You need to use concat operator || not + as follows:
update ncl_getafix.service_graph
set Associated_ids = Associated_ids || ',' || '95d4980b-d12c-4854-97c6-bd9854f8f003'
where SERVICE_ID='075d7a58-7fad-4e1d-9822-83a2fa1a0d05';
i found the answer.
Use || symbol instead of + in query
How do I make the query like this?
UPDATE DUA_DATA_FIL_AUD
SET REV = :rev,
SYS_UPDT_TS = :now
WHERE DUA_DATA_FIL_ID = 283
AND REV = 2524;
And so on for all the next 13 records and update all the corresponding columns?
Create a result of dynamic update queries using a select form the table you want to apply the updates on it's result set.
This shall create you a sort of script that you can copy and run in your command window to update the desired lines.
Hope this addresses what you really want :
SELECT 'UPDATE DUA_DATA_FIL_AUD SET REV = :rev, SYS_UPDT_TS = :now WHERE
DUA_DATA_FIL_ID =' || DUA_DATA_FIL_ID || 'AND REV =' || MAX(REV) || ';/'
FROM DUA_DATA_FIL_AUD GROUP BY DUA_DATA_FIL_ID,REV
Here what I'm trying to do..
Table name: Message_Actions
column: Forward_details
In Forward_detail column, I have strings values like:
EIioT
TIoH
EI
and so on..
I want to simply add the letter G at the end of each string without altering the existing
tried:
update Message_actions
set forward_details = forward_details || 'G' ;
no luck
but
update Message_actions
set forward_details = 'forward_details' || 'G' ;
results in forward_detailsG
Maybe you should use trunc(forward_details) || 'G'
I am using following script to generate objects in C# from Oracle and it works ok.
select 'yield return new Question { QuestionID = '||Q.questionid||', Qcode = "'||Q.Qcode||'", QuestionDescription = "'||Q.questiondescription||'", QuestionText = "'||Q.questiontext||'", QuestionCategoryId = '||Q.questioncategoryid||', QuestionTypeID = '||Q.QuestionTypeID||', IsThunderheadOnly = '|| case q.isthunderheadonly when 0 then 'false' else 'true' end ||', DisplayOrder = '||q.displayorder||' };'
from QUESTION q
where
questioncategoryid = 7
However again and again I run into the problem where I cannot || add columns with NULL values and solution to this point was adding those properties manually, which was ok when selecting up to 20 records.
Now I ran into a case of having to select hundreds of records and adding them manually would take substantial amount of time.
How could I modify the script to add (example) MaxValue property if column in the table is NOT NULL but skip it it if it is?
You can skip it with case ... when ... else like you figured out by yourself:
... ||case when A.NEXTQUESTIONID is not null then 'NextQuestionID = '||A.NEXTQUESTIONID||',' else '' end || ...
You can also use the nvl2 function for a shorter solution:
... || nvl2(A.NEXTQUESTIONID, 'NextQuestionID = '||A.NEXTQUESTIONID||',', '') || ...
anyone can help me with this. I created a trigger in firebird. I have this line that uses concatenation.
NEW.FIELDNAME = FIELD1 || FIELD2;
but it is not working, no record has been inserted. Is there any way for string concatenation? THANKS IN ADVANCE!
here is my full trigger
*query that initiate the variable PREV_STATUS:
SELECT FIRST 1 PREV_STATUSPERMINS FROM C3_EQUIPTSTATEPERMIN
WHERE TESTERID = NEW.TESTERID ORDER BY DATEMODIFIED DESC INTO :PREV_STATUS;
IF(PREV_STATUS IS NULL) THEN
BEGIN
NEW.PREV_STATUSPERMINS = '000';
END
ELSE
BEGIN
NEW.PREV_STATUSPERMINS = PREV_STATUS || NEW.STATUS;
END
You should use the "new" keyword to access the values of your fields within a trigger :
new.fieldname = new.field1 || new.field2;
Also, don't forget that if either of the fields is null, the concatenation will be null. If you want to avoid that, you could do something like this :
NEW.FIELDNAME = coalesce(new.FIELD1, '') || coalesce(new.FIELD2, '')