Oracle 23.26PL/SQLLab-verified · 2026-12-01

ORA-01008: not all variables bound

Dynamic SQL had more bind placeholders than the values passed in USING.

Oracle AI Database 26ai Free 23.26.3.0.0
ORA-01008: value for bind variable placeholder 2 was not provided

What changed in 26ai error messages →

Jump to a cause

  1. 01A condition was added to the SQL but not to USING
  2. 02The same placeholder name appears twice
  3. 03OPEN cursor FOR '...' without USING
  4. 04DBMS_SQL: a BIND_VARIABLE call is missing
  5. 05:new written inside dynamic SQL in a trigger
  6. 06Dynamic INSERT has RETURNING INTO :var, but EXECUTE IMMEDIATE has no RETURNING INTO
  7. 07Dynamic search adds optional conditions, but USING always passes the same values

Lab-verifiedReproduced and fixed on Oracle AI Database 26ai Free 23.26.3.0.0 · 2026-12-01 · container image gvenzl/oracle-free:23-slim

ORA-01008 means a :name placeholder in the SQL did not get a value. In PL/SQL it almost always comes from dynamic SQL (EXECUTE IMMEDIATE or OPEN ... FOR '...') because static SQL binds variables automatically.

The classic message is "not all variables bound". 23ai is more specific: value for bind variable placeholder 2 was not provided tells you which placeholder (counting from 1, left to right) is missing.

01A condition was added to the SQL but not to USING

The SQL has two placeholders, :dept and :min_sal, but USING 10 passes only one. The error said placeholder 2 had no value, which is :min_sal.

Pass one value per placeholder, in order: USING 10, 350. The block printed count = 1.

Setup
Setuprun as lab_a
CREATE TABLE emp (emp_id NUMBER PRIMARY KEY, dept_id NUMBER, sal NUMBER);
INSERT INTO emp VALUES (1, 10, 300);
INSERT INTO emp VALUES (2, 10, 500);
INSERT INTO emp VALUES (3, 20, 400);
COMMIT;
OUTPUT
Table created.


1 row created.


1 row created.


1 row created.


Commit complete.
Reproducerun as lab_a
SET SERVEROUTPUT ON
DECLARE
  v_cnt NUMBER;
  v_sql VARCHAR2(200) := 'SELECT COUNT(*) FROM emp WHERE dept_id = :dept AND sal > :min_sal';
BEGIN
  EXECUTE IMMEDIATE v_sql INTO v_cnt USING 10;
  DBMS_OUTPUT.PUT_LINE('count = ' || v_cnt);
END;
/
✕ ERROR
DECLARE
*
ERROR at line 1:
ORA-01008: value for bind variable placeholder 2 was not provided
ORA-06512: at line 5
Help: https://docs.oracle.com/error-help/db/ora-01008/
Check the causerun as lab_a
COLUMN placeholder FORMAT A20
WITH s AS (SELECT 'SELECT COUNT(*) FROM emp WHERE dept_id = :dept AND sal > :min_sal' AS q FROM dual)
SELECT LEVEL AS pos, REGEXP_SUBSTR(q, ':[a-z_]+', 1, LEVEL) AS placeholder
  FROM s CONNECT BY LEVEL <= REGEXP_COUNT(q, ':[a-z_]+');
OUTPUT
       POS PLACEHOLDER
---------- --------------------
         1 :dept
         2 :min_sal

2 rows selected.

Listing the placeholders in the SQL string gives 1 :dept and 2 :min_sal. USING passed only one value, so position 2 was empty.

When you add AND col = :x to a dynamic SQL string, add the value to every USING that runs it.

Fix: run the corrected statementrun as lab_a
SET SERVEROUTPUT ON
DECLARE
  v_cnt NUMBER;
  v_sql VARCHAR2(200) := 'SELECT COUNT(*) FROM emp WHERE dept_id = :dept AND sal > :min_sal';
BEGIN
  EXECUTE IMMEDIATE v_sql INTO v_cnt USING 10, 350;
  DBMS_OUTPUT.PUT_LINE('count = ' || v_cnt);
END;
/
✓ SUCCESS
count = 1

PL/SQL procedure successfully completed.

02The same placeholder name appears twice

