Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to combine TRIM and LOWER functions in JPQL?

Tags:

jpql

I need to perform the following select:

select c.address from Customer c where lower(trim(c.name)) = :name

But I get the following exception:

javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query

Any idea how can I combine trim with lower?

like image 210
Marius Avatar asked Apr 18 '13 09:04

Marius


People also ask

Can we use inner join in JPQL?

[INNER] JOIN JPQL provides an additional type of identification variable, a join variable, which represent a more limited iteration over specified collections of objects. In JPQL, JOIN can only appear in a FROM clause. The INNER keyword is optional (i.e. INNER JOIN is equivalent to JOIN).

Which is faster JPQL or native query?

In some cases it can happen Hibernate/JPA does not generate the most efficient statements, so then native SQL can be faster - but with native SQL your application loses the portability from one database to another, so normally is better to tune the Hibernate/JPA Query mapping and the HQL statement to generate more ...

Which is JPQL aggregate function?

JPQL supports the five aggregate functions of SQL: COUNT - returns a long value representing the number of elements. SUM - returns the sum of numeric values. AVG - returns the average of numeric values as a double value.

What is the JPQL trim () function?

In this section, you will learn about the JPQL trim () function. This function will trimmed the space character from your given string. In this section, you will learn about the JPQL trim () function. This function will trimmed the space character from your given string. In this section, you will learn about the JPQL trim () function.

What are the built-in string functions in JPQL?

JPQL provides following built-in string functions: concatenates two or more strings into one string. The second and third arguments of the SUBSTRING function denote the starting position and length of the substring to be returned. These arguments are integers.

How to remove all spaces characters from a string in JPQL?

In this section, you will learn about the JPQL trim () function. This function will trimmed the space character from your given string. This query remove all spaces characters from the given string as sname.

How does the TRIM () function work in SQL?

The function operates on the value in the state column for each row in turn. And now we’re back to normal: The TRIM () function can also be used to strip characters other than spaces from the front and end of a string, although this usage is probably less common.


Video Answer


1 Answers

I discovered the solution, you must use both in order for the statment to work:

select c.address from Customer c where lower(trim(both from c.name)) = :name
like image 81
Marius Avatar answered Oct 24 '22 21:10

Marius