1

I have a sql query which I fire on sql plus and I get the result. The same query when I fire from java code - jdbc I get an exception -

java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended.

The query is

select prod_id, prod_area, prod_name, step_name,
       to_char(entry_time, 'DD/MM/YYYY HH24:MI:SS') as entry_time,
       round(extract(day from current_timestamp - entry_time)*1440 +
             extract(hour from current_timestamp - entry_time)*60 +
             extract(minute from current_timestamp - entry_time)) as pending_minutes
from prodreport
where exit_time is null;

java code

String query = "select prod_id,prod_area,prod_name,step_name,to_char(entry_time, 'DD/MM/YYYY HH24:MI:SS') as entry_time, round(extract(day from current_timestamp - entry_time)*1440 + extract(hour from current_timestamp - entry_time)*60 + extract(minute from current_timestamp - entry_time)) as pending_minutes from prodreport where exit_time is null;"
3
  • 7
    What happens if you remove the trailing ; from the query string? Commented May 22, 2019 at 7:51
  • 1
    please provide your java code. PreparedStatement indeed splits the SQL and removes semicolons Commented May 22, 2019 at 8:18
  • @jarlh Thank you it worked Commented May 23, 2019 at 15:15

1 Answer 1

-1

Possibly its because of semicolon(;) which you are sending with query. Please go through the usage of it, It will might help.

The Semicolon

The semicolon character is a statement terminator. It is a part of the ANSI SQL-92 standard, but was never used within Transact-SQL. Indeed, it was possible to code T-SQL for years without ever encountering a semicolon.

Usage

There are two situations in which you must use the semicolon. The first situation is where you use a Common Table Expression (CTE), and the CTE is not the first statement in the batch. The second is where you issue a Service Broker statement and the Service Broker statement is not the first statement in the batch.

Sign up to request clarification or add additional context in comments.

1 Comment

Why do you quote T-SQL rules when the question is about Oracle?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.