zoukankan      html  css  js  c++  java
  • 存储过程查询数据库字段的相似度 IT

    create or replace procedure p_compare(p_name    IN varchar2,
            po_result in out SYS_REFCURSOR)
            is
    begin
      OPEN po_result FOR
        select *
          from (select t.*,
                       UTL_MATCH.edit_distance_similarity(p_name, t.item_name) AS xsd
                  FROM T_CATALOG_MESSAGE t
                 where t.data_valid_flag = '1')
         where 1 = 1
           and xsd > 40
         order by xsd desc;
    end p_compare;
    

      java调用存储过程

    /**
         * 根据事项名称查询所有复核条件的事项
         * @param filterMap
         * @param pageDesc
         * @return
         */
        public JSONArray queryAllItemByitemName(Map<String, Object> filterMap, PageDesc pageDesc) {
        	String itemName=String.valueOf(filterMap.get("itemName"));
        	JSONArray jsonArray =new JSONArray();
        	//模糊查询
        	/*sql+=" select * from  t_catalog_message t where t.data_valid_flag  = '1'   "
            		+" [:(like)itemName | and t.item_name like :itemName ] "
            		+"[ :departmentLineId| and INSTR(:departmentLineId,T.department_line_id)>0 ] "
            		+" order by t.ins_time desc ";*/
        	String sql ="";
            /*sql+=" select * from ("
            		+ " select t.*, UTL_MATCH.edit_distance_similarity('1',t.item_name) AS xsd FROM T_CATALOG_MESSAGE t "
    				+" where t.data_valid_flag  = '1' )"
    				+ " where 1=1 and  xsd>40 "
            		+"[ :departmentLineId| and INSTR(:departmentLineId,T.department_line_id)>0 ] "
            		+" order by xsd desc ";*/
            /*QueryAndNamedParams params = QueryUtils.translateQuery(sql.toString(), filterMap);
            JSONArray jsonArray = DatabaseOptUtils.listObjectsByNamedSqlAsJson(this, params.getQuery(), params.getParams(), pageDesc);*/
            
            CallableStatement cs=null;
            Connection connection=null;
            ResultSet rs = null;
            ResultSetMetaData md=null;
            try {
                connection= this.jdbcTemplate.getDataSource().getConnection();
                cs = connection.prepareCall("{call p_compare(?,?)}");
                cs.setString(1, itemName);
                cs.registerOutParameter(2, OracleTypes.CURSOR);
                cs.execute();
                rs = (ResultSet) cs.getObject(2);
                while (rs.next()) {
                	JSONObject jsonObject=new JSONObject();//
                	System.out.println(rs.getString(1) + " :  " + rs.getString(2)); 
                	jsonObject.put("itemName", rs.getString(3));
                	jsonObject.put("baseCode", rs.getString(4));
                	jsonArray.add(jsonObject);
                }
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }finally{
                try {
                    if(rs!=null){
                        rs.close();
                    }
                    if (cs!=null) {
                        cs.close();
                    }
                    if(connection!=null) {
                        connection.close();
                    }
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            return jsonArray;
        }
    

      

  • 相关阅读:
    docker 入门9篇文章
    shell获取 linux 系统的位数
    docker 查看容器详细
    VirtualBox 运行失败
    export 命令 设置环境变量
    查看内核启动顺序 设置默认启动内核
    生成 git 密钥 步骤
    初始化 二维数组
    关于开发环境 git 重新部署
    git-版本管理工具的介绍+发展史+分布式版本控制系统和集中式版本控制系统的区别
  • 原文地址:https://www.cnblogs.com/qxqbk/p/15216363.html
Copyright © 2011-2022 走看看