0

I am trying to do following to get output like 'MASTHANVALI - Technical Writer'

Query query = em.createQuery("select concat(upper(ename) , \" - \", deg )from employee");

But having following error.

Exception in thread "main" java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: Exception Description: Syntax error parsing [select concat(upper(ename) , " - ", deg )from employee]. 
[20, 25] The encapsulated expression is not a valid expression. 
[37, 40] The expression 'deg' is not valid expression. 
[54, 54] An identification variable must be provided for a range variable declaration. 
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1605) 
at com.tutorialspoint.eclipselink.service.ScalarandAggregateFunctions.main(ScalarandAggregateFunctions.java:14) Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.JPQLException

Any idea how to do this?

Neil Stockton
  • 11,383
  • 3
  • 34
  • 29
  • The error message tells you 3 things that are wrong. "ename" is not recognized. "deg" is not recognized. you need an alias after "employee". – Neil Stockton Aug 24 '16 at 13:02

1 Answers1

0

try replacing the double quotes with single qoutes and add a space after the closing bracket

 Query query = 
   em.createQuery("select concat(upper(ename) , ' - ', deg ) from employee");
Guenther
  • 2,035
  • 2
  • 15
  • 20