(dept_id = :dept OR :dept IS NULL) looks like one variable, but EXECUTE IMMEDIATE binds SQL placeholders by position, not by name. Two :dept mean two values, and the error pointed to placeholder 2.

Pass the value twice: USING p_dept, p_dept. With p_dept NULL the block returned count = 3, all rows.

Setup
Setuprun as lab_a
CREATE TABLE emp (emp_id NUMBER PRIMARY KEY, dept_id NUMBER, sal NUMBER);
INSERT INTO emp VALUES (1, 10, 300);
INSERT INTO emp VALUES (2, 10, 500);
INSERT INTO emp VALUES (3, 20, 400);
COMMIT;
OUTPUT
Table created.


1 row created.


1 row created.


1 row created.


Commit complete.
Reproducerun as lab_a
SET SERVEROUTPUT ON
DECLARE
  v_cnt  NUMBER;
  p_dept NUMBER := NULL;
BEGIN
  EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM emp WHERE (dept_id = :dept OR :dept IS NULL)'
    INTO v_cnt USING p_dept;
  DBMS_OUTPUT.PUT_LINE('count = ' || v_cnt);
END;
/
✕ ERROR
DECLARE
*
ERROR at line 1:
ORA-01008: value for bind variable placeholder 2 was not provided
ORA-06512: at line 5
Help: https://docs.oracle.com/error-help/db/ora-01008/
Check the causerun as lab_a
COLUMN placeholder FORMAT A20
WITH s AS (SELECT 'SELECT COUNT(*) FROM emp WHERE (dept_id = :dept OR :dept IS NULL)' AS q FROM dual)
SELECT LEVEL AS pos, REGEXP_SUBSTR(q, ':[a-z_]+', 1, LEVEL) AS placeholder
  FROM s CONNECT BY LEVEL <= REGEXP_COUNT(q, ':[a-z_]+');
OUTPUT
       POS PLACEHOLDER
---------- --------------------
         1 :dept
         2 :dept

2 rows selected.

The list shows :dept at both position 1 and position 2. Same name, but two positions, so two values are needed.

This positional rule applies to dynamic SQL statements. If you want one value, you can also rename them :dept1 and :dept2 so the count is obvious.

Fix: run the corrected statementrun as lab_a
SET SERVEROUTPUT ON
DECLARE
  v_cnt  NUMBER;
  p_dept NUMBER := NULL;
BEGIN
  EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM emp WHERE (dept_id = :dept OR :dept IS NULL)'
    INTO v_cnt USING p_dept, p_dept;
  DBMS_OUTPUT.PUT_LINE('count = ' || v_cnt);
END;
/
✓ SUCCESS
count = 3

PL/SQL procedure successfully completed.

03OPEN cursor FOR '...' without USING

A ref cursor opened from a string with :dept needs a USING clause too. Without it the error was raised at OPEN (line 6), placeholder 1.

Add USING 10 after the string. The loop printed employees 1 and 2 (300, 500).

Setup
Setuprun as lab_a
CREATE TABLE emp (emp_id NUMBER PRIMARY KEY, dept_id NUMBER, sal NUMBER);
INSERT INTO emp VALUES (1, 10, 300);
INSERT INTO emp VALUES (2, 10, 500);
INSERT INTO emp VALUES (3, 20, 400);
COMMIT;
OUTPUT
Table created.


1 row created.


1 row created.


1 row created.


Commit complete.
Reproducerun as lab_a
SET SERVEROUTPUT ON
DECLARE
  c     SYS_REFCURSOR;
  v_id  NUMBER;
  v_sal NUMBER;
BEGIN
  OPEN c FOR 'SELECT emp_id, sal FROM emp WHERE dept_id = :dept ORDER BY emp_id';
  LOOP
    FETCH c INTO v_id, v_sal;
    EXIT WHEN c%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(v_id || ' ' || v_sal);
  END LOOP;
  CLOSE c;
