Sql oracle 11g中解码时的CLOB到CHAR问题

Sql oracle 11g中解码时的CLOB到CHAR问题,sql,plsql,oracle11g,clob,Sql,Plsql,Oracle11g,Clob,我正在编写一个查询,以提取可用格式的数据,供供应商迁移到新系统。该查询以前用于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(QUES

我正在编写一个查询,以提取可用格式的数据,供供应商迁移到新系统。该查询以前用于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.

任何帮助都将不胜感激。

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

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

SQL语句只能对小于4000字节的字符串进行操作。如果字符串较长,则将其视为CLOB而不转换为字符串。