how do I insert an Oracle TIMESTAMP into a Derby TIMESTAMP - sql

So I have some Oracle TIMESTAMP in a SQL dump from my Oracle database. And I want to import that into the Derby database. In Oracle, the SQL statement is looking like:
Insert into TABLE_NAME (COL1, COL2, COL3)
values (
'blah',
to_timestamp('17-MAR-11 15.52.25.000000000','DD-MON-RR HH24.MI.SS.FF'),
'blah'
);
COL2 has type TIMESTAMP here. When I run it in Derby, I predictably get "Error: 'TO_TIMESTAMP' is not recognized as a function or procedure."
So how do I insert a TIMESTAMP in Derby, and more specifically, how would I convert the above SQL statement to a SQL statement which is executable in Derby?

As Derby is a Java database you will be accessing it through JDBC, therefor you can use the JDBC escape format to specify a timestamp value:
INSERT INTO TABLE_NAME (COL1, COL2, COL3)
VALUES ('blah', {ts '2011-03-17 15:52:25'}, 'blah');
But it will require you to reformat the literal value into ISO format.
The above statement would work with Oracle as well, if run through a JDBC tool.

Related

"failed to evaluate expression" when fiddling with INSERT INTO on DataBricks SQL

I receive the following error when I try to insert into a casted date in my table
Error in SQL statement: AnalysisException: failed to evaluate expression to_date('01.01.2016', 'dd.mm.yyyy'): Cannot evaluate expression: to_date(01.01.2016, Some(dd.mm.yyyy)); line 2 pos 1
insert into E_Par_Holidays
values
('BE', to_date('01.01.2016', 'dd.mm.yyyy'));
The table is defined as:
create table E_Par_Holidays (
Country varchar(255),
Holiday date
);
And oddly the following SQL statement works like a charm:
SELECT to_date('01.01.2016', 'dd.mm.yyyy') as DateExample;
Thank you for your help!
I fixed it by using insert into select logic
insert into E_Par_Holidays
SELECT 'BE', to_date('01.01.2016', 'dd.mm.yyyy');
you shouldn't use insert statement in spark sql.
instead use dataframe writer api
dataframe.write.mode(SaveMode.append).jdbc(...)
You can use following: insert into alfiya.timestamptbl values(cast('0001-01-01 17:00:00.000 +0300' as timestamp ));

Run query from MariaDB on Oracle

I have MariaDB and Oracle databases. I have set up ODBC Connect between the two, so that I can access Oracle from MariaDB.
I can do the following from MariaDB:
CREATE TABLE oracopy ENGINE=connect TABLE_TYPE=ODBC tabname='testtab' CONNECTION='DSN=ORCL';
This creates a table locally.
What I really want to do however is run a Query on the remote Oracle and return the results to the MariaDB session.
The query would be Oracle speficic, i.e. might containing ORACLE functions like DECODE. Also the query could include a PLSQL function call which again would need to be run on Oracle. E.g:
SELECT t.id, DECODE( t.typ,'HH', 'Val 1', 'Val 2' ) tt,
my_package.fn_test ( t.dob ) dob
FROM testtab t;
Does MariaDB have a "run this query on XXX remote database".
Consider using the source definition argument, SRCDEF, as shown in docs.
CREATE TABLE oracopy ENGINE=connect TABLE_TYPE=ODBC CONNECTION="DSN=ORCL"
SRCDEF="SELECT t.id, DECODE( t.typ,'HH', 'Val 1', 'Val 2' ) tt,
my_package.fn_test ( t.dob ) dob
FROM testtab t;"

How to insert multiple values in 11g?

How to insert multiple values in a table in oracle 11g using query?
I tried This
Use the following DML known as INSERT ALL statement :
insert all into departmentstrigger values(4,'Hello')
into departmentstrigger values(5,'HEy There')
into departmentstrigger values(6,'sup')
into departmentstrigger values(7,'Hii')
select * from dual;
SQL Fiddle Demo
For a detailed explanation you may look at : Insert All Statement

is it possible to insert data where null value is locating by using insert into keyword

Insert into table_name
values('hyd') where col1 isnull;
INSERT syntax can't have WHERE clause. You can use INSERT INTO command for this type of use case.

Using cast in insert statement

I am inserting some raw data into a table in MS SQL 2005 from excel.
Some of these data are not formatted correctly ie the amount colum is formatteT as a number 12345 whereas i need to be like 123.45 so i use this
CAST(TRANSACTION_HISTORY.AMOUNT AS decimal) / 100
to convert it correctly.
However is there a way to use the cast in an insert statement??
thanks
You can use CAST in any kind of statement(Insert, update, delete, select) where you use data.
Insert into table1 values( CAST(col1 as nvarchar(50)) )
I assume you're using a linked server or openquery to get the data from excel. You can cast in the select statement.
So
INSERT INTO YourTable
SELECT Cast(Transaction_History.Amount AS Decimal)/100
FROM EXCELLINK...[$Sheet1]
You could also just update all values in the table after you do the import
UPDATE YourTable
SET YourColumn = YourColumn/100