java timestamp with timezone to store in ORACLE DB - oracle

I need to insert Timestamp with Timezone in Oracle DB using java JDBC. I have a timestamp in one variable and need to append Timezone, like Europe/Paris, to my timestamp and store it in the DB which has a column of datatype Timestamp with Timezone.
How can I achieve that?

Related

CurrentTime() generated from Pig showing as NULL in Hive Datetime column

In Pig script I have generated datetime column with its value as CurrentTime().
While reading the data from Hive Table for the output generated by PigScript, it shows as NULL.
Is there any way that I can load the current datetime column from PIG to show in Hive Table?
The data in the file looks like 2020-07-24T14:38:26.748-04:00 and in the hive table the column is of timestamp datatype
Hive timestamp should be in 'yyyy-MM-dd HH:mm:ss.SSS' format (without T and timezone -04:00)
1.Define Hive column as STRING
2.Transfom string to format compatible with Hive timestamp
If you do not need milliseconds:
--use your string column instead of literal
from_unixtime(unix_timestamp('2020-07-24T14:38:26.748-04:00',"yyyy-MM-dd'T'HH:mm:ss.SSSX"))
Returns:
2020-07-24 18:38:26
If you need milliseconds then additionally extract milliseconds and concatenate with transformed timestamp:
select concat(from_unixtime(unix_timestamp('2020-07-24T14:38:26.748-04:00',"yyyy-MM-dd'T'HH:mm:ss.SSSX")),
'.',regexp_extract('2020-07-24T14:38:26.748-04:00','\\.(\\d{3})',1))
Result:
2020-07-24 18:38:26.748
Both results are compatible with Hive timestamp and if necessary can be cast explicitly to Timestamp type using CAST(str as timestamp) function, though comparing these strings with timestamps or inserting into timestamp works without explicit cast.
Alternatively you can format timestamp in Pig to be 'yyyy-MM-dd HH:mm:ss.SSS' I do not have Pig and can not check how ToString works.
Also for LazySimpleSerDe, alternative timestamp formats can be supported by providing the format to the SerDe property "timestamp.formats" (as of release 1.2.0 with HIVE-9298). Try "yyyy-MM-dd'T'HH:mm:ss.SSSX"

Timezone for COMMIT_TIMESTAMP in V$LOGMNR_CONTENTS

In V$LOGMNR_CONTENTS dictionary view the TIMESTAMP and COMMIT_TIMESTAMP columns are of DATE data type - without any timezone information. So which timezone are they in - database timezone, host timezone, or UTC? Is there a database parameter to configure their timezone?
I guess it is the time zone of database server's operating system. Simply because SYSDATE which might be used for insert is also returned in the time zone of database server's operating system.
Perhaps Oracle uses DATE data type instead of TIMESTAMP data type for historical reasons. I don't know when TIMESTAMP was introduced but certainly DATE came earlier.
When a SELECT statement is executed against the V$LOGMNR_CONTENTS view, the archive redo log files are read sequentially. These archive redo log files are the ones present into the archive log destination. Translated records from the redo log files are returned as rows in this view. This continues until either the filter criteria specified at startup (EndTime or endScn) are met or the end of the archive log file is reached.
The field TIMESTAMP is the Timestamp when the database change was made. This timestamp corresponds to the SCN transformation SCN_TO_TIMESTAMP, so that for a given SCN you have a correspondent timestamp.
The field COMMIT_TIMESTAMP is the timestamp when the transaction was committed; only meaningful if the COMMITTED_DATA_ONLY option was chosen in a DBMS_LOGMNR.START_LOGMNR() invocation. As you know, querying the redo logs and archive logs require that you invoke this package in a log miner session.
Actually, Oracle uses sometimes DATE data types when it probably should use TIMESTAMP in a lot of different dictionary fields. Why ? I honestly don't know, it is the same when they use for some dictionary views owner, for others table_owner and for others owner_name.
The DBTIMEZONE is specified in the CREATE DATABASE statement, so in the moment you create the database. you can change the DBTIMEZONE by using ALTER DATABASE
alter database set time_zone = 'EST';
Keep in mind that altering the database time zone will only take effect after shutdown/startup, and it is not recommendable.
TIMESTAMP WITH TIME ZONE is a variant of TIMESTAMP that includes a time zone region name or time zone offset in its value. The time zone offset is the difference (in hours and minutes) between local time and UTC (Coordinated Universal Time, formerly Greenwich Mean Time).
Oracle Database normalizes all new TIMESTAMP WITH LOCAL TIME ZONE data to the time zone of the database when the data is stored on disk.Oracle Database does not automatically update existing data in the database to the new time zone. Therefore, you cannot reset the database time zone if there is any TIMESTAMP WITH LOCAL TIME ZONE data in the database. You must first delete or export the TIMESTAMP WITH LOCAL TIME ZONE data and then reset the database time zone. For this reason, Oracle does not encourage you to change the time zone of a database that contains data.
An example of my case: I have an Oracle Database in Azure ( where all the servers are using UTC ) In my case I chose to use UTC instead of using a different DBTIMEZONE. Then I created a function to transform any timestamp stored in any table to my time zone.
I wonder why you need to read the redo/archive logs, do you have to recover some lost transactions ? I hope the explanation is satisfactory, please don't hesitate to comment or ask whatever other doubts you may have.

