Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ROracle dbWriteTable to write POSIXct back to Oracle DB

In Oracle DB:

DESCRIBE ORACLE_DB_TABLE;

|---------------------------------------|
| Column Name      | Data Type          |
|---------------------------------------|
| TRANSACTION_TIME | DATE               |
| TRANSACTION_ID   | VARCHAR2 (20 Byte) |
| TRANSACTION_AMT  | NUMBER (38,10)]    |
|---------------------------------------|

In R:

> r_data_table
      TRANSACTION_TIME TRANSACTION_ID TRANSACTION_AMT
1: 2015-04-28 11:12:24            ABC             123
> dbWriteTable(conn, "ORACLE_DB_TABLE", r_data_table, overwrite = F, append = T, row.names = F)
> Error in .oci.WriteTable(conn, name, value, row.names = row.names, overwrite = overwrite,  :
  Error in .oci.ValidateZoneInEnv(FALSE) :
  environment variable 'ORA_SDTZ()' must be set to the same time zone region as the the environment variable 'TZ(Europe/London)'
> dbGetQuery(conn, "SELECT SESSIONTIMEZONE FROM DUAL")
  SESSIONTIMEZONE
1   Europe/London

As you can see from the error message, I've set the environment variable TZ in R = "Europe/London". Also, from the query above, you can see that the session time zone in Oracle is 'Europe/London' as well.

Why is the error message complaining that the time zone is different between Oracle and R?

How can I write a POSIXct from R to a DATE column in Oracle DB?

like image 781
chengcj Avatar asked Apr 28 '15 10:04

chengcj


1 Answers

The following works:

> Sys.setenv(TZ = "GMT")
> Sys.setenv(ORA_SDTZ = "GMT")
> dbWriteTable(conn, "ORACLE_DB_TABLE", r_data_table, overwrite = F, append = T, row.names = F)
like image 166
chengcj Avatar answered Sep 17 '22 21:09

chengcj