I have one of the column audit_info
with JSON data in the table:
{
"AddInfo":{
"UPN":"[email protected]",
"UserName":"[email protected]",
"TimeStamp":"2021-10-11T15:54:34:4805634Z",
"Source":"xyz"
},
"ChangeInfo":{
"UPN":"[email protected]",
"UserName":"[email protected]",
"TimeStamp":"2021-10-11T15:54:34:4832421Z",
"Source":"xyz"
}
}
I need to update TimeStamp of seconds decimal point from :4832421Z
to .4832421Z
Can anyone please help me?
update the_table
set audit_info=??
2
Answers
Try replace. This replace the json field an text and then you convert it again an json. It should be something like this:
Original Question:
If you do not have
{:}
anywhere else then you can use replace:fiddle
Updated Question:
On later Oracle versions, if you want to update the last
:
to.
in the paths$.AddInfo.TimeStamp
and$.ChangeInfo.TimeStamp
then you can use useJSON_TABLE
to extract the timestamps and then simple string functions to extract the components before and after the last:
and then useJSON_MERGEPATCH
to update the specific paths:Then, for the sample data, after the
MERGE
the table contains:If you do not want to worry about specific paths then you can use a regular expression to match the timestamp:
fiddle