END;
/
✕ ERROR
DECLARE
*
ERROR at line 1:
ORA-01008: value for bind variable placeholder 1 was not provided
ORA-06512: at line 6
Help: https://docs.oracle.com/error-help/db/ora-01008/
Check the causerun as lab_a
COLUMN placeholder FORMAT A20
WITH s AS (SELECT 'SELECT emp_id, sal FROM emp WHERE dept_id = :dept ORDER BY emp_id' AS q FROM dual)
SELECT LEVEL AS pos, REGEXP_SUBSTR(q, ':[a-z_]+', 1, LEVEL) AS placeholder
  FROM s CONNECT BY LEVEL <= REGEXP_COUNT(q, ':[a-z_]+');
OUTPUT
       POS PLACEHOLDER
---------- --------------------
         1 :dept

1 row selected.

The cursor SQL has one placeholder, :dept at position 1, which is the position the error named.

Fix: run the corrected statementrun as lab_a
SET SERVEROUTPUT ON
DECLARE
  c     SYS_REFCURSOR;
  v_id  NUMBER;
  v_sal NUMBER;
BEGIN
  OPEN c FOR 'SELECT emp_id, sal FROM emp WHERE dept_id = :dept ORDER BY emp_id' USING 10;
  LOOP
    FETCH c INTO v_id, v_sal;
    EXIT WHEN c%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(v_id || ' ' || v_sal);
  END LOOP;
  CLOSE c;
END;
/
✓ SUCCESS
1 300
2 500

PL/SQL procedure successfully completed.

04DBMS_SQL: a BIND_VARIABLE call is missing

The SQL given to DBMS_SQL.PARSE had two placeholders, :new_dept and :old_dept, but only :new_dept was bound. DBMS_SQL.EXECUTE failed with ORA-01008 (ORA-06512: at line 7, the EXECUTE line). Unlike EXECUTE IMMEDIATE, the message here left the placeholder number blank: value for bind variable placeholder was not provided.

After adding DBMS_SQL.BIND_VARIABLE(c, ':old_dept', 10), the block printed 2 rows updated.

Setup
Setuprun as lab_a
CREATE TABLE emp (emp_id NUMBER PRIMARY KEY, dept_id NUMBER);
INSERT INTO emp VALUES (1, 10);
INSERT INTO emp VALUES (2, 10);
INSERT INTO emp VALUES (3, 30);
COMMIT;
OUTPUT
Table created.


1 row created.


1 row created.


1 row created.


Commit complete.
Reproducerun as lab_a
DECLARE
  c NUMBER := DBMS_SQL.OPEN_CURSOR;
  n NUMBER;
BEGIN
  DBMS_SQL.PARSE(c, 'UPDATE emp SET dept_id = :new_dept WHERE dept_id = :old_dept', DBMS_SQL.NATIVE);
  DBMS_SQL.BIND_VARIABLE(c, ':new_dept', 20);
  n := DBMS_SQL.EXECUTE(c);
  DBMS_OUTPUT.PUT_LINE(n || ' rows updated');
  DBMS_SQL.CLOSE_CURSOR(c);
END;
/
✕ ERROR
DECLARE
*
ERROR at line 1:
ORA-01008: value for bind variable placeholder  was not provided
ORA-06512: at "SYS.DBMS_SQL", line 1838
ORA-06512: at line 7
Help: https://docs.oracle.com/error-help/db/ora-01008/
Check the causerun as lab_a
COLUMN placeholder FORMAT A20
WITH s AS (SELECT 'UPDATE emp SET dept_id = :new_dept WHERE dept_id = :old_dept' AS q FROM dual)
SELECT LEVEL AS pos, REGEXP_SUBSTR(q, ':[a-z_]+', 1, LEVEL) AS placeholder
  FROM s CONNECT BY LEVEL <= REGEXP_COUNT(q, ':[a-z_]+');
OUTPUT
       POS PLACEHOLDER
---------- --------------------
         1 :new_dept
         2 :old_dept

2 rows selected.

The parsed SQL has two placeholders: 1 :new_dept and 2 :old_dept. BIND_VARIABLE was called only for :new_dept, so :old_dept is the missing one.

Every placeholder in the parsed SQL needs its own BIND_VARIABLE call before EXECUTE. When the SQL text is built from conditions, add the bind in the same IF that adds the condition.

Fix: run the corrected statementrun as lab_a
DECLARE
  c NUMBER := DBMS_SQL.OPEN_CURSOR;
  n NUMBER;
