当前位置: 首页 > 知识库问答 >
问题:

使用oracle函数pivot进行查询的Java准备语句

陆昕
2023-03-14
select * from table (PIVOT ( ' select A, B, SUM(C) from TABLE_XYZ where A =' 'abcd' ' GROUP BY A, B ORDER BY A ASC ' )) order by A;

共有1个答案

易超
2023-03-14

您可以使用string.format(<使用格式说明符的字符串格式,如%s或%d等>, ) 。对于您的查询;可以这样写:

String query = String.format('select * from table (PIVOT ('select A, B, SUM(C) from TABLE_XYZ where A =' %s ' GROUP BY A, B ORDER BY A ASC')) order by A;',  'abcd');

因此,您的查询将如下所示(abcd不带引号):

选择*from table(PIVOT('select A,B,SUM(C)from TABLE_XYZ,其中A='abcd'GROUP BY A,B ORDER BY A asc'))ORDER BY A;

String query = String.format('select * from table (PIVOT ('select A, B, SUM(C) from TABLE_XYZ where A =' %s ' GROUP BY A, B ORDER BY A ASC')) order by A;',  '\'abcd\'');
 类似资料: