Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8942771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:36:12+00:00 2026-06-15T11:36:12+00:00

I have the following Oracle SQL query. Given a given name and surname, it

  • 0

I have the following Oracle SQL query. Given a given name and surname, it finds all records with One name and the initial of the other, in either order. I have created the score column to place likely matches at the top of the results set.

SELECT
  surname,
  givenname,
  (CASE WHEN surname = 'Smith' THEN 2 ELSE 0)
    + (CASE WHEN givenname = 'John' THEN 1 ELSE 0)
    AS score
FROM person
WHERE (surname = 'Smith' AND givenname LIKE 'J%')
  OR  (surname LIKE 'S%' AND givenname = 'John')
  OR  (surname = 'John' AND givenname LIKE 'S%')
  OR  (surname LIKE 'J%' AND givenname = 'Smith')
ORDER BY
  score DESC,
  surname ASC,
  givenname ASC;

The problem is the score is giving an error at the location of the +. The IDE reports:

Syntax error, expected:
/
*
|

And execution reports:

SQL Error: ORA-00905: missing keyword

What am I doing wrong? Is there a better way to calculate the score?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:36:13+00:00Added an answer on June 15, 2026 at 11:36 am

    You are missing the END on your CASE statements:

    SELECT
      surname,
      givenname,
      (CASE WHEN surname = 'Smith' THEN 2 ELSE 0 END)  -- < add END
        + (CASE WHEN givenname = 'John' THEN 1 ELSE 0 END)  -- < add END
        AS score
    FROM person
    WHERE (surname = 'Smith' AND givenname LIKE 'J%')
      OR  (surname LIKE 'S%' AND givenname = 'John')
      OR  (surname = 'John' AND givenname LIKE 'S%')
      OR  (surname LIKE 'J%' AND givenname = 'Smith')
    ORDER BY
      score DESC,
      surname ASC,
      givenname ASC;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following query which runs perfectly well on both Oracle and SQL
I have a following oracle sql query in which START_DATE is a number column
How do I query the database name in Oracle SQL Developer? I have tried
I have the following query in ORACLE SQL: Select Trunc(Cs.Create_Dtime), Count(Case When Cs.Cs_Listing_Id Like
I have the following SQL query in oracle: SELECT * FROM ( SELECT s.singleid,s.titel,a.naam,s.taal,SUM(b.aantal)
I have the following PL/SQL stored procedure on an Oracle database: PROCEDURE MyProcedure (
I have a following oracle query: SELECT a.USER_ID, c.first_name, c.last_name, TO_CHAR( b.logon_date, 'MM/DD/YYYY HH:MI:SS
I have the following query that runs in my Oracle database and I want
I'm using Oracle 10.2 and have the following query: select h.company, count(*) from history
I have a java.sql.Clob object which I populate from an Oracle query and then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.