Andres Betancur Cañola Andres Betancur Cañola - 2 months ago 14
SQL Question

"missing right parenthesis" error in oracle db

I want to query the last x minutes of data from a table called V_DISPOSITIVO

I have the following query (for example, x= 10 minutes):

WHERE FECHA > (select FECHA - interval '10' minute
where (rownum = 1)
order by FECHA desc)

It fails, but the output doesn't give me the exact cause it fails. It just says

Error code 907, SQL state 42000: ORA-00907: missing right parenthesis

What am I doing wrong?


I need the date of the last row saved (it could be 2 years ago), and then substract x minutes from that.

There is no such thing as the "last" row in a relational database. If you mean the "latest" value in a date or timestamp column, simply use max() and substract the 10 minutes:

SELECT fecha
FROM v_dispositivo
WHERE fecha > (SELECT max(FECHA)  - interval '10' minute 
               FROM v_dispositivo);