how to format oracle.sql.TIMESTAMP#64b6887

We are using timestamp datatype in oracle 10g. in database data
coming properly but in the app the timestamp will come like oracle.sql.TIMESTAMP#31c2bcfc.
{"isSuccessful":true,"resultSet":[{"PAN_NUMBER":"befpd9907G","NATIONALITY":"Indian","GUARDIAN_NAME":"guard1","THIRD_APPLICANT":"Third","MOTHER_MAIDEN_NAME":"Mother","ACCOUNT_TYPE":"AccType","MARITAL_STATUS":"Mststus","STATE":"state","CARD_TYPE":"def","MINOR":"no","EDUCATION":"double","LAST_NAME":"last","SSN_NUMBER":"ssn34","FIRST_NAME":"first","PIN_CODE":"5600","EXPIRY_DATE":"oracle.sql.TIMESTAMP#7a628b9a","AADHAR_NUMBER":"123456789012","COUNTRY":"coun","ANNUAL_INCOME":4.25,"PREFERRED_NAME":"prefered","CATEGORY":"Gen","SECOND_APPLICANT":"Second","GENDER":"gender","APPLICATION_FORM_DATE":"oracle.sql.TIMESTAMP#31c2bcfc"}]}
Where did i do a mistake?

converting sybase datetime format to oracle timestamp

I am getting bellow datetime format from sybase DB
2015-08-12T11:49:50.196+01:00
and i need to insert this value into oracle database column of type TIMESTAMP(6).
i am not able to specify the correct format to insert the above datetime in to Timestamp column in oracle.
can any one help me in this.
thanks in advance.
Are you sure that you don't want to store time zone information (thus type TIMESTAMP(6) WITH TIME ZONE)?
CREATE TABLE timestamp (value TIMESTAMP(6));
INSERT INTO timestamp VALUES (TO_TIMESTAMP_TZ('2015-08-12T11:49:50.196+01:00', 'YYYY-MM-DD"T"HH24:MI:SS.FF3 TZH:TZM'));

Informatica Date/Time Conversion

in one of the requirment informatica fetching data from flat file as source file and insert records into a temporary table temp of DB2 database. Flat file has one column as datetime datatype (YYYY/MM/DD HH:MM:SS). However, informatica fetching this column as string datatype (Since Informatica date format is different from this column & DB2). So before loading into temp table of DB2 database, I need to convert back this column into Datetime format.
With Expresion transformation, I can do this but I dont know how? To_date conversion function (TO_DATE(FIELD, 'YYYY/MM/DD HH:MM:SS')) is there but it will take care of date only (YYYY/MM/DD). Its not taking care of time (HH:MM:SS) and because of this records are not inserting into temp table.
How can I convert datetime from String datatype to DB2 datetime format (YYYY/MM/DD HH:MM:SS)?
You tried to use the month format string (i.e. MM) for the minutes part of the date.
You need to use MI:
TO_DATE(FIELD, 'YYYY/MM/DD HH:MI:SS')

Resources