存储过程查询数据库字段的相似度

2021/9/2 2:06:24

本文主要是介绍存储过程查询数据库字段的相似度,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

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;
    }

  



这篇关于存储过程查询数据库字段的相似度的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程