Lab-verifiedReproduced and fixed on Oracle AI Database 26ai Free 23.26.3.0.0 · 2026-11-29 · container image gvenzl/oracle-free:23-slim
ORA-01006 comes from dynamic SQL: EXECUTE IMMEDIATE … USING or DBMS_SQL.BIND_VARIABLE. Oracle compares the values you bind with the :placeholders it finds in the statement string, and you bound one that does not exist.
The ORA-06512: at line N under it points to the PL/SQL line that did the binding. Print the SQL string (DBMS_OUTPUT or SELECT it) and count the placeholders.
01More values in USING than placeholders in the statement
The statement has one placeholder (:d) but USING 10, 'KIM' passes two values. This often happens when a condition is removed from the SQL string but its value is left in USING. ORA-06512: at line 4 is the EXECUTE IMMEDIATE line.
Setup
CREATE TABLE emp (empno NUMBER PRIMARY KEY, ename VARCHAR2(20), deptno NUMBER);
INSERT INTO emp VALUES (1, 'KIM', 10);
INSERT INTO emp VALUES (2, 'LEE', 20);
COMMIT;Table created.
1 row created.
1 row created.
Commit complete.SET SERVEROUTPUT ON
DECLARE
v_cnt NUMBER;
BEGIN
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM emp WHERE deptno = :d'
INTO v_cnt USING 10, 'KIM';
DBMS_OUTPUT.PUT_LINE('count=' || v_cnt);
END;
/DECLARE
*
ERROR at line 1:
ORA-01006: Bind variable does not exist.
ORA-06512: at line 4
Help: https://docs.oracle.com/error-help/db/ora-01006/SELECT COUNT(*) FROM emp WHERE deptno = 10; COUNT(*)
----------
1
1 row selected.Make the counts match. Here the intended name condition AND ename = :n was added back, so two placeholders get two values and the count is 1. If the condition is not needed, remove the extra value from USING instead.
SET SERVEROUTPUT ON
DECLARE
v_cnt NUMBER;
BEGIN
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM emp WHERE deptno = :d AND ename = :n'
INTO v_cnt USING 10, 'KIM';
DBMS_OUTPUT.PUT_LINE('count=' || v_cnt);
END;
/count=1
PL/SQL procedure successfully completed.02Placeholder written inside quotes (':name')
Inside the dynamic string, '':name'' becomes ':name' — a string literal, not a placeholder. SELECTing the same expression shows the actual statement text: WHERE ename = ':name'. The statement has no placeholder, so the USING value has nowhere to go.
Setup
CREATE TABLE emp (empno NUMBER PRIMARY KEY, ename VARCHAR2(20), deptno NUMBER);
INSERT INTO emp VALUES (1, 'KIM', 10);
COMMIT;Table created.
1 row created.
Commit complete.SET SERVEROUTPUT ON
DECLARE
v_no NUMBER;
BEGIN
EXECUTE IMMEDIATE 'SELECT empno FROM emp WHERE ename = '':name'''
INTO v_no USING 'KIM';
DBMS_OUTPUT.PUT_LINE('empno=' || v_no);
END;
/DECLARE
*
ERROR at line 1:
ORA-01006: Bind variable does not exist.
ORA-06512: at line 4
Help: https://docs.oracle.com/error-help/db/ora-01006/SELECT 'SELECT empno FROM emp WHERE ename = '':name''' AS stmt FROM dual;STMT
-------------------------------------------
SELECT empno FROM emp WHERE ename = ':name'
1 row selected.Do not quote placeholders. Oracle binds the value as a string by itself: WHERE ename = :name returns empno 1.
SET SERVEROUTPUT ON
DECLARE
v_no NUMBER;
BEGIN
EXECUTE IMMEDIATE 'SELECT empno FROM emp WHERE ename = :name'
INTO v_no USING 'KIM';
DBMS_OUTPUT.PUT_LINE('empno=' || v_no);
END;
/empno=1
PL/SQL procedure successfully completed.03DBMS_SQL.BIND_VARIABLE with a name that is not in the parsed SQL
The UPDATE uses :new_dept and :old_dept, but the code binds :dept. The stack shows SYS.DBMS_SQL and then at line 7, which is the BIND_VARIABLE call with the wrong name.
Setup
CREATE TABLE emp (empno NUMBER PRIMARY KEY, ename VARCHAR2(20), deptno NUMBER);
INSERT INTO emp VALUES (1, 'KIM', 10);
INSERT INTO emp VALUES (2, 'LEE', 10);
COMMIT;Table created.
1 row created.
1 row created.
Commit complete.SET SERVEROUTPUT ON
DECLARE
c INTEGER := DBMS_SQL.OPEN_CURSOR;
n INTEGER;
BEGIN
DBMS_SQL.PARSE(c, 'UPDATE emp SET deptno = :new_dept WHERE deptno = :old_dept', DBMS_SQL.NATIVE);
DBMS_SQL.BIND_VARIABLE(c, ':new_dept', 30);
DBMS_SQL.BIND_VARIABLE(c, ':dept', 10);
n := DBMS_SQL.EXECUTE(c);
DBMS_OUTPUT.PUT_LINE('updated=' || n);
DBMS_SQL.CLOSE_CURSOR(c);
END;
/DECLARE
*
ERROR at line 1:
ORA-01006: Bind variable does not exist.
ORA-06512: at "SYS.DBMS_SQL", line 1531
ORA-06512: at line 7
Help: https://docs.oracle.com/error-help/db/ora-01006/SELECT deptno, COUNT(*) FROM emp GROUP BY deptno; DEPTNO COUNT(*)
---------- ----------
10 2
1 row selected.Use exactly the names from the SQL text (:old_dept). The UPDATE then changes 2 rows (rolled back at the end of this example).
SET SERVEROUTPUT ON
DECLARE
c INTEGER := DBMS_SQL.OPEN_CURSOR;
n INTEGER;
BEGIN
DBMS_SQL.PARSE(c, 'UPDATE emp SET deptno = :new_dept WHERE deptno = :old_dept', DBMS_SQL.NATIVE);
DBMS_SQL.BIND_VARIABLE(c, ':new_dept', 30);
DBMS_SQL.BIND_VARIABLE(c, ':old_dept', 10);
n := DBMS_SQL.EXECUTE(c);
DBMS_OUTPUT.PUT_LINE('updated=' || n);
DBMS_SQL.CLOSE_CURSOR(c);
ROLLBACK;
END;
/updated=2
PL/SQL procedure successfully completed.FAQ
How do I fix ORA-01006 bind variable does not exist?
Print the dynamic SQL string and compare its :placeholders with the values in USING or the names in DBMS_SQL.BIND_VARIABLE. Remove the extra bind, or add the missing placeholder.
Why does ':name' in quotes cause ORA-01006?
Inside quotes it is a string literal, so the statement has no placeholder. Write :name without quotes; the bound value is already a string.
What is the difference between ORA-01006 and ORA-01008?
ORA-01006 means you bound a variable the SQL does not have. ORA-01008 (value for bind variable placeholder was not provided) is the opposite: the SQL has a placeholder that got no value.
Which line caused ORA-01006?
Look at the last ORA-06512: at line N. It points to the EXECUTE IMMEDIATE or BIND_VARIABLE call in your block.
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