如何在oracle中使用translate函数进行搜索重复?

时间:2015-04-17 09:54:37

标签: sql oracle

我有问题使我的postgresql查询适应oracle

SELECT id, name, firstName
  FROM myschema.individus
  WHERE translate(trim(lower(name)),'éèêëàâäîïôöùûüçÉÈ','eeeeaaaiioouuucee') || 
        translate(trim(lower(firstName)),'éèêëàâäîïôöùûüçÉÈ','eeeeaaaiioouuucee') in
          (SELECT translate(trim(lower(name)),'éèêëàâäîïôöùûüçÉÈ','eeeeaaaiioouuucee') ||
                  translate(trim(lower(firstName)),'éèêëàâäîïôöùûüçÉÈ','eeeeaaaiioouuucee')
             FROM myschema.individus
             group by translate(trim(lower(name)),'éèêëàâäîïôöùûüçÉÈ','eeeeaaaiioouuucee') ||
                      translate(trim(lower(firstname)),'éèêëàâäîïôöùûüçÉÈ','eeeeaaaiioouuucee')
             HAVING COUNT (c) > 1)
  ORDER BY name, firstName

对于我的重复搜索,我将名称和名字连接到||运算符,我使用translate作为重音符号。但是HAVING中的count函数返回0,所以我的查询返回0行。

如果我删除了having语句,我会得到很多结果。

如果我使用:

having count(translate(trim(lower(name)),'éèêëàâäîïôöùûüçÉÈ','eeeeaaaiioouuucee') ||
             translate(trim(lower(Firstname)),'éèêëàâäîïôöùûüçÉÈ','eeeeaaaiioouuucee')) > 0

没有结果。

1 个答案:

答案 0 :(得分:0)

我建议稍微重写一下查询:

SELECT id, name, firstName
  FROM myschema.individus
  WHERE translate(trim(lower(name)),'éèêëàâäîïôöùûüçÉÈ','eeeeaaaiioouuucee') || 
        translate(trim(lower(firstName)),'éèêëàâäîïôöùûüçÉÈ','eeeeaaaiioouuucee') in
          (SELECT translate(trim(lower(name)),'éèêëàâäîïôöùûüçÉÈ','eeeeaaaiioouuucee') ||
                  translate(trim(lower(firstName)),'éèêëàâäîïôöùûüçÉÈ','eeeeaaaiioouuucee'),
                  COUNT(*) AS cnt
             FROM myschema.individus
             group by translate(trim(lower(name)),'éèêëàâäîïôöùûüçÉÈ','eeeeaaaiioouuucee') ||
                      translate(trim(lower(firstname)),'éèêëàâäîïôöùûüçÉÈ','eeeeaaaiioouuucee')
             HAVING cnt > 1)
  ORDER BY name, firstName

如果它不接受HAVING cnt > 1,请使用HAVING COUNT(*) > 1

分享并享受。