Lab-verifiedReproduced and fixed on Oracle AI Database 26ai Free 23.26.3.0.0 · 2026-11-30 · container image gvenzl/oracle-free:23-slim
ORA-01795 is usually known as the "1000 items in an IN list" limit. On Oracle 26ai Free, where this page was run, the message said maximum number of expressions in a list is 65535, and an IN list with 1001 values ran without error. The error appeared only with 70000 values.
The limit number depends on the version, but the fix is the same: don't paste the IDs into the SQL text. Put them in a table and use IN (SELECT …).
01Too many values in one IN (…) list
A PL/SQL block built SELECT COUNT(*) FROM orders WHERE id IN (1,2,…,70000) as text and ran it with EXECUTE IMMEDIATE. It failed with ORA-01795: maximum number of expressions in a list is 65535, and ORA-06512: at line 9 points to the EXECUTE IMMEDIATE line.
The same block with 1001 values worked and printed 1001 items: 1001, so on 26ai the old 1000 limit was not hit.
The fix: a global temporary table tmp_ids (ON COMMIT PRESERVE ROWS) filled with the 70000 IDs, then WHERE id IN (SELECT id FROM tmp_ids). That returned 70000 with no error.
Setup
CREATE TABLE orders (id NUMBER PRIMARY KEY, status VARCHAR2(10));
INSERT INTO orders SELECT LEVEL, 'NEW' FROM dual CONNECT BY LEVEL <= 70000;
COMMIT;Table created.
70000 rows created.
Commit complete.SET SERVEROUTPUT ON
DECLARE
v_sql CLOB := 'SELECT COUNT(*) FROM orders WHERE id IN (1';
v_cnt NUMBER;
BEGIN
FOR i IN 2..70000 LOOP
v_sql := v_sql || TO_CLOB(',' || i);
END LOOP;
v_sql := v_sql || ')';
EXECUTE IMMEDIATE v_sql INTO v_cnt;
DBMS_OUTPUT.PUT_LINE('70000 items: ' || v_cnt);
END;
/DECLARE
*
ERROR at line 1:
ORA-01795: maximum number of expressions in a list is 65535
ORA-06512: at line 9
Help: https://docs.oracle.com/error-help/db/ora-01795/SET SERVEROUTPUT ON
DECLARE
v_sql CLOB := 'SELECT COUNT(*) FROM orders WHERE id IN (1';
v_cnt NUMBER;
BEGIN
FOR i IN 2..1001 LOOP
v_sql := v_sql || TO_CLOB(',' || i);
END LOOP;
v_sql := v_sql || ')';
EXECUTE IMMEDIATE v_sql INTO v_cnt;
DBMS_OUTPUT.PUT_LINE('1001 items: ' || v_cnt);
END;
/1001 items: 1001
PL/SQL procedure successfully completed.CREATE GLOBAL TEMPORARY TABLE tmp_ids (id NUMBER PRIMARY KEY) ON COMMIT PRESERVE ROWS;Table created.A subquery in IN was not limited here: the 70000-row subquery worked.
INSERT INTO tmp_ids SELECT LEVEL FROM dual CONNECT BY LEVEL <= 70000;
SELECT COUNT(*) FROM orders WHERE id IN (SELECT id FROM tmp_ids);70000 rows created.
COUNT(*)
----------
70000
1 row selected.FAQ
What is the maximum number of items in an Oracle IN list?
It is commonly known as 1000. On Oracle 26ai Free the message showed 65535: 1001 values passed and 70000 values failed. Check the number in your own error message.
How do I query more than 1000 IDs with IN?
Load the IDs into a table (a global temporary table works) and use WHERE id IN (SELECT id FROM tmp_ids). On this page that returned all 70000 rows.
Why does ORA-01795 come with ORA-06512?
The SQL was run with EXECUTE IMMEDIATE inside a PL/SQL block. ORA-06512 just shows the line of that block where the error came up (line 9 here).
Does the limit apply to a subquery in IN?
No. IN (SELECT id FROM tmp_ids) with 70000 rows ran without ORA-01795. The limit is on values written directly in the list.
How we verify
Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.
lab_a and lab_b are ordinary users created for the test; system is the DBA account. Oracle AI Database 26ai Free Release 23.26.3.0.0 - Develop, Learn, and Run for Free 23.26.3.0.0