oracle and hive timestamp - oracle11g

I have a vendor oracle DB storing values to a column creation_timestamp as timestamp(6) when i create an extract of that table and load it to HDFS and create hive schema with that column defined as timestamp it does not populate the field. However if I use string it is all there. I have other MSSQL datetime data that successfully stored as timestamp in hive so I am just a little unsure why the oracle timestamp data is not populating.
The oracle timestmap looks like this: 07-JAN-15 05.55.20.732754000 PM
I have a feeling hive does not like the month as letters as the documentation states:Strings: JDBC compliant java.sql.Timestamp format "YYYY-MM-DD HH:MM:SS.fffffffff" (9 decimal place precision)
How can I convert the oracle timestamp(6):07-JAN-15 05.55.20.732754000 PM to the java.sql.Timestamp format shown above?

I was able to alter my session and then export the table, hive has now accepted it as a timestamp
ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF';
07-JAN-15 05.55.20.732754000 PM is now: 2015-01-07 17:55:20.732754000

Use to_date in hive.
Example :
select TO_DATE(from_unixtime(UNIX_TIMESTAMP('7-MAR-13', 'd-MMMM-yy'))) from table_name
Refer : date functions

Related

How should I format my string to pass it to my database via TIBCO BW6?

I'm new to TIBCO BW6. This is my scenario. I have a .csv file, and one of my columns is a string in this format: '31/08/2021 15:18:00'
I created a process that reads my file and inserts a new row into my database. I have a problem with the date.
In my palette JDBC Update, the date is a timestamp. When I match the input, the right pattern for matching my string in datetime is pattern yyyy-mm-dd hh:mm:ss.
To do this kind of thing the best solution is generally to use the SQL database formatting functions in your SQL query.
Something like this (for ORACLE) :
insert into table_name
(my_date_field)
values (TO_DATE('2022/01/23 11:25:44', 'yyyy-mm-dd hh24:mi:ss'));
In BusinessWorks the query would look like this and you would have to map the value of the field corresponding to the '?' with your actual timestamp :
insert into table_name
(my_date_field)
values (TO_DATE(?, 'yyyy/mm/dd hh24:mi:ss'));

Inserting SAS datetime into Teradata using proc sql

