1

我正在编写一个查询以提取可用格式的数据,以便供应商迁移到新系统。该查询以前在 oracle 9i 数据库上处理相同的数据、相同的表等。我们最近不得不将该数据库升级到 Oracle 11g。这是我的声明:

SELECT ACTIVITY_TRACKER_ID,
  MAX(DECODE(PROTOCOL_NUMBER, NULL, TO_CHAR(PROTOCOL_NUMBER1), TO_CHAR(PROTOCOL_NUMBER))) PROTOCOL_NUMBER,
  MAX(DECODE(QUESTION_ID, '1', TO_CHAR(COMMENT_NOTES))) RESEARCHPURPOSE,
  MAX(DECODE(QUESTION_ID, '-1060', TO_CHAR(COMMENT_NOTES))) NOOFSUBJECTS,
  MAX(DECODE(QUESTION_ID, '-1253', TO_CHAR(COMMENT_NOTES))) CONDUCTING,
  ''RESEARCHFUNDED,
  MAX(DECODE(QUESTION_ID,'-1332',TO_CHAR(ANS_CHOICE_NAME))) THESIS,
  MAX(DECODE(QUESTION_ID,'-1172',TO_CHAR(ANS_CHOICE_NAME))) IRBREVIEW,
  MAX(DECODE(QUESTION_ID,'-1175',TO_CHAR(ANS_CHOICE_NAME))) US,
  ''HUMANSUBJECTS,
  MAX(DECODE(QUESTION_ID,'-1337',TO_CHAR(ANS_CHOICE_NAME))) HEALTHINFO,
  ''SUBJECT_DATA_YESNO1,
  MAX(DECODE(QUESTION_ID,'-1079',TO_CHAR(COMMENT_NOTES))) SUBJECTDATA_YESNO1_EXPLAIN,
  ''SUBJECT_DATAYESNO2,
  MAX(DECODE(QUESTION_ID,'-1232',TO_CHAR(COMMENT_NOTES))) SUBJECTDATA_YESNO2_EXPLAIN,
  MAX(DECODE(QUESTION_ID,'-1233',TO_CHAR(COMMENT_NOTES))) SUBJECTDATA_3,
  MAX(DECODE(QUESTION_ID,'-1173',TO_CHAR(COMMENT_NOTES))) EXTERNALIRB,
  MAX(DECODE(QUESTION_ID,'-1173',TO_CHAR(COMMENT_NOTES))) EXTERNALIRBSTATUS,
  MAX(DECODE(QUESTION_ID,'-1173',TO_CHAR(COMMENT_NOTES))) EXTERNALIRBAPPROVALTXT,
  ''EXTERNALIRBAPPROVALDOC,
  ''INTLPERMDOC,
  MAX(DECODE(QUESTION_ID,'-1176',TO_CHAR(COMMENT_NOTES))) INTLSTAFFKNOWLEDGE,
  MAX(DECODE(QUESTION_ID,'-1176',TO_CHAR(COMMENT_NOTES))) INTLCUSTOMS,
  MAX(DECODE(QUESTION_ID,'-1176',TO_CHAR(COMMENT_NOTES))) INTLRISK,
  MAX(DECODE(QUESTION_ID,'-1176',TO_CHAR(COMMENT_NOTES))) INTLCOMM,
  MAX(DECODE(QUESTION_ID,'-1176',TO_CHAR(COMMENT_NOTES))) INTLSTUDYCHANGE,
  MAX(DECODE(QUESTION_ID,'-1176',TO_CHAR(COMMENT_NOTES))) INTLTRAINING,
  MAX(DECODE(QUESTION_ID,'-1176',TO_CHAR(COMMENT_NOTES))) INTLCITI
FROM
  (SELECT IRB_SUB_LAST_ACTIVITY.ACTIVITY_TRACKER_ID,
    IRB_SUBMISSIONS.PROTOCOL_NUMBER,
    IRB_SUBMISSIONS.PROTOCOL_TITLE,
    SUB2.PROTOCOL_NUMBER AS PROTOCOL_NUMBER1,
    IRB_COMMENTS.COMMENT_NOTES,
    IRB_ANS_CHOICE_LIST.ANS_CHOICE_NAME,
    IRB_SUB_QUES_ANSWERS.QUESTION_ID
  FROM IRB_SUBMISSIONS
  FULL JOIN IRB_SUB_LAST_ACTIVITY
  ON IRB_SUB_LAST_ACTIVITY.SUBMISSION_ID = IRB_SUBMISSIONS.SUBMISSION_ID
  FULL JOIN IRB_SUBMISSIONS SUB2
  ON IRB_SUBMISSIONS.PARENT_SUBMISSION_ID = SUB2.SUBMISSION_ID
  FULL JOIN IRB_SUB_QUES_ANSWERS
  ON IRB_SUBMISSIONS.SUBMISSION_ID = IRB_SUB_QUES_ANSWERS.SUBMISSION_ID
  AND SUB2.SUBMISSION_ID           = IRB_SUB_QUES_ANSWERS.SUBMISSION_ID
  FULL JOIN IRB_ANS_CHOICE_LIST
  ON IRB_SUB_QUES_ANSWERS.ANS_CHOICE_ID = IRB_ANS_CHOICE_LIST.ANS_CHOICE_ID
  FULL JOIN IRB_COMMENTS
  ON IRB_SUB_QUES_ANSWERS.COMMENT_ID = IRB_COMMENTS.COMMENT_ID
  )
