我正在使用 postgres 9.1 和 jdbc 的 java 代码。
我可以在我的sql查询字符串
中使用order by
子句
我只是想获取查询的元数据
信息来查找查询是否有order by
子句。如果有,则在 order by 子句
中指定了多少个字段。
例如:
按年龄排序
按年龄、姓名排序
按年龄升序、姓名降序排列
在这些示例中,我只想检索 order by 子句中指定的参数数量及其列名称。
最佳答案
如果您将查询作为字符串获取,您可以简单地解析它。
即找出 ORDER BY 的存在
"SELECT * FROM MyTable ORDER BY SomeColumn".toLowerCase().indexOf("order by") // if it's return -1 query does not contains order by section otherwise it returns start index for first occurence "ORDER BY" in given string
对于更复杂的字符串搜索,您可能需要使用 RegExp
关于java - 如何获取sql查询的元数据信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13915134/