Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 带参数的Oracle Java Concat-Like_Sql_Oracle_Sql Like_Concat - Fatal编程技术网

Sql 带参数的Oracle Java Concat-Like

Sql 带参数的Oracle Java Concat-Like,sql,oracle,sql-like,concat,Sql,Oracle,Sql Like,Concat,我喜欢在Oracle SQL Developer中执行此查询,以便在Java中测试并稍后实现相同的查询 SELECT enti.* FROM Entity enti WHERE enti.apellidouno LIKE CONCAT('%',:apellido1,'%') AND enti.nombreuno LIKE CONCAT('%',:nombre1,'%') AND ( :apellido2 IS NULL OR enti.apellidodo

我喜欢在Oracle SQL Developer中执行此查询,以便在
Java
中测试并稍后实现相同的查询

SELECT
    enti.*
FROM
    Entity enti
WHERE
    enti.apellidouno LIKE CONCAT('%',:apellido1,'%')
    AND enti.nombreuno LIKE CONCAT('%',:nombre1,'%')
    AND ( :apellido2 IS NULL OR enti.apellidodos LIKE CONCAT('%',:apellido2,'%') )
    AND ( :nombre2 IS NULL OR enti.nombredos LIKE CONCAT('%',:nombre2,'%') );
我有这个消息

ORA-00909:número de argumentos no válido 90900000-“参数数无效” *原因:
*行动: 莱尼亚错误:103,A列:30

该位置仅为行中
CONCAT
子句的字母
C

enti.apellidouno-LIKE
CONCAT
(“%”,:apellido1,“%”)

现在,在我的界面中

public interface EntityRepository extends CrudRepository<Entity, Long>, JpaRepository<Entity, Long> {


    public static final String ENTITY_POR_APELLIDOS_Y_NOMBRES
            = " SELECT enti "
            + " FROM Entity enti "
            + " WHERE "
            + "  enti.apellidouno LIKE CONCAT('%',:apellido1,'%') "
            + "  AND enti.nombreuno LIKE CONCAT('%',:nombre1,'%') "
            + "  AND (:apellido2 is null OR enti.apellidodos LIKE CONCAT('%',:apellido2,'%') "
            + "  AND (:nombre2 is null OR enti.nombredos LIKE CONCAT('%',:nombre2,'%') ";

    @Query(ENTITY_POR_APELLIDOS_Y_NOMBRES)
    List<Entity> findEntityByApellidosAndNombres(
            @Param("apellido1") String apellido1, @Param("apellido2") String apellido2, 
            @Param("nombre1") String nombre1, @Param("nombre2") String nombre2);

}

您需要嵌套
CONCAT
,因为在Oracle中它只处理2个参数:

SELECT enti.*
FROM Entity enti
WHERE enti.apellidouno LIKE CONCAT(CONCAT('%',:apellido1),'%')
 -- ...
您可以选择使用
| |

SELECT enti.*
FROM Entity enti
WHERE enti.apellidouno LIKE '%' || :apellido1 || '%'
SELECT enti.*
FROM Entity enti
WHERE enti.apellidouno LIKE '%' || :apellido1 || '%'