GROUP BY ACTIVITY_TRACKER_ID

运行查询时,我收到以下错误:

ORA-22835: Buffer too small for CLOB to CHAR or BLOB to RAW conversion (actual: 4316, maximum: 4000)
22835. 00000 -  "Buffer too small for CLOB to CHAR or BLOB to RAW conversion (actual: %s, maximum: %s)"
*Cause:    An attempt was made to convert CLOB to CHAR or BLOB to RAW, where
           the LOB size was bigger than the buffer limit for CHAR and RAW
           types.
           Note that widths are reported in characters if character length
           semantics are in effect for the column, otherwise widths are
           reported in bytes.
*Action:   Do one of the following
           1. Make the LOB smaller before performing the conversion,
           for example, by using SUBSTR on CLOB
           2. Use DBMS_LOB.SUBSTR to convert CLOB to CHAR or BLOB to RAW.

任何帮助将不胜感激。

4

1 回答 1

3

不完全确定为什么它以前像这样在 9i 上工作,但在 11g 上却没有,但我只需要使用 DBMS_LOB.SUBSTR 来获取数据,然后合并我导出的电子表格中的列以提供给供应商。IE:

SELECT ACTIVITY_TRACKER_ID,
  MAX(DECODE(PROTOCOL_NUMBER, NULL, TO_CHAR(PROTOCOL_NUMBER1), TO_CHAR(PROTOCOL_NUMBER))) PROTOCOL_NUMBER,
  MAX(DECODE(QUESTION_ID, '1', DBMS_LOB.SUBSTR(COMMENT_NOTES,4000,1))) RESEARCHPURPOSE1,
   MAX(DECODE(QUESTION_ID, '1', DBMS_LOB.SUBSTR(COMMENT_NOTES,4000,4001))) RESEARCHPURPOSE2
FROM
  (SELECT IRB_SUB_LAST_ACTIVITY.ACTIVITY_TRACKER_ID,
    IRB_SUBMISSIONS.PROTOCOL_NUMBER,
    IRB_SUBMISSIONS.PROTOCOL_TITLE,
    SUB2.PROTOCOL_NUMBER AS PROTOCOL_NUMBER1,
    IRB_COMMENTS.COMMENT_NOTES,
    IRB_ANS_CHOICE_LIST.ANS_CHOICE_NAME,
    IRB_SUB_QUES_ANSWERS.QUESTION_ID
  FROM IRB_SUBMISSIONS
  FULL JOIN IRB_SUB_LAST_ACTIVITY
  ON IRB_SUB_LAST_ACTIVITY.SUBMISSION_ID = IRB_SUBMISSIONS.SUBMISSION_ID
  FULL JOIN IRB_SUBMISSIONS SUB2
  ON IRB_SUBMISSIONS.PARENT_SUBMISSION_ID = SUB2.SUBMISSION_ID
  FULL JOIN IRB_SUB_QUES_ANSWERS
  ON IRB_SUBMISSIONS.SUBMISSION_ID = IRB_SUB_QUES_ANSWERS.SUBMISSION_ID
  AND SUB2.SUBMISSION_ID           = IRB_SUB_QUES_ANSWERS.SUBMISSION_ID
  FULL JOIN IRB_ANS_CHOICE_LIST
  ON IRB_SUB_QUES_ANSWERS.ANS_CHOICE_ID = IRB_ANS_CHOICE_LIST.ANS_CHOICE_ID
  FULL JOIN IRB_COMMENTS
  ON IRB_SUB_QUES_ANSWERS.COMMENT_ID = IRB_COMMENTS.COMMENT_ID
  )
GROUP BY ACTIVITY_TRACKER_ID
于 2013-09-09T19:50:51.830 回答