Can not use SUM in a simple query because of a syntax error?

Hi
Thank you for reading my post.
I am trying to execute the following query:
q = em.createQuery("SELECT SUM((NE.pipeLength - 0.6)+((NE.networkDepth-NE.initialDepth)*0.41)+ NE.standLenght)  FROM NExpansion NE  where (( NE.contract.contractor=:contractor) AND (NE.pDiameter=:diameter))");
              q.setParameter("contractor", contractor);
q.setParameter("diameter", diameter);
     l =  (Long) q.getSingleResult();And I get the following error:
Caused by: Exception [TOPLINK-8025] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.EJBQLException
Exception Description: Syntax error parsing the query [SELECT SUM((NE.pipeLength - 0.6)+((NE.networkDepth-NE.initialDepth)*0.41)+ NE.standLenght)  FROM NExpansion NE  where (( NE.contract.contractor=:contractor) AND (NE.pDiameter=:diameter))], line 1, column 12: unexpected token [(].
Internal Exception: line 1:12: unexpected token: (
        at oracle.toplink.essentials.exceptions.EJBQLException.unexpectedToken(EJBQLException.java:389)
        at oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParser.handleANTLRException(EJBQLParser.java:350)
        at oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParser.addError(EJBQLParser.java:278)
        at oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParser.reportError(EJBQLParser.java:378)
        at oracle.toplink.essentials.internal.parsing.ejbql.antlr273.EJBQLParser.aggregateExpression(EJBQLParser.java:1416)
        at oracle.toplink.essentials.internal.parsing.ejbql.antlr273.EJBQLParser.selectExpression(EJBQLParser.java:1158)
        at oracle.toplink.essentials.internal.parsing.ejbql.antlr273.EJBQLParser.selectClause(EJBQLParser.java:403)
        at oracle.toplink.essentials.internal.parsing.ejbql.antlr273.EJBQLParser.selectStatement(EJBQLParser.java:178)
        at oracle.toplink.essentials.internal.parsing.ejbql.antlr273.EJBQLParser.document(EJBQLParser.java:135)
        at oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParser.parse(EJBQLParser.java:166)
        at oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParser.buildParseTree(EJBQLParser.java:127)
        at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:215)
        at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:189)
        at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:153)
        at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.<init>(EJBQueryImpl.java:114)
        at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.<init>(EJBQueryImpl.java:99)
        at oracle.toplink.essentials.internal.ejb.cmp3.EJBQueryImpl.<init>(EJBQueryImpl.java:86)
        at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImpl.createQuery(EntityManagerImpl.java:204)
        ... 30 more
