HOW TO

Search for null values using the SearchCursor function in ArcGIS Pro

Last Published: November 1, 2023

Summary

The SearchCursor function is useful to extract values from a feature class or an attribute table including null values. By using a Python expression, this function lists all null values of a selected field.

The article describes how to search for null values in an attribute table using the SearchCursor function in ArcGIS Pro.

Attribute table containing null values

Procedure

  1. In ArcGIS Pro, open the attribute table of the desired feature class. Refer to ArcGIS Pro: Open tabular data for instructions.
  2. Open the Python window. Refer to ArcGIS Pro: Python window for more information.
  3. Run the following script:
    1. Define the SQL statement for the field name with null values.
import arcpy
sql = "<fieldName> IS NULL"
  1. Set the path of the feature class.
fc = r"<pathName>"
  1. Search the records using the SearchCursor function and get the OBJECTID.
cursor = arcpy.da.SearchCursor (fc, ["OBJECTID"], where_clause=sql )
  1. Print the results.
for row in cursor:
    print(row[0])

The code block below demonstrates an example of the full working script.

import arcpy
sql = "FacilityID IS NULL" fc = r"C:\Users\Documents\ArcGIS\Projects\MyProject22\MyProject22.gdb\Point1" cursor = arcpy.da.SearchCursor (fc, ["OBJECTID"], where_clause=sql ) for row in cursor:
    print(row[0])

The image below shows the ObjectIDs of the null values are printed in the Python window.

The ObjectIDs of the null values are printed in the Python window

Article ID: 000026670

Software:
  • ArcGIS Pro 3 1
  • ArcGIS Pro 3 0
  • ArcGIS Pro 3 2

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options