BEGIN
  DBMS_SQL.PARSE(c, 'UPDATE emp SET dept_id = :new_dept WHERE dept_id = :old_dept', DBMS_SQL.NATIVE);
  DBMS_SQL.BIND_VARIABLE(c, ':new_dept', 20);
  DBMS_SQL.BIND_VARIABLE(c, ':old_dept', 10);
  n := DBMS_SQL.EXECUTE(c);
  DBMS_OUTPUT.PUT_LINE(n || ' rows updated');
  DBMS_SQL.CLOSE_CURSOR(c);
END;
/
SELECT emp_id, dept_id FROM emp ORDER BY emp_id;
ROLLBACK;
✓ SUCCESS
2 rows updated

PL/SQL procedure successfully completed.


    EMP_ID    DEPT_ID
---------- ----------
         1         20
         2         20
         3         30

3 rows selected.


Rollback complete.

05:new written inside dynamic SQL in a trigger

The row trigger orders_ai ran EXECUTE IMMEDIATE 'INSERT INTO orders_log ... VALUES (:new.order_id, SYSDATE)'. A plain INSERT INTO orders then failed with ORA-01008 for placeholder 1, raised from LAB_A.ORDERS_AI (ORA-04088). Inside the string, :new.order_id is not the trigger's :new record; the dynamic statement sees it as just another bind placeholder, and nothing was passed for it.

The trigger was rewritten with a normal placeholder :id and USING :new.order_id. The same INSERT then succeeded and orders_log had order 1.

Setup
Setuprun as lab_a
CREATE TABLE orders (order_id NUMBER PRIMARY KEY, amount NUMBER);
CREATE TABLE orders_log (order_id NUMBER, logged_at DATE);
CREATE OR REPLACE TRIGGER orders_ai
AFTER INSERT ON orders FOR EACH ROW
BEGIN
  EXECUTE IMMEDIATE 'INSERT INTO orders_log (order_id, logged_at) VALUES (:new.order_id, SYSDATE)';
END;
/
OUTPUT
Table created.


Table created.


Trigger created.
Reproducerun as lab_a
INSERT INTO orders VALUES (1, 500);
✕ ERROR
INSERT INTO orders VALUES (1, 500)
            *
ERROR at line 1:
ORA-01008: value for bind variable placeholder 1 was not provided
ORA-06512: at "LAB_A.ORDERS_AI", line 2
ORA-04088: error during execution of trigger 'LAB_A.ORDERS_AI'
Help: https://docs.oracle.com/error-help/db/ora-01008/
Check the causerun as lab_a
COLUMN text FORMAT A90
SELECT line, text FROM user_source WHERE name = 'ORDERS_AI' AND UPPER(text) LIKE '%:NEW%';
OUTPUT
      LINE TEXT
---------- ------------------------------------------------------------------------------------------
         4   EXECUTE IMMEDIATE 'INSERT INTO orders_log (order_id, logged_at) VALUES (:new.order_id, S
           YSDATE)';


1 row selected.

user_source shows :new.order_id inside the quoted string passed to EXECUTE IMMEDIATE, with no USING clause after it.

Fixrun as lab_a
CREATE OR REPLACE TRIGGER orders_ai
AFTER INSERT ON orders FOR EACH ROW
BEGIN
  EXECUTE IMMEDIATE 'INSERT INTO orders_log (order_id, logged_at) VALUES (:id, SYSDATE)'
    USING :new.order_id;
END;
/
OUTPUT
Trigger created.

If the SQL doesn't need to be dynamic, write the INSERT directly in the trigger body; :new works there without USING.

After the fixrun as lab_a
INSERT INTO orders VALUES (1, 500);
COMMIT;
SELECT order_id FROM orders_log;
✓ SUCCESS
1 row created.


Commit complete.


  ORDER_ID
----------
         1

1 row selected.

06Dynamic INSERT has RETURNING INTO :var, but EXECUTE IMMEDIATE has no RETURNING INTO

The SQL string ends with RETURNING order_id INTO :new_id, but EXECUTE IMMEDIATE only passed USING 'KIM'. :new_id is a placeholder too and needs a variable to receive the value, so 26ai reported that placeholder 2 was not provided.

