使用 R 从 Oracle 数据库中提取 table

Extract a table from the Oracle database using R

我正在尝试通过给出日期条件

使用 R 从 Oracle 数据库中提取 table

以下是我运行在R中的代码:

pw14.db.train<-sqlQuery(myconn,"select * from r_input where snapshot_date <='16-01-2015'")

但是我收到以下错误:

[1] "HY000 1843 [Oracle][ODBC][Ora]ORA-01843: not a valid month\n"                                     
[2] "[RODBC] ERROR: Could not SQLExecDirect 'select * from r_input where snapshot_date <='16-01-2015'

snapshot_date 列的日期格式。在数据库 table 上是“23-07-14”。

使用日期列时我需要编写的正确查询应该是什么?

由于你在Oracle上的列是日期类型,你需要将字符串'16-01-2015'转换成日期类型:

pw14.db.train <- sqlQuery(myconn,"select * from r_input where snapshot_date <=  to_date('16-01-2015', 'dd-mm-yyyy') ")

然后您的查询将正常工作。