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
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;Table created.
1 row created.
1 row created.
1 row created.
Commit complete.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;
/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/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_]+'); 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.
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;
/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
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;Table created.
1 row created.
1 row created.
1 row created.
Commit complete.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;
/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/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_]+'); 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.
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;
/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
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;Table created.
1 row created.
1 row created.
1 row created.
Commit complete.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;
/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/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_]+'); POS PLACEHOLDER
---------- --------------------
1 :dept
1 row selected.The cursor SQL has one placeholder, :dept at position 1, which is the position the error named.
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;
/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
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;Table created.
1 row created.
1 row created.
1 row created.
Commit complete.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;
/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/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_]+'); 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.
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;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
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;
/Table created.
Table created.
Trigger created.INSERT INTO orders VALUES (1, 500);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/COLUMN text FORMAT A90
SELECT line, text FROM user_source WHERE name = 'ORDERS_AI' AND UPPER(text) LIKE '%:NEW%'; 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.
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;
/Trigger created.If the SQL doesn't need to be dynamic, write the INSERT directly in the trigger body; :new works there without USING.
INSERT INTO orders VALUES (1, 500);
COMMIT;
SELECT order_id FROM orders_log;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
CREATE TABLE orders (
order_id NUMBER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
cust_name VARCHAR2(30)
);Table created.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;
/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/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; 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.
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;
/new order_id = 1
PL/SQL procedure successfully completed.07Dynamic search adds optional conditions, but USING always passes the same values
count_emp starts from WHERE 1 = 1 and appends AND dept_id = :dept or AND sal > :min_sal only when the parameter is not NULL, then runs EXECUTE IMMEDIATE v_sql INTO v_cnt USING p_dept. With only the department (count_emp(10, NULL)) it returned 2. With both filters (count_emp(10, 350)) the SQL had two placeholders but USING had one value, so it failed with placeholder 2 was not provided at line 11 of the function.
The number of placeholders changes with the input, while USING is fixed when you write the code. That is why this kind of search screen works in some tests and fails in others.
Setup
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;
CREATE OR REPLACE FUNCTION count_emp (p_dept NUMBER, p_min_sal NUMBER) RETURN NUMBER IS
v_sql VARCHAR2(400) := 'SELECT COUNT(*) FROM emp WHERE 1 = 1';
v_cnt NUMBER;
BEGIN
IF p_dept IS NOT NULL THEN
v_sql := v_sql || ' AND dept_id = :dept';
END IF;
IF p_min_sal IS NOT NULL THEN
v_sql := v_sql || ' AND sal > :min_sal';
END IF;
EXECUTE IMMEDIATE v_sql INTO v_cnt USING p_dept;
RETURN v_cnt;
END;
/Table created.
1 row created.
1 row created.
1 row created.
Commit complete.
Function created.SELECT count_emp(10, NULL) AS cnt FROM dual;
SELECT count_emp(10, 350) AS cnt FROM dual; CNT
----------
2
1 row selected.
SELECT count_emp(10, 350) AS cnt FROM dual
*
ERROR at line 1:
ORA-01008: value for bind variable placeholder 2 was not provided
ORA-06512: at "LAB_A.COUNT_EMP", line 11
Help: https://docs.oracle.com/error-help/db/ora-01008/COLUMN text FORMAT A70
SELECT line, text FROM user_source
WHERE name = 'COUNT_EMP' AND (text LIKE '%:%' OR text LIKE '%USING%')
ORDER BY line; LINE TEXT
---------- ----------------------------------------------------------------------
2 v_sql VARCHAR2(400) := 'SELECT COUNT(*) FROM emp WHERE 1 = 1';
6 v_sql := v_sql || ' AND dept_id = :dept';
9 v_sql := v_sql || ' AND sal > :min_sal';
11 EXECUTE IMMEDIATE v_sql INTO v_cnt USING p_dept;
4 rows selected.In user_source, two lines append a placeholder (:dept, :min_sal), but line 11 passes only USING p_dept.
CREATE OR REPLACE FUNCTION count_emp (p_dept NUMBER, p_min_sal NUMBER) RETURN NUMBER IS
v_sql VARCHAR2(400) := 'SELECT COUNT(*) FROM emp WHERE 1 = 1';
v_cnt NUMBER;
BEGIN
IF p_dept IS NOT NULL THEN
v_sql := v_sql || ' AND dept_id = :dept';
ELSE
v_sql := v_sql || ' AND (1 = 1 OR :dept IS NULL)';
END IF;
IF p_min_sal IS NOT NULL THEN
v_sql := v_sql || ' AND sal > :min_sal';
ELSE
v_sql := v_sql || ' AND (1 = 1 OR :min_sal IS NULL)';
END IF;
EXECUTE IMMEDIATE v_sql INTO v_cnt USING p_dept, p_min_sal;
RETURN v_cnt;
END;
/Function created.Make every placeholder appear in every case: when a filter is not used, append a dummy condition like AND (1 = 1 OR :min_sal IS NULL), and always pass USING p_dept, p_min_sal. The dummy condition is always true, so it does not filter rows. After the change all four combinations ran: 1, 2, 2 and 3 rows.
SELECT count_emp(10, 350) AS a, count_emp(10, NULL) AS b,
count_emp(NULL, 350) AS c, count_emp(NULL, NULL) AS d FROM dual; A B C D
---------- ---------- ---------- ----------
1 2 2 3
1 row selected.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