-2

What is wrong with below code?

SELECT  first_name, last_name
FROM    employees
UNION ALL
SELECT  first_name, last_name
FROM    dependents
ORDER BY  last_name
LIMIT 6 OFFSET 1;

Even a simple query with LIMIT doesn't seem to be working :

SELECT  first_name, last_name
FROM    dependents
ORDER BY  last_name
LIMIT 6 OFFSET 1;

Getting this error repeatedly: ORA-00933: SQL command not properly ended

Pரதீப்
  • 85,687
  • 16
  • 112
  • 148

2 Answers2

1

I believe oracle does not support LIMIT. Try this

ORDER BY last_name
OFFSET 1 ROWS FETCH NEXT 6 ROWS ONLY;

Note this syntax supports from Oracle 12c

Pரதீப்
  • 85,687
  • 16
  • 112
  • 148
1

What is wrong with the code is that Oracle does not support limit. Period. The most recent versions support the ANSI standard fetch first <n> rows only.

Perhaps you intend:

SELECT e.*
FROM (SELECT e.*, ROW_NUMBER() OVER (ORDER BY last_name) as seqnum
      FROM (SELECT first_name, last_name FROM employees
            UNION ALL
            SELECT first_name, last_name
            FROM dependents
           ) e
      ORDER BY last_name
     ) e
WHERE seqnum BETWEEN 1 and 7;
Gordon Linoff
  • 1,122,135
  • 50
  • 484
  • 624