3

I got a problem. When running this MyBatis select:

<select id="findIdByCode" resultType="long">
        select USER_ID from PWD_REST_CODE
        where RESTORATION_CODE = #{code}
        and current_date between date_from and DATE_FROM + interval #{interval} second
</select>

I got EJB Exception:

EJB exception occurred during invocation from home or business: 
com.project.auth.ejb.data.UserManagerBean_rdl8zk_Intf generated exception: 
org.apache.ibatis.exceptions.PersistenceException: ### Error querying 
database. Cause: java.sql.SQLSyntaxErrorException: ORA-00933: неверное 
завершение SQL-предложения ### The error may exist in 
com/project/auth/dao/UserDAO.xml ### The error may involve 
defaultParameterMap ### The error occurred while setting parameters ### SQL: 
select USER_ID from PWD_REST_CODE where RESTORATION_CODE = ? and current_date 
between date_from and DATE_FROM + interval ? second ### Cause: 
java.sql.SQLSyntaxErrorException: ORA-00933: неверное завершение SQL-предложения 

(неверное завершение SQL-предложения stands for SQL command not properly ended)

But when I run exactly the same query in database manager:

    select USER_ID from PWD_REST_CODE
    where RESTORATION_CODE = '217799dfHj'
    and current_date between date_from and DATE_FROM + interval '86400' second

I got the deserved id (user_id, 5). Why it happens?

1
  • interval '86400' second is a bit different from interval 86400 second what you use in MyBasic. I suppose that because the type is NUMBER MyBatis doesn't add the quotes around it. Commented Oct 25, 2018 at 15:05

1 Answer 1

1

As Marmite Bomber correctly wrote in comments you can't use number in INTERVAL literal. Use numToDSInterval function to convert number to interval:

<select id="findIdByCode" resultType="long">
     select USER_ID from PWD_REST_CODE
     where RESTORATION_CODE = #{code}
         and current_date between date_from
         and DATE_FROM + numToDSInterval( #{interval}, 'second' )
</select>
Sign up to request clarification or add additional context in comments.

Comments

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.