1

I have a geodatabase in Oracle with around 50 tables. I want to get the values in the 2nd field of every table in my geodatabase. I will be using the values in the 2nd field as an input for a geoprocessing tool. The 2nd field name is different in every table but the values are what I need for the tool. This is the code i'm working with so far:

import arcpy
aWS = r"C:\Users\dav\AppData\Roaming\ESRI\Desktop10.3\ArcCatalog\Connection to OracleGDB.sde"
arcpy.env.workspace = aWS

arcpy.env.overwriteOutput = True

luList = arcpy.ListTables("*LK")
for lu in luList:
    print lu

    Desc = "DESCRIPTION"

    cursor = arcpy.SearchCursor(lu)
    for row in cursor:
        print(row.getValue(Desc))


       #Get the values in the 2nd field of lu and put it in the "2ndField" input

       #Run Table to Domain function
       arcpy.TableToDomain_management(lu, 2ndField, Desc, "NewGeo.gdb", 2ndFieldName, "DESCRIPTION")
3
  • Have a look at arcpy.listfields. Also you should be using arcpy.da.searchcursor instead.
    – Fezter
    Commented Mar 18, 2016 at 21:53
  • Yes, I've looked at that: 'fields = arcpy.ListFields(lu) for field in fields: print field.name' but I'm not sure how to get the 2nd field
    – Djb
    Commented Mar 18, 2016 at 22:00
  • Once you've done that, to get the second element of the list called fields, just fields[1].
    – Fezter
    Commented Mar 18, 2016 at 22:19

1 Answer 1

3

Try this:

import arcpy
aWS = r"C:\Users\dav\AppData\Roaming\ESRI\Desktop10.3\ArcCatalog\Connection to OracleGDB.sde"
arcpy.env.workspace = aWS

arcpy.env.overwriteOutput = True

luList = arcpy.ListTables("*LK")
for lu in luList:
    print lu

    #Get the name of the second field in the current table
    fieldsInTable = arcpy.ListFields(lu)
    secondFieldName = fieldsInTable[1].name
    print "Second field in " + lu + " is named: " + secondFieldName

    Desc = "DESCRIPTION"

    cursor = arcpy.SearchCursor(lu)
    for row in cursor:
        print(row.getValue(Desc))


       #Get the values in the 2nd field of lu and put it in the "2ndField" input
       secondFieldValue = str(row.getValue(secondFieldName)

       #Let's map my variables to your tool's variables
       #You can change this if you need to - I'm making assumptions here
       2ndFieldName = secondFieldName
       2ndField = secondFieldValue

       #Run Table to Domain function
       arcpy.TableToDomain_management(lu, 2ndField, Desc, "NewGeo.gdb", 2ndFieldName, "DESCRIPTION")
2
  • This may answer your question on how to get the second field name, but the code to load the domain is incorrect. I guess that would be a different question though.
    – RHB
    Commented Mar 19, 2016 at 1:43
  • This worked and I was able to get the second field name, but @RHB is correct; I am unable to populate domains from the Oracle database. Any clue on how to do that? I suppose I'll ask another question formally
    – Djb
    Commented Mar 22, 2016 at 22:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.