Setup
Setuprun as lab_a
CREATE TABLE orders (
  order_id  NUMBER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  cust_name VARCHAR2(30)
);
OUTPUT
Table created.
Reproducerun as lab_a
SET SERVEROUTPUT ON
DECLARE
  v_id  NUMBER;
  v_sql VARCHAR2(200) := 'INSERT INTO orders (cust_name) VALUES (:name) RETURNING order_id INTO :new_id';
BEGIN
  EXECUTE IMMEDIATE v_sql USING 'KIM';
  DBMS_OUTPUT.PUT_LINE('new order_id = ' || v_id);
END;
/
✕ ERROR
DECLARE
*
ERROR at line 1:
ORA-01008: value for bind variable placeholder 2 was not provided
ORA-06512: at line 5
Help: https://docs.oracle.com/error-help/db/ora-01008/
Check the causerun as lab_a
COLUMN placeholder FORMAT A20
WITH s AS (SELECT 'INSERT INTO orders (cust_name) VALUES (:name) RETURNING order_id INTO :new_id' AS q FROM dual)
SELECT LEVEL AS pos, REGEXP_SUBSTR(q, ':[a-z_]+', 1, LEVEL) AS placeholder
  FROM s CONNECT BY LEVEL <= REGEXP_COUNT(q, ':[a-z_]+');
SELECT COUNT(*) AS cnt FROM orders;
OUTPUT
       POS PLACEHOLDER
---------- --------------------
         1 :name
         2 :new_id

2 rows selected.


       CNT
----------
         0

1 row selected.

The placeholders are 1 :name and 2 :new_id; position 2 is the RETURNING target. The failed INSERT did not happen: orders has 0 rows (CNT 0).

Receive RETURNING values with a RETURNING INTO clause, not USING: EXECUTE IMMEDIATE ... USING 'KIM' RETURNING INTO v_id. After the change it printed new order_id = 1.

Fix: run the corrected statementrun as lab_a
SET SERVEROUTPUT ON
DECLARE
  v_id  NUMBER;
  v_sql VARCHAR2(200) := 'INSERT INTO orders (cust_name) VALUES (:name) RETURNING order_id INTO :new_id';
BEGIN
  EXECUTE IMMEDIATE v_sql USING 'KIM'
    RETURNING INTO v_id;
  DBMS_OUTPUT.PUT_LINE('new order_id = ' || v_id);
END;
/
✓ SUCCESS
new order_id = 1

PL/SQL procedure successfully completed.

FAQ

What does ORA-01008 not all variables bound mean?

A :placeholder in the SQL got no value. Count the placeholders in the SQL string and compare with the values in USING.

Why ORA-01008 when I use the same bind variable twice?

In EXECUTE IMMEDIATE each occurrence is a separate position. :dept twice needs USING p_dept, p_dept.

Which bind variable is missing?

In 23ai the message names the position, for example placeholder 2. Count the : placeholders from the left.

Does ORA-01008 happen with static SQL in PL/SQL?

Not from PL/SQL variables, because they are bound automatically. All cases on this page are dynamic SQL strings (EXECUTE IMMEDIATE, OPEN FOR, DBMS_SQL).

How do I fix ORA-01008 with DBMS_SQL?

Call DBMS_SQL.BIND_VARIABLE once for every :name in the parsed SQL before DBMS_SQL.EXECUTE. In this check the message did not show which placeholder was missing, so compare the names in the SQL text with your bind calls.

Why does :new in EXECUTE IMMEDIATE inside a trigger give ORA-01008?

In a dynamic SQL string, :new.col is treated as an ordinary bind placeholder, not the trigger record. Use a placeholder such as :id in the string and pass USING :new.col.

EXECUTE IMMEDIATE INSERT ... RETURNING INTO raises ORA-01008. How do I fix it?

The :var after RETURNING counts as a placeholder. Add a RETURNING INTO variable clause to EXECUTE IMMEDIATE instead of putting it in USING. In the run above, the missing clause gave placeholder 2 was not provided, and adding it printed the new id.

ORA-01008 only happens with some search conditions in my dynamic SQL. Why?

If you append AND col = :x only when a parameter is set, the number of placeholders changes but your USING list does not. In the run above, one filter worked and two filters failed with placeholder 2 was not provided. Append AND (1 = 1 OR :x IS NULL) for unused filters so USING can always pass every value.

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