我正在编写一个查询,以便以可用的格式提取数据,供供应商迁移到新系统。该查询以前在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.
非常感谢任何帮助。
答案 0 :(得分:3)
不完全确定为什么它在9i之前就像这样工作但不在11g但是我只需要使用DBMS_LOB.SUBSTR来获取数据然后合并我导出的电子表格中的列以提供给供应商。即:
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