[TL;DR] Use a MERGE
statement:
MERGE INTO Table1 dst
USING Table2 src
ON ( src.invoiced_value = dst.invoiced_value )
WHEN MATCHED THEN
UPDATE SET invoiced_date = TRUNC( src.invoiced_date ) + INTERVAL '3:56:24' HOUR TO SECOND;
Can i use the following query?
No, an UPDATE
statement does not have a FROM
clause. You would need to use a correlated sub-query or a MERGE
statement.
can i append the date like this to_date(e.invoiced_date ||' 3:56:24', 'MM/DD/YYYY HH:MI:SS')
?.
Maybe ... but you should not do it this way. TO_DATE( string_value, format_model )
takes a string as the first argument (and the ||
string concatenation operator also requires string arguments to concatenate) so your e.invoiced_date
will be implicitly converted from a DATE
to a string and your expression is effectively:
to_date(
TO_CHAR(
e.invoiced_date,
( SELECT value FROM NLS_SESSION_PARAMETERS WHERE PARAMETER = 'NLS_DATE_FORMAT' )
) || ' 3:56:24',
'MM/DD/YYYY HH:MI:SS'
)
If your NLS_DATE_FORMAT
session parameter is MM/DD/YYYY
then your query will work. If it is something different then your query will either raise an exception or work but give incorrect results. Since NLS_DATE_FORMAT
is a session parameter and each user can set it to whatever value they want then you should not rely on this to be consistent.
Instead, add an interval literal to the date (which does not require any conversions to-or-from a string):
TRUNC( src.invoiced_date ) + INTERVAL '3:56:24' HOUR TO SECOND
Or explicitly convert the date to a string in the correct format:
TO_DATE( TO_CHAR( e.invoiced_date, 'MM/DD/YYYY' ) || ' 3:56:24', 'MM/DD/YYYY HH24:MI:SS' )