while using group concat in query I am not able to get all the event
group name due to default length of group concat is 1024 so how I can
set max_length of group concat in existing code.
我有一个代码,我在使用group concat并设置max len
==========================================================================
DATA_QUERY="set group_concat_max_len=10024;
select group_concat(eg.name) from event_groups eg left join theatres t ON t.theatre_id = eg.theatre_id group by t.theatre_id order by t.application_name"
Session session = getFacadeLookup().getPersistenceFacade().getHibernateSession();
Query query = session.createsqlQuery(DATA_QUERY) and execute
List
最佳答案
首先尝试设置group_concat_max_len:
session.doWork(connection -> {
try(Statement statement = connection.createStatement()) {
statement.execute("SET GLOBAL group_concat_max_len=10024");
}
});
或Java 8之前的语法:
session.doWork(new Work() {
@Override
public void execute(Connection connection) throws sqlException {
try (Statement statement = connection.createStatement()) {
statement.execute("SET GLOBAL group_concat_max_len=10024");
}
}
});
然后才执行您的查询:
Query query = session.createsqlQuery(
"select group_concat(eg.name) " +
"from event_groups eg " +
"left join theatres t ON t.theatre_id = eg.theatre_id " +
"group by t.theatre_id order by t.application_name");
List
原文地址:https://www.jb51.cc/spring/431551.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。