Problems gist:
- 问题 1:
- 我有几个变量(太大了..每个 2K)需要 连接到最终内容。这是一个实习生列表。 Oracle concat无法concat超过4k,导致我出现太长concat异常
- 问题 2:
- 当我尝试解决问题 1 时,将这些变量放入 java 中 VO(ValueObject) 并连接成java字符串。问题是我有一个 由以下命令创建的InstructionType列表和AdditionalInfo子列表 这个查询2,我无法将多行设置为单个 字符串。尝试使用字符串数组列表。
**
** 我有一个 mybatis 查询,看起来像这样。Problem 1 Description:
<select id="xyz" parameterType="com.test.VO" resultMap="abc" fetchSize="100" resultSetType="FORWARD_ONLY">
select tag.TAG_desc TAGNAME,
(det.tag_val_1 || det.tag_val_2 || det.tag_val_3 || det.tag_val_4 ||
det.tag_val_5 || det.tag_val_6 || det.tag_val_7 || det.tag_val_8 ||
det.tag_val_9 || det.tag_val_10) TAGVALUE,
det.tag_no||lpad(det.sub_fld, 2, '0') TAGID
from A det, B tag
where det.brch_code = #{branchCode}
and det.prod_ref_id = #{refId}
and det.tnx_id= #{tnxId}
and det.msg_type= #{messageNumber}
and det.msg_type = tag.msg_type
and (det.tag_no = tag.tag_no or substr(det.tag_no, 0, 2) = tag.tag_no )
and (det.tag_no = rpad(tag.tag_no, 3, '_') )
and det.tag_val_1 is not null
</select>
<resultMap id="abc" type="com.test.InstructionType$AdditionalInfo">
<result property="name" column="TAGNAME" />
<result property="id" column="TAGID" />
<result property="content" column="TAGVALUE" />
</resultMap>
它给了我以下错误:
; uncategorized SQLException for SQL []; SQL state [72000]; error code [1489]; ORA-01489: result of string concatenation is too long
; nested exception is java.sql.SQLException: ORA-01489: result of string concatenation is too long
tag_val_1 到 tag_val_10 最多可以有 2K 个字符,这导致了上述问题。
Problem 2 Description:
尝试将 tag_val 获取到 ValueObject(VO) 并在 java 中进行连接。
看起来有点像
<select id="XYZ" parameterType="com.test.OutboundInterfaceVO" resultMap="abc" fetchSize="100" resultSetType="FORWARD_ONLY">
select tag.TAG_desc TAGNAME,
(det.tag_val_1||det.tag_val_2)TAGVAL12,
(det.tag_val_3||det.tag_val_4 )TAGVAL34,
(det.tag_val_5||det.tag_val_6 )TAGVAL56,
(det.tag_val_7||det.tag_val_8||det.tag_val_9 || det.tag_val_10) TAGVALUE710,
from A det, B tag
where det.brch_code = #{branchCode}
and det.prod_ref_id = #{refId}
and det.tnx_id= #{tnxId}
and det.msg_type= #{messageNumber}
and det.msg_type = tag.msg_type
and (det.tag_no = tag.tag_no or substr(det.tag_no, 0, 2) = tag.tag_no )
and (det.tag_no = rpad(tag.tag_no, 3, '_') )
and det.tag_val_1 is not null
</select>
<resultMap id="abc" type="com.test.OutboundInterfaceVO">
<result property="tagName" column="TAGNAME" />
<result property="tagId" column="TAGID" />
<result property="tagVal12" column="TAGVAL12" />
<result property="tagVal34" column="TAGVAL34" />
<result property="tagVal56" column="TAGVAL56" />
<result property="tagVal710" column="TAGVAL710" />
</resultMap>
case1>尝试认为它返回一行(我的错)
private String tagName;
private String tagId;
private String tagVal12;
private String tagVal34;
private String tagVal56;
private String tagVal710;
案例2>查询成功返回,没有ORA错误(在PL/SQL Dev中检查)
这次问题出在结果图中。
返回了大约 30 行,尝试将它们捕获为字符串列表,
private List<String[]> tagName = new ArrayList<String[]>();
private List<String[]> tagId = new ArrayList<String[]>();
private List<String[]> tagVal12 = new ArrayList<String[]>();
private List<String[]> tagVal34 = new ArrayList<String[]>();
private List<String[]> tagVal56 = new ArrayList<String[]>();
private List<String[]> tagVal710 = new ArrayList<String[]>();
在java中循环如下。
List<InstructionType> instructionList = mapper.pqr(interfaceVO);
for (InstructionType instructionType : instructionList) {
------
mapper.XYZ(VO);
for (InstructionType.AdditionalInfo addlist : instructionType.getAdditionalInfo())
{
addlist.setID(interfaceVO.getTagId());
addlist.setName(interfaceVO.getTagName());
content.append(interfaceVO.getTagVal12());
content.append(interfaceVO.getTagVal34());
content.append(interfaceVO.getTagVal56());
content.append(interfaceVO.getTagVal710());
addlist.setContent(content.toString());
}
}
instructionDetails.getInstruction().addAll(instructionList);
我的InstructionType类,会有一点帮助
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "InstructionType", namespace = "http://www.db.com/tf", propOrder = {
"additionalInfo"
})
public class InstructionType {
@XmlElement(name = "AdditionalInfo", namespace = "http://www.abc.com/tf")
protected List<InstructionType.AdditionalInfo> additionalInfo;
...along with setters and getters
public static class AdditionalInfo {
@XmlValue
protected String content;
@XmlAttribute(name = "Name", required = true)
protected String name;
@XmlAttribute(name = "ID")
protected String id;
.....along with setters and getter in each class
}
}
Note: I have mybatis 3.2.2 and Oracle 11g, java 6
卡住了,伙计们,任何解决问题 1 并避免问题 2 的帮助都会很棒。 否则,请帮助我以更好的方式设置列表列表。
提前非常感谢您。
最佳答案
您从 Oracle DB 收到错误。这个和mybatis无关。错误信息非常清楚。
如果我是您,我会简单地在 Java 中而不是 SQL 中进行字符串连接。
关于java - 无法在 mybatis 查询中连接超过 4k 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19870898/