0

我有一个表(ResponseData),其中列 RESPONSE_ID、RESPONSEDATA、KEY1、KEY2、KEY3、KEY4、VALUE1、VALUE2、VALUE3、VALUE4 用户可以插入以下任何类别的数据。

  • 1,"我的回复一","姓名",null,null,null,"Apple",null,null,null
  • 2、"我的回复二","姓名","年龄",null,null,"Apple","22",null,null

稍后在不同页面中,当用户请求 name="Apple",age="32" 的 Responsedata 应该返回记录 1,因为如果用户请求 name="Apple" age="22" 应该返回记录 1 和2 因为它与记录 1 按名称匹配,记录 2 按名称和年龄匹配。

在这种情况下我们如何形成搜索查询。我尝试使用utl_match.jaro_winkler_similarity如下表上的记录数。感谢您的投入。

4

1 回答 1

0
declare
  cursor c(k1 varchar2,
           k2 varchar2,
           k3 varchar2,
           k4 varchar2,
           v1 varchar2,
           v2 varchar2,
           v3 varchar2,
           v4 varchar2)
   is(select *
        from (select ResponseData.*,
                     case
                       when    (k1 = key1 and v1 <> value1)
                            or (k1 = key2 and v1 <> value2)
                            or (k1 = key3 and v1 <> value3)
                            or (k1 = key4 and v1 <> value4)
                            or (k2 = key1 and v2 <> value1)
                            or (k2 = key2 and v2 <> value2)
                            or (k2 = key3 and v2 <> value3)
                            or (k2 = key4 and v2 <> value4)
                            or (k3 = key1 and v3 <> value1)
                            or (k3 = key2 and v3 <> value2)
                            or (k3 = key3 and v3 <> value3)
                            or (k3 = key4 and v3 <> value4)
                            or (k4 = key1 and v4 <> value1)
                            or (k4 = key2 and v4 <> value2)
                            or (k4 = key3 and v4 <> value3)
                            or (k4 = key4 and v4 <> value4)
                       then 'not match'
                       else 'match'
                     end ok
                from ResponseData)
       where ok = 'match'
          or ok = 'not match');  -- debug mode
begin
  for r in c('name', null, null, 'age', 'Apple', null, null, '22') loop
    dbms_output.put_line(r.id||': ('||r.key1||'=>'||r.value1||'), ('||r.key2||'=>'||r.value2||'), ('
                                    ||r.key3||'=>'||r.value3||'), ('||r.key4||'=>'||r.value4||') - '||r.ok);
  end loop;
end;
于 2016-12-05T13:50:24.420 回答