Caused by: line 1:12: unexpected token: (
        at oracle.toplink.essentials.internal.parsing.ejbql.antlr273.EJBQLParser.aggregateExpression(EJBQLParser.java:1365)
        ... 43 morePlease let me know what am I doing wrong?
Thanks.

Hello,
From the grammar in the JPA spec, SUM only takes a state_field_path_expression which is defined as
state_field_path_expression := {identification_variable | single_valued_association_path_expression}.state_field
Please feel free to file an enhancement to have this expanded upon.
Best Regards,
Chris

Similar Messages

  • How can i use SUM aggregate in select query?

    HI,
    GURUS,
    How can i use SUM function in Select Query and i want to store that value into itab.
    for ex:
    TABLES: vbap.
    types: begin of ty_vbap,
           incluse type vbap,
           sum type string,
          end of ty_vbap.
    data: i_vbap type TABLE OF ty_vbap,
          w_vbap type ty_vbap.
    SELECT sum(posnr) FROM vbap into table i_vbap up to 5 rows.
                            (or)
    SELECT sum(posnr) FROM vbap into table i_vbap group by vbeln.
      loop at i_vbap into w_vbap
    " which variable have to use to display summed value.
      endloop.
    if above code is not understandable pleas give ome sample code on  above query.
    Thank u,
    shabeer ahmed.

    Hi,
    Check this sample code.
    TABLES SBOOK.
    DATA:  COUNT TYPE I, SUM TYPE P DECIMALS 2, AVG TYPE F.
    DATA:  CONNID LIKE SBOOK-CONNID.
    SELECT CONNID COUNT( * ) SUM( LUGGWEIGHT ) AVG( LUGGWEIGHT )
           INTO (CONNID, COUNT, SUM, AVG)
           FROM SBOOK
           WHERE
             CARRID   = 'LH '      AND
             FLDATE   = '19950228'
           GROUP BY CONNID.
      WRITE: / CONNID, COUNT, SUM, AVG.
    ENDSELECT.
    Regards,
    Sravanthi

  • HT203175 I have no problem signing on to iTunes my issue is once on the site I can not use the "search". It says there is a runtime error R6025 pure virtual function call. Has anyone had this problem and how do I fix it. Thanks

    I do not have a problem getting in the iTunes stores. My issue is once on the site I can not use the "search". It says there is a pure virtual function call R6025. How can I solve this problem? Do I have to create a new account? Do I have to uninstall and re-install? Thanks

    Thanks so much for your feedback. I really appreciate any input here.
    If someone from Adobe could GUARANTEE that this problem would go away if I
    purchased CS4, I would pony up the cash and do it. However, I'm skeptical
    about that because I just saw someone else post a message on the forum today
    who is running CS4 and getting the exact same runtime error as me.
    I'll try un-installing and re-installing as Admin, and if that doesn't work,
    maybe I can find a used copy of CS3.
    In the meantime, I'm also wondering if a Photoshop file can carry any sort
    of corrupt metadata inside it once it has errored out? Reason I ask is, I
    had to port all of my old PSD files to the new computer, and I only seem to
    be getting this error when I attempt to work on one of the files that
    previously got the runtime error when they were sitting on my XP machine.
    When I create new files from scratch on this new computer, they seem to be
    working just fine (at least, for now).
    If so, I would probably be smart to never open those troublesome
    "errored-out" files again.

  • Query can not use index

    1,i found a sql :select userid,repute from user_attribute where
    repute>3000 order by repute desc
    cost heavily;
    SELECT STATEMENT Cost = 637
    SORT ORDER BY
    TABLE ACCESS FULL USER_ATTRIBUTE
    2,i use: select index_name from user_indexes where table_name
    = 'USER_ATTRIBUTE'
    INDEX_NAME
    IDX_USER_ATTRIBUTE_FACE
    IDX_USER_ATTRIBUTE_POWER
    IDX_USER_ATTRIBUTE_REPUTE
    IDX_USER_ATTRIBUTE_USERID
    so column repute has indexed
    3, i use CBO with analysize shema compute
    optimizer_index_caching integer 99
    optimizer_index_cost_adj integer 5
    4,i use: select /*index(IDX_USER_ATTRIBUTE_REPUTE)*/
    userid,repute from user_attribute where repute>3000 order by
    repute desc
    i got same explain plan as old
    5,why it can not use index to query,thanks.

    I think your optimizer hint syntax is wrong. you need a "+"
    sign to indicate that the comment block is an optimizer hint,
    and the table name is not optional in the index hints
    select /*+ index(user_attribute
    IDX_USER_ATTRIBUTE_REPUTE)*/
    userid,repute from user_attribute where repute>3000 order
    by
    repute desc
    also, try ...
    select /*+ index_desc(user_attribute
    IDX_USER_ATTRIBUTE_REPUTE)*/
    userid,repute from user_attribute where repute>3000
    This should order the result for you.

  • I am using iPhoto '09 Version 8.1.2 but can not use iCloud with it. I've looked for updates in iPhoto and iLife'11 but no luck. Suggestions very welcome.

    I am using iPhoto '09 Version 8.1.2 but can not use iCloud with it. I've looked for updates in iPhoto and iLife'11 but no luck. Suggestions very welcome.

    No you won't necessarily lose your photos when upgrading but it's very very unwise not to back up first. Backing up is like using a seat belt in a car. You can drive without one for years and have no issues, but if you do have a problem the outcome will be a lot worse. So, too, with back ups. And upgrading is one of those times when the risks of a problem are higher.
    Most Simple Back Up:
    Drag the iPhoto Library from your Pictures Folder to another Disk. This will make a copy on that disk.
    Slightly more complex: Use an app that will do incremental back ups. This is a very good way to work. The first time you run the back up the app will make a complete copy of the Library. Thereafter it will update the back up with the changes you have made. That makes subsequent back ups much faster. Many of these apps also have scheduling capabilities: So set it up and it will do the back up automatically.
    Example of such apps: Chronosync - but there are many others. Search on MacUpdate or the App Store

  • Can I use table function inside Dynamic query ?

    Dear Gurus,
    I have following code
    DECLARE
    TYPE CRITERIA_LIST_TABLE AS TABLE OF VARCHAR2(20);
    OtherNoList CRITERIA_LIST_TABLE; /* CRITERIA_LIST_TABLE is index by table*/
    QUERY_STRING VARCHAR2(4000);
    BEGIN
    OtherNoList := CRITERIA_LIST_TABLE();
    SELECT DISTINCT REGEXP_SUBSTR('1,5,6,4', '[^\,]+',1, LEVEL ) BULK COLLECT INTO OtherNoList
    FROM DUAL
    CONNECT BY LEVEL <= REGEXP_COUNT('1,5,6,4', '\,') + 1 ;
    QUERY_STRING := 'INSERT INTO TAB1 (C1,C2) '||
    'SELECT C1,'||
    'C2 '||
    'FROM TAB1 ,'||
    'TABLE( '||
              'CAST (OtherNoList AS CRITERIA_LIST_TABLE) '||
                   ') OTHRNOS '||
    'WHERE TAB1.C1 = OTHRNOS.COLUMN_VALUE ';
    DBMS_OUTPUT.PUT_LINE('Query String is '||QUERY_STRING);
    EXECUTE IMMEDIATE QUERY_STRING;
    END;
    Can I use Table function inside dynamic query.
    Thanking in advance
    Sanjeev

    Try:
    DECLARE
    TYPE CRITERIA_LIST_TABLE AS TABLE OF VARCHAR2(20);
    OtherNoList CRITERIA_LIST_TABLE; /* CRITERIA_LIST_TABLE is index by table*/
    QUERY_STRING VARCHAR2(4000);
    BEGIN
    OtherNoList := CRITERIA_LIST_TABLE();
    SELECT DISTINCT REGEXP_SUBSTR('1,5,6,4', '[^\,]+',1, LEVEL ) BULK COLLECT INTO OtherNoList
    FROM DUAL
    CONNECT BY LEVEL <= REGEXP_COUNT('1,5,6,4', '\,') + 1 ;
    QUERY_STRING := 'INSERT INTO TAB1 (C1,C2) '||
    'SELECT C1,'||
    'C2 '||
    'FROM TAB1 ,'||
    'TABLE( '||
    'CAST (:OtherNoList AS CRITERIA_LIST_TABLE) '||
    ') OTHRNOS '||
    'WHERE TAB1.C1 = OTHRNOS.COLUMN_VALUE ';
    DBMS_OUTPUT.PUT_LINE('Query String is '||QUERY_STRING);
    EXECUTE IMMEDIATE QUERY_STRING using OtherNoList;
    END;p.s. not tested
    Amiel Davis

  • HT4528 I want to unlock it from o2 network size to be used on any network in Romania. right now I can not use this phone on any network in Romania and I would like if possible with your help me to unlock it. model phone is iPhone 4.  I understand that it

    help me !
    I want to unlock it from o2 network size to be used on any network in Romania. right now I can not use this phone on any network in Romania and I would like if possible with your help me to unlock it. model phone is iPhone 4.
    I understand that it takes IMEI?
    thank you, with great esteem and respect Stan Ionut-Alin from Bucharest Romania
    I can someone help me please to use this phone in romania
    So the phone is encrypted or locked in england on o2 network

    There is NO solution other than already described
    O2 locked the iPhone as they subsidised the original price
    when sold new
    Therefore ONLY O2 can unlock the iPhone
    it is NOTHING to do with Apple they have no authority
    to unlock an iPhone
    Apple do NOT lock iPhones ,carriers do
    simple no debate
    If you purchased through eBay raise a claim

  • HT4628 I can not use the internal wireless card with my Mac pro 2012, I don't know if it is broken

    I can not use the internal wireless card with my Mac pro 2012, I don't know if it is broken. The problem is happen recently, I have to use an independent wireless card now. Thanks!

    When you enable Internet Sharing in OS X, you are creating a separate sub-net.
    There is no option to allow this to be a simple pass-through from Ethernet to AirPort (or the other way).
    The problem is easily solved by getting an inexpensive wireless router. You can replace your current router OR disable the DHCP server on the wireless router and allow the wireless clients to get an IP address from the current router.

  • Can not use all the tools in my drawing markups any ideas on getting them to work?

    Can not use all the tools in my drawing markups any ideas on getting them to work?

    Hi tonys60181,
    Could you please let me know what version of Adobe Acrobat are you using.
    What all drawing tools are you unable to access?
    Is this issue specific to one PDF file or all?
    What exactly happens when you try to use any drawing markup?
    Please let me know.
    Regards,
    Anubha

  • Can not use TOUCH function on Nokia 6600 slide

    Can not use TOUCH function on Nokia 6600 slide-
    turned on sensor in phone settings, but when i touch the PHONE it does not work.
    Please, tell me how use this function or maybe my phone is out of order

    As long as your Sensor Settings are On within Menu, Settings, Phone, Sensor Settings then you just need to do the following -
    Tapping
    The tap function allows you to quickly
    mute and reject calls and alarm tones, and
    to display a clock just by double-tapping
    the back or front of the phone when the
    slide is closed.
    Select Menu > Settings > Phone >
    Sensor settings to activate the tap
    function and vibration feedback.
    Mute calls or alarms
    Double-tap the phone.
    Reject a call or snooze an alarm after
    muting it
    Double-tap the phone again.
    Display the clock
    Double-tap the phone.
    (If you have missed calls or received new
    messages, you must view them before you
    can see the clock.)
    Simply, if you double tap the screen when the slide is closed and you can see the clock appear then it is working.
    I hope this makes it clearer for you.
    Full Manual here - http://nds1.nokia.com/phones/files/guides/Nokia_6600_slide_UG_en.pdf

  • I can not install the newest version of iTunes because of a file that can not be found. This is what I am seeing:(The feature you are trying to use is on a network resource that is unavailable. C:\......\Application Data\Apple\Apple Software Update\

    I can not install the newest version of iTunes because of a file that can not be found. This is what I am seeing:(The feature you are trying to use is on a network resource that is unavailable. C:\Documents and Settings\Aubrie\Local Settings\Application Data\Apple\Apple Software Update\)

    (1) Download the Windows Installer CleanUp utility installer file (msicuu2.exe) from the following Major Geeks page (use one of the links under the "DOWNLOAD LOCATIONS" thingy on the Major Geeks page).
    http://majorgeeks.com/download.php?det=4459
    Here's a screenshot showing the particular links on the page that you should be clicking:
    After clicking one of the circled links, you should be taken to another page, and after a few seconds you should see a download dialog appear for the msicuu2.exe file. Here's a screenshot of what it looks like for me in Firefox:
    Choose to Save the file. If the dialog box does not appear for you, click the link on the page that says "CLICK HERE IF IT DOES NOT". Here's a screenshot of the page with the relevant link circled:
    When the dialog appears, choose to save the file.
    (2) Go to the Downloads area for your Web browser. Doubleclick the msicuu2.exe file and follow the prompts to install the Windows Installer CleanUp utility. (If you're on a Windows Vista or Windows 7 system and you get a Code 800A0046 error message when doubleclicking the msicuu2.exe file, try instead right-clicking on the msicuu2.exe file and selecting "Run as administrator".)
    (3) In your Start menu click All Programs and then click Windows Install Clean Up. The Windows Installer CleanUp utility window appears, listing software that is currently installed on your computer.
    (4) In the list of programs that appears in CleanUp, select any iTunes entries and click "Remove", as per the following screenshot:
    (5) Quit out of CleanUp, restart the PC and try another iTunes install. Does it go through properly this time?

  • I can not use my mouse or keyboard when I am trying to install windows via boot camp

    Please can you help!
    I can not use my mouse or keyboard when I am trying to install windows via boot camp

    Starting a couple of days ago my mouse and keyboard stopped working suddenly.  
    How are they connected?   In my case they are wireless and their receiver is plugged into my USB hub.  After an update I found the OS inexplicably not recognizing my USB hub and hence any devices which were plugged into it.  My fix was to
    plug the receiver into a different USB port (so I could use the mouse and keyboard; otherwise I would have had to use the OSK via Touch or pen.)  Once I had normal access into my machine again I used Device Manager to remove all USB controller and
    hubs (including hidden ones) and I then shut down, disconnected all USB devices and powered back up, this time using only Touch to get going.  Once the OS had settled down I started plugging stuff back in the way that I wanted it to be recognized. 
    If I didn't have Touch I would have had to have left the wireless receiver plugged in both places which I assume would be OK.  I have no idea why updates have such a catastrophic effect for USB devices.
    Robert Aldwinckle

  • I am having troubles, when I open LR I get a message that there is an error and it will try to fix the error next time it opens, but I get the error next time it opens, and this is going on and on where I can not use LR, any suggestions?

    I am having troubles, when I open LR I get a message that there is an error and it will try to fix the error next time it opens. LR closes on it's own, I reopen it and get that same message next time it opens, and this is going on and on where I can not use LR, any suggestions? If I click on a different set of photos in the libary before I get that message I might or might not get the message next time it oipens, but I still can not get to those photos, and it is not just one or two but most of my photos. HELP!!!!
    Thanks
    Carol

    The first thing I would suggest is for you to go to the folder containing your catalog, using your system browser. There will be a folder that has the extension .lrdata. Delete that folder, and then try to start Lightroom. If that doesn't work, replace your catalog with your most recent backup.

  • In my numeric key pad I can not use the (.) dot because it has a (,) and it is not working in calculations.  What I can do?

    In my numeric key pad I can not use the decimal dot (.) because it has a (,) and this not work with decimal calculations.  What I can do?  Help ………

    IT NOT WORK IN MEXICO.  THANKS A LOT.  BEST REGARDS.  MANUEL LOPEZ
    El 6/2/2015, a las 16:50, Apple Support Communities Updates <[email protected]> escribió:
    You received a reply
    SGIII has replied to your question. You can view the full discussion in Apple Support Communities.
    In my numeric key pad I can not use the (.) dot because it has a (,) and it is not working in calculations.  What I can do?
    Correct Answer Helpful Answer
    Use the buttons above to tell SGIII and the rest of the community if this reply solved your question or helped you get closer to finding a solution.
    To reply to SGIII, go to the discussion in Apple Support Communities.
    You are receiving this email from Apple Support Communities. You can change your email preferences in your Apple Support Communities Profile.
    TM and copyright © 2014 Apple Inc. 1 Infinite Loop, MS 96-DM. Cupertino, CA 95014.
    All Rights Reserved | Privacy Policy | Terms of Use | Apple Support

  • I'm exhausted of trying to find a solution to a problem created by Apple. I have moved to iCloud, following your instructions and now I can not use my mobileme e-mail address. How can I contact directly with Apple, not just an automatic reply phone number

    I'm exhausted of trying to find a solution to a problem created by Apple. I have moved to icloud following all your instructions and now I can not use my mobile me e-mail address. I can not activate icloud because when I put my e-mail address it answers that somebody is already using my address. I have my old e-mails, but I can not receive any e-mail or send them.
    I have contacted Apple Technical Support in Spain and I was sent an e-mail saying that I have to call a phone number and when I call it is always an answering machine who answers that says that I have to pay 50€ for a consultation or wait for 10 minutes. When I have made the consultation it was never mentioned that I have to pay 50€ for a phone consultation. If I don't want to wait I have to pay for the Apple Tecnical Support which cost 250 €, this was not mentioned in the technical support page.
    Can somebody let me know how can I contact Apple in another way in order to talk with a human being or chat directly? I was very happy just using my mobileme e-mails, I didn't need any clouds and I was force by Apple to registered if I want to continue using my mobileme e-mail address.

    Sandra,
    See this Apple support document for information on reporting an issue with your iTunes purchase.
    http://support.apple.com/kb/HT1933
    B-rock

Maybe you are looking for