I have a SAS datetime stored in a macro variable and try to write that into a timestamp column in teradata using proc sql. E.g. I can write that into a string column with %BQUOTE('&macrovariable') and it returns 14APR2020:06:47:20. But I am failing to convert that into a timestamp and write into timestamp field in teradata. Cast as timestamp did also not work :( It returns ERROR: Teradata execute: Invalid timestamp.
My Code:
INSERT INTO MYTABLEWITHDATETIMEFIELD
VALUES (
%BQUOTE('&macrovariable')
)
Could you help me out? THANKS!
Best regards
Flo

Sqlite get the date part of a DateTime and return as a DateTime, not a string

In Sqlite I want to extract the date and time portions of a DateTime field separately in a view and return them also as a datetime, not strings. I've tried Cast, Date(), datetime(), but they all return strings.
I've read the SQLite documentation and understand how there is not an actual Date data type. Yet a Table field defined as DateTime is able to be parsed as a Date by an Excel query, but calculations on that field are not. I'm trying to do all data prep in the database view.
My data has the following field taken directly from the table definition:
LastModifiedDate datetime
I want the date (without time) to have the same DateTime data type as LastModifiedDate, not Text, because I use this view in many spreadsheets. I can apply Excel Date functions and formatting to LastModifiedDate field directly as returned from the ODBC query to Excel, and want to do the same to the Date-only part. I don't want to have to put a string-to-date conversion in every spreadsheet when I know it can get the date natively from Sqlite in LastModifiedDate.
SELECT LastModifiedDate,
date(LastModifiedDate) as Datepart,
cast(LastModifiedDate as numeric) as Date2
FROM Transactions
LastModifiedDate Datepart Date2
2019-07-28 18:22:38.9165394 2019-07-28 2019
LastModifiedDate in the above query is interpreted in Excel as a date to which date formats and date functions can be applied with no further processing required. Datepart above is returned as Text to Excel, and I can't apply date functions and formats without further pre-processing in Excel. I would like Datepart to be interpreted a date in Excel just as LastModifiedDate is.
I'm looking at the ch-werner.de sqliteodbc-0.9998. It will return an ODBC TIMESTAMP type only if the column decltype starts with timestamp or datetime. It returns ODBC TIME only for decltypes starting with time and ODBC DATE only for decltypes starting with date.
sqlite3 provides this decltype only for result table columns that are direct database column references. So if your SELECT statement has some expression that is more than a plain column reference, the decltype is lost. sqlite3 works like this at least up to version 3.39.0. It is documented.
The CAST expression converts the value of given expression to a storage classes by the determined affinity of the given declared type, but does not assign decltype to the result.
If you want to see the decltypes for query columns, you can use the sqlite3 cli and give it command .stats 2. Then it'll output the column declared types for each statement it executes.
If the decltype is found, the sqliteodbc-0.9998 will always parse string values into ODBC types. If DSN Option JDConv is enabled, it'll also parse floating point julianday values (whether provided as float or a string of a float) into ODBC types and when writing it'll write floating point into database.
If you can afford to change the schema, you can add a generated virtual column. This is cheap in storage, because data is not affected, but it costs when you query the column. This column can calculate other column into the values and decltypes you need for ODBC.
ALTER TABLE data ADD COLUMN
Datepart date AS (date(LastModifiedDate))
Then to get the Datepart, you simply query the column.
SELECT Datepart FROM data

How to Implement Timestamp in oracle?

create table abc_test(
id number,
rv timestamp
);
insert into abc_test(id,rv) values (1, CURRENT_TIMESTAMP);
Is there any better way to do it?
Can the timestamp be stored in the database in some binary format like "01x0000000000046565".
In Microsoft sql, this can easily be done as below :
create table xyz_test(id1 timestamp, name varchar(50))
insert into xyz_test (Name) values('person1')
select * from xyz_test
The above query will show some binary form for the timestamp column and "person1" in the name column
How to get the same result in the oracle?
It is indeed stored in a binary format -- the tool that you are using translates it when it is retrieved.
Display of dates and timestamps is dependent on tool configuration, and on session settings etc.. You can read the timestamp in whatever format you like -- consult the documentation for To_Char(datetime).

How to change date format of a datetime object?

currently, i have a datetime object
DateTime theDateTime = DateTime.ParseExact(dateAndTime, "d MMMM yyyy hh:mm tt", provider);
which successfully converts it into a datetime (from a string) to become for example :
7/6/2012 9:30:00 AM
How do i convert this to become 2012/07/06 09:30:00 (24hr format)? So that i can insert it into the database using C#??
PS: I'm using Sybase SQL Anywhere 12, and from what I've read, they neeed the format to be in year/months/day and the time to be in 24hr format right? Please correct me if I'm wrong.
The DateTime itself does not have a format. The date and time are stored internally as a number. Usually the classes of the database provider take care of converting a DateTime to the correct format.
If Sybase will only accept the date formatted as a string you will need to use the DateTime.ToString method and format it with the correct format string.
How are you building your insert command? Are you using database parameters or just building a string containing the insert statement?
SQL Anywhere 12 has a default date format of YYYY-MM-DD HH:NN:SS.SSS
This can be configured/changed with the timestamp_format database option however:
timestamp_format option
The setting can be permanently changed through SQL like:
SET OPTION PUBLIC.timestamp_format = '<format here>';
Or temporarily changed (per connection basis) like:
SET TEMPORARY OPTION timestamp_format = '<format here>';
Of course, if you already have a datetime object in your code, you should be able to pass the value into a parameterized query. It doesn't have to be passed as a string.

Resources