1

I am looking to read in the data that is stored as a CLOB value in my Oracle database. The contents simply are HTML that renders emails that we send through our CRM application. I want to re-create images of the email to include in my reports on crm performance.

I can successfully read the data into SPSS using the following query, which converts the CLOB to a string of length (32750).

GET DATA
  /TYPE=ODBC
  /CONNECT='DSN=<MYDSN>;UID=<USER>;PWD=mypassword;Host=myhost;Port=myport;SID='+
    'SID'
  /SQL='SELECT *  FROM mytable'
  /ASSUMEDSTRWIDTH=32750.
CACHE.
EXECUTE.
DATASET NAME clob_query WINDOW=FRONT.

What I am looking to do is perform a similar query but read the data into R. I attempted the following query and got the error below:

> SQL <-"SELECT to_char(CONTENT) as content from REL_EMAIL_TEMPLATE"
> ds <- sqlQuery(ch, SQL, as.is=T, stringsAsFactors=F)
> ds
[1] "HY000 22835 [Oracle][ODBC][Ora]ORA-22835: Buffer too small for CLOB to CHAR or BLOB to RAW conversion (actual: 5923, maximum: 4000)\n"
[2] "[RODBC] ERROR: Could not SQLExecDirect 'SELECT to_char(CONTENT) as content from REL_EMAIL_TEMPLATE'"   

I am not sure how I can make the "buffer" larger, but figure that because I accomplish this in SPSS that R must be able to do this as well.

Many thanks in advance.

4

2 回答 2

2

我觉得我必须在发布之前尝试过这个解决方案,但是我回到了这个问题并且能够让它运行。

这次唯一的区别是我只尝试使用WHERE子句将 1 条记录拉入 R。

这是我的查询:

SQL <- "SELECT TO_CHAR(CONTENT) FROM RELATEMGR.REL_EMAIL_TEMPLATE WHERE primary_key = 1"
body <- sqlQuery(ch, SQL, stringsAsFactors=F)

诡异的。不确定 R 的不同版本是否也很重要,但至少这让我到达了我需要的地方。

只是为了完整起见:

> sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RODBC_1.3-6

loaded via a namespace (and not attached):
[1] tools_2.15.0
于 2012-11-15T14:32:06.473 回答
0

试试这个,我认为 TO_CHAR MAX 大小是 4000:

"SELECT dbms_lob.substr(CONTENT, 32767, 1 ) AS content FROM REL_EMAIL_TEMPLATE"
于 2012-08-31T14:43:58.817 回答