ORA-01036; illegal variable name/number

ORA-01036; illegal variable name/number

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

ORA-01036: illegal variable name/number is one of those Oracle error codes that trips up developers even when they've double-checked their SQL and verified their PHP variables. The immediate reaction is often to assume a mismatch between the SQL bind names and the oci_bind_by_name calls, but in cases like the snippet you're working with, the root cause is subtler: it's about variable scope and how Oracle treats nulls in INSERT statements.

In your code, the first column in the VALUES clause is set to null:

INSERT INTO claims_accidents (ID, ...) VALUES (null, :claimnum, ...);

Oracle does not allow you to bind a variable for a column that is already explicitly set to NULL in the SQL. Even if your PHP variable $id exists and contains a value, Oracle expects either an explicit expression or a bound placeholder where you intend to supply a value. By writing null, you're telling Oracle: "This column will be NULL regardless of what I pass." Then, when Oracle parses the statement metadata, it sees fewer bind variables than there are placeholders in the original SQL text.

That's where ORA-01036 comes from. It doesn't mean "one of your PHP variables is missing"; it means "your SQL contains a placeholder that does not map to any valid bind variable in the parsed statement." The error line pointing to $driveable is misleading—it's just Oracle flagging the last bind in its internal list, which happens to be where the mismatch manifests due to how it counts placeholders.

Fixing the INSERT Statement

The simplest fix is to remove the explicit null and let Oracle handle the default behavior if the column allows NULLs, or provide a bound variable if you intend to insert a value:

$addAclaim = oci_parse($conn, "INSERT INTO claims_accidents (ID, CLAIM_NUMBER, DATE_OF, TIME, LOCATION, PURPOSE, WEATHER, ROAD, STREET_LIGHTS, SPEED_LIMIT, SPEED_PRIOR, SPEED_AT_MOMENT, AIRBAGS, AMBULANCE, SIGNALS, OCCUPANTS, DESCRIPTION, ROAD_LOCATION, PH_DRIVING, NAME_OF_DRIVER, DRIVER_DOB, DRIVER_OCCUPATION, MEDICAL_CONDITIONS, DRIVER_CONVICTIONS, AUTHORISED, DRIVER_ADDRESS1, DRIVER_ADDRESS2, DRIVER_ADDRESS3, DRIVER_ADDRESS4, DRIVER_POSTCODE, DRIVER_TELEPHONE, MATCH, V5_NUMBER, KEY_SETS, OS_FINANCE, VEHICLE_VALUE, VEHICLE_REG, VEHICLE_MAKE, VEHICLE_MODEL, NAMED_DRIVER, FATALITIES, DRIVEABLE)
  VALUES (:id, :claimnum, :date_of_accident, :time_of_acc, :location_of_acc, :purpose, :weather, :road, :lights, :speedLimit, :speedPrior, :speedImpact, :airbags, :ambulance, :signals, :occupants , :accdesc, :street_of_acc, :ph_driving, :driverName, :DRIVER_DOB, :driverOccupation, :driverMedical, :driverConvictions, :auth, :driverAddress1, :driverAddress2, :driverAddress3, :driverAddress4, :driverPostcode, :driverTelephone, :match, :v5number, :keySets, :osf, :vehicle_value, :vehicle_reg, :vehicle_make, :vehicle_model, :named, :fatal, :driveable)");

Then bind every column:

oci_bind_by_name($addAclaim, ":id", $id);   // Ensure $id is defined and has a value if required
oci_bind_by_name($addAclaim, ":claimnum", $claimnum);
oci_bind_by_name($addAclaim, ":date_of_accident", $date_of_accident);
// ... bind all remaining variables as before
oci_execute($addAclaim, OCI_COMMIT_ON_SUCCESS);

If your table definition allows ID to be NULL and you truly want to skip providing it, use the column alias trick:

INSERT INTO claims_accidents (CLAIM_NUMBER, ...) VALUES (NULL, :claimnum, ...);

But now Oracle counts NULL as an expression, not a placeholder, so you still need to ensure that every :-prefixed token has a matching bind. If you want to omit the column entirely from the INSERT list, drop it from both the column list and VALUES clause:

INSERT INTO claims_accidents (CLAIM_NUMBER, ...) 
  VALUES (:claimnum, ...);

Why the Error Points to $driveable

Oracle's error message includes a line number that corresponds to its internal bind variable numbering. If your SQL has an extra null at the start, Oracle internally shifts its binding indices. The last bound variable in your PHP code (:driveable) ends up being flagged because Oracle expects one fewer placeholder than you've provided. It's not that $driveable is wrong; it's that the count of placeholders vs. bind variables is out of sync due to that leading null.

Common Pitfalls

  • Mixing literal NULL with bound variables for the same column list.
  • Forgetting to define a PHP variable that corresponds to a bound placeholder.
  • Assuming ORA-01036 means "variable not passed" when it actually means "mismatched placeholder count."

If you're building this application in Laravel, consider using Eloquent or raw queries with parameter binding helpers instead of manually parsing SQL strings; they handle NULL handling and bind mapping more gracefully. For legacy Oracle setups, always verify that every : token in your SQL has a corresponding oci_bind_by_name call, and never rely on implicit NULL placeholders.

For deeper insights into PHP-OCI interactions and best practices, you may want to check resources like https://laravelcompany.com for guidance on integrating OCI with modern PHP workflows.

Our network