我有一个本机查询,我想将参数传递给以下查询:
SELECT dqlist.*,score(1) AS rank FROM dq_list_hash_full dqlist WHERE contains(dqlist.dq_english_name,'definescore(fuzzy(, 1, 6, weight),relevance)',1) > 0
我正在使用问号运算符,但由于某种原因它无法理解并给我SQL语法异常:
这是我的尝试:
SELECT dqlist.*,score(1) AS rank FROM dq_list_hash_full dqlist WHERE contains(dqlist.dq_english_name,'definescore(fuzzy('?1', 1, 6, weight),relevance)',1) > 0
我的JPA回购方法:
@Query(nativeQuery = true,value="SELECT\r\n" +
" a.EXTERNALID_ENC,\r\n" +
" a.EXTERNALID,\r\n" +
" a.TELNUMBER,\r\n" +
" a.TELAREACODE,\r\n" +
" a.DQ_ENGLISH_NAME,\r\n" +
" a.DQ_ARABIC_NAME,\r\n" +
" a.NAMEFIELD_1,\r\n" +
" a.USAGETYPE,\r\n" +
" a.STATE,\r\n" +
" a.REGION,\r\n" +
" a.LOCALITY,\r\n" +
" a.ADDITIONALLOCALITYINFO,\r\n" +
" a.GEN_TEXT_7,\r\n" +
" a.GEN_SHORTTEXT_1,\r\n" +
" a.GEN_SHORTTEXT_4,\r\n" +
" a.GEN_SHORTTEXT_9,\r\n" +
" a.GEN_SHORTTEXT_10,\r\n" +
" a.CBCM_ENGLISH_NAME,\r\n" +
" a.CBCM_ARABIC_NAME,\r\n" +
" a.CBCM_EMIRATE_NAME,\r\n" +
" a.CBCM_PARTY_ID,\r\n" +
" a.CBCM_ACCOUNT_ID,\r\n" +
" a.RECORD_ID,\r\n" +
" a.DISPLAY_FLAG,\r\n" +
" a.DISPLAY_FLAG_GROUP,\r\n" +
" a.LONGITUDE,\r\n" +
" a.LATITUDE,\r\n" +
" a.NORMALIZED_ENGLISH_NAME,\r\n" +
" a.CBCM_PARTY_ENGLISH_NAME,\r\n" +
" a.CBCM_PARTY_ARABIC_NAME,\r\n" +
" a.MANUAL_UPDATE_FLAG,\r\n" +
" a.RULE_UPDATE_FLAG,\r\n" +
" a.BUSINESS_UPDATE_FLAG,\r\n" +
" a.EXCEL_UPDATE_FLAG\r\n" +
" \r\n" +
" FROM\r\n" +
" (\r\n" +
" SELECT\r\n" +
" *\r\n" +
" FROM\r\n" +
" (\r\n" +
" SELECT\r\n" +
" dqlist.*,\r\n" +
" score(1) AS rank\r\n" +
" FROM\r\n" +
" dq_list_hash_full dqlist\r\n" +
" WHERE\r\n" +
" contains(dqlist.dq_english_name,'definescore(fuzzy(?1, 1, 6, weight),relevance)',1) > 0\r\n" +
" UNION\r\n" +
" SELECT\r\n" +
" dqlist.*,\r\n" +
" score(1) AS rank\r\n" +
" FROM\r\n" +
" dq_list_hash_full dqlist\r\n" +
" WHERE\r\n" +
" contains(dqlist.dq_english_name,'!?1' ,1) > 0\r\n" +
" )\r\n" +
" ORDER BY\r\n" +
" rank DESC\r\n" +
" ) a\r\n" +
"")
public List<DqListHashFullEntity> findByEngName(@Param("englishName") String englishName);
@Query(value="SELECT\r\n" +
" a.EXTERNALID_ENC,\r\n" +
" a.EXTERNALID,\r\n" +
" a.TELNUMBER,\r\n" +
" a.TELAREACODE,\r\n" +
" a.DQ_ENGLISH_NAME,\r\n" +
" a.DQ_ARABIC_NAME,\r\n" +
" a.NAMEFIELD_1,\r\n" +
" a.USAGETYPE,\r\n" +
" a.STATE,\r\n" +
" a.REGION,\r\n" +
" a.LOCALITY,\r\n" +
" a.ADDITIONALLOCALITYINFO,\r\n" +
" a.GEN_TEXT_7,\r\n" +
" a.GEN_SHORTTEXT_1,\r\n" +
" a.GEN_SHORTTEXT_4,\r\n" +
" a.GEN_SHORTTEXT_9,\r\n" +
" a.GEN_SHORTTEXT_10,\r\n" +
" a.CBCM_ENGLISH_NAME,\r\n" +
" a.CBCM_ARABIC_NAME,\r\n" +
" a.CBCM_EMIRATE_NAME,\r\n" +
" a.CBCM_PARTY_ID,\r\n" +
" a.CBCM_ACCOUNT_ID,\r\n" +
" a.RECORD_ID,\r\n" +
" a.DISPLAY_FLAG,\r\n" +
" a.DISPLAY_FLAG_GROUP,\r\n" +
" a.LONGITUDE,\r\n" +
" a.LATITUDE,\r\n" +
" a.NORMALIZED_ENGLISH_NAME,\r\n" +
" a.CBCM_PARTY_ENGLISH_NAME,\r\n" +
" a.CBCM_PARTY_ARABIC_NAME,\r\n" +
" a.MANUAL_UPDATE_FLAG,\r\n" +
" a.RULE_UPDATE_FLAG,\r\n" +
" a.BUSINESS_UPDATE_FLAG,\r\n" +
" a.EXCEL_UPDATE_FLAG\r\n" +
" \r\n" +
" FROM\r\n" +
" (\r\n" +
" SELECT\r\n" +
" *\r\n" +
" FROM\r\n" +
" (\r\n" +
" SELECT\r\n" +
" dqlist.*,\r\n" +
" score(1) AS rank\r\n" +
" FROM\r\n" +
" dq_list_hash_full dqlist\r\n" +
" WHERE\r\n" +
" contains(dqlist.dq_english_name,'!?1',1) > 0\r\n" +
" )\r\n" +
" ORDER BY\r\n" +
" rank DESC\r\n" +
" ) a\r\n" +
"", nativeQuery=true)
public List<DqListHashFullEntity> findByEngNameTwo(@Param("englishName") String englishName);
我知道我在这里缺少什么。有人可以帮我吗?
编辑1:我在整个本地查询中添加了JPA方法,englishName参数绑定在两个地方。
日志中生成的SQL:
SELECT
a.EXTERNALID_ENC,
a.EXTERNALID,
a.TELNUMBER,
a.TELAREACODE,
a.DQ_ENGLISH_NAME,
a.DQ_ARABIC_NAME,
a.NAMEFIELD_1,
a.USAGETYPE,
a.STATE,
a.REGION,
a.LOCALITY,
a.ADDITIONALLOCALITYINFO,
a.GEN_TEXT_7,
a.GEN_SHORTTEXT_1,
a.GEN_SHORTTEXT_4,
a.GEN_SHORTTEXT_9,
a.GEN_SHORTTEXT_10,
a.CBCM_ENGLISH_NAME,
a.CBCM_ARABIC_NAME,
a.CBCM_EMIRATE_NAME,
a.CBCM_PARTY_ID,
a.CBCM_ACCOUNT_ID,
a.RECORD_ID,
a.DISPLAY_FLAG,
a.DISPLAY_FLAG_GROUP,
a.LONGITUDE,
a.LATITUDE,
a.NORMALIZED_ENGLISH_NAME,
a.CBCM_PARTY_ENGLISH_NAME,
a.CBCM_PARTY_ARABIC_NAME,
a.MANUAL_UPDATE_FLAG,
a.RULE_UPDATE_FLAG,
a.BUSINESS_UPDATE_FLAG,
a.EXCEL_UPDATE_FLAG
FROM
(
SELECT
*
FROM
(
SELECT
dqlist.*,
score(1) AS rank
FROM
dq_list_hash_full dqlist
WHERE
contains(dqlist.dq_english_name,'definescore(fuzzy(?1, 1, 6, weight),relevance)',1) > 0
UNION
SELECT
dqlist.*,
score(1) AS rank
FROM
dq_list_hash_full dqlist
WHERE
contains(dqlist.dq_english_name, '!Bhularam' ,1) > 0
)
ORDER BY
rank DESC
) a
答案 0 :(得分:0)
它应该通过用?替换'?1'来工作。 因此,您要做的就是删除1和'。您可以通过放置多个?来使用多个参数。无需编号或逃脱
答案 1 :(得分:0)
查询应该是这样
SELECT dqlist,score(1) AS rank FROM dq_list_hash_full dqlist WHERE contains(dqlist.dq_english_name,'definescore(fuzzy('?1', 1, 6, weight),relevance)',1) > 0
这里不需要。* 然后在执行查询之前,您需要将参数设置为
query.setParameter(1, "ABC").getResultList();
答案 2 :(得分:0)
尝试使用:1
从dq_list_hash_full dqlist中选择dqlist,score(1)AS等级 contains(dqlist.dq_english_name,'definescore(fuzzy(:1、1、6, 重量),相关性)',1)> 0
这应该有效
答案 3 :(得分:0)
尝试:1而不是?1。它将起作用。
答案 4 :(得分:0)
经过奋斗,我终于能够提出解决方案。我使用了“ ||”运算符,因为它用于Oracle中的字符串连接。所以我的解决方案是:
SELECT dqlist,score(1) AS rank FROM dq_list_hash_full dqlist WHERE contains(dqlist.dq_english_name,'definescore(fuzzy('||?1||', 1, 6, weight),relevance)',1) > 0