自学内容网 自学内容网

Orecle 迁移 人大金仓数据库 SQL 问题

1. start  with ...  connect by 语法不兼容

      使用 oracle 项目一般使用,start with ... connect by 语法做菜单栏数据查询,该语法在人大金仓数据库提供的可视化工具中可以执行,但在Springboot + mybatis 项目中无法执行(版本2.X),通过与人大金仓人员交涉,可以使用 with recursive.... as(... union ..) select ... where... 语法替代,该语法基础是如下:

      假设有如下一张表(menu_table):

idmenu_idparent_menu_idmenu_desc
11一级
21011二级
310101101三级
4101010110101四级

       我们可以使用一下 SQL查询出树状数据:

       with recursive temp as(

             select * from menu_table where id = 3

             union 

             select * from menu_table a  join  temp b on b.parent_menu_id = a.menu_id

         ) select * from temp

        该SQL执行结果如下:

idmenu_idparent_menu_idmenu_desc
11一级
21011二级
310101101三级

           SQL 语法分析: 

           SQL 中的 select * from menu_table where id = 3 查出来的数据,会作为初始基础数据,union 后面的SQL select * from menu_table a  join  temp b on b.parent_menu_id = a.menu_id ,  定义树状数据的规则,当前SQL是向上查询,使用基础数据中 parent_menu_id 值 101 为条件去    menu_table 表中查询 menu_id 值为 101 的数据,会递归处理直到不满足该条件为止            b.parent_menu_id = a.menu_id

          如果我们要向下查找数据要怎么做呢?把条件该为这样 b.menu_id = a.parent_menu_id 

2.数据精度问题  

      oracle 数据库 numeric 类型数据查询出的数据,不会默认在小数点后面补充无效的 0 ,人大金仓数据查询数据会默认在小数点后面做补充 0 操作,如果 java 接受数据使用 String 类型会出现小数点后面很多零问题,可以在数据库配置文件 url 配置信息,添加后缀:initParams=ignore_zero_number=on 忽略补充零

3.druid 连接池胡乱打印SQL报错

     oracle 数据库切换人大金仓数据库,使用 druid 监控 SQL 信息时,会出现 SQL 执行成功功能正常,但是日志文件中出现 SQL 解析报错信息,需要在 druid 配置文件中添加 druid.filter.stat.merge-sql = false 信息


原文地址:https://blog.csdn.net/sdfsfaffs/article/details/142713880

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!