<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python - Update Cursor - Oracle Database - ORA-00923 in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-update-cursor-oracle-database-ora-00923/m-p/1224281#M65914</link>
    <description>&lt;P&gt;Using &lt;FONT face="courier new,courier"&gt;arcpy.SearchCursor&lt;/FONT&gt; and&amp;nbsp;&lt;FONT face="courier new,courier"&gt;arcpy.UpdateCursor&lt;/FONT&gt; instead of &lt;FONT face="courier new,courier"&gt;arcpy.da.SearchCursor&lt;/FONT&gt;&amp;nbsp;and&amp;nbsp;&lt;FONT face="courier new,courier"&gt;arcpy.da.UpdateCursor&lt;/FONT&gt; is not helping your cause. "Old Cursors" are kludgy and mostly only present for reverse compatibility -- they should &lt;U&gt;not&lt;/U&gt; be used for new code (and pre-10.1 code should really be rewritten to not use them).&lt;/P&gt;&lt;P&gt;Whenever I've needed to do large database UPDATEs, I've used UPDATE in SQL statements. The usual procedure is to load the change data into a temporary table via FeatureClassToFeatureClass or TableToTable (or even &lt;FONT face="courier new,courier"&gt;arcpy.da.InsertCursor&lt;/FONT&gt;), then create an &lt;FONT face="courier new,courier"&gt;arcpy.ArcSDESQLExecute&lt;/FONT&gt; cursor to submit the SQL commands.&amp;nbsp; My most recent trick was to add an INSERT TRIGGER on the staging table, and let it do the UPDATE on the target table as each INSERT committed. This of course assumes that the target table is not versioned, though this is sometimes possible with the use of versioned views.&lt;/P&gt;&lt;P&gt;- V&lt;/P&gt;</description>
    <pubDate>Mon, 24 Oct 2022 14:36:13 GMT</pubDate>
    <dc:creator>VinceAngelo</dc:creator>
    <dc:date>2022-10-24T14:36:13Z</dc:date>
    <item>
      <title>Python - Update Cursor - Oracle Database - ORA-00923</title>
      <link>https://community.esri.com/t5/python-questions/python-update-cursor-oracle-database-ora-00923/m-p/1224246#M65908</link>
      <description>&lt;P&gt;Good day:&lt;/P&gt;&lt;P&gt;&amp;nbsp; I am working on a project that requires me to take data from a file GDB table and update a non-gis table in an Oracle database. I have multiple Update Cursor scripts that I use to update GDB FC(s) and table(s) and have no problems with that. When I build the script to update the Oracle database table, I keep getting DBMS error [ORA-00923: FROM keyword not found where expected]&lt;/P&gt;&lt;P&gt;I cannot figure out what is going on and how to fix this. The fields, to and from and path(s) are 100% correct.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've attached the update cursor python script. Is there something I am missing? I have 100% read/write permission on the Oracle database that is connected via an ODBC connection.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible that the ObjectID in the GDB table is causing a conflict since it doesnt exist in the Oracle table?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def AttributeUpdate(source_table, in_field, update_fields, join_table, join_key, join_values):
   
    # Make sure there is matching number of join and update fields
    update_dict = {}
    if len(update_fields) == len(join_values):
        for i in range(len(update_fields)):
            update_dict[join_values[i]] = update_fields[i]
            
        for k,v in update_dict.iteritems():
            # Create Dictionary
            path_dict = {}
            srows = arcpy.SearchCursor(join_table)
            for srow in srows:
                keyrow = srow.getValue(join_key)
                valrow = srow.getValue(k)
                path_dict[keyrow] = valrow
            del srow, srows
            
            # Update Cursor
            urows = arcpy.UpdateCursor(source_table)
            for row in urows:
                upkey = row.getValue(in_field)
                if upkey in path_dict:
                    row.setValue(v, path_dict[upkey])
                    urows.updateRow(row)
                else:
                    pass  # skip nulls
                
            del row, urows
            print '\'%s\' field in "%s" updated successfully' %(v, p.basename(source_table))
        
    else:
        print 'ERROR:  Number of update fields and value fields does not match'
            
if __name__ == '__main__':

    DCSI = r'Database Connections\DCSI.sde\DCSI.MEWCO_TRANS_RATING'
    GDB = r'C:\Users\cwafstet\Documents\GIS WORKING FILES LOCAL\ELECTRIC\MEWCo ELECTRIC SYSTEM.gdb\MEWCO_TRANS_RATING'

    # Attribute Update
    DCSI_fields = ['XFMR BANK RATING']
    GDB_fields = ['XFMR_BANK_RATING']

    AttributeUpdate(DCSI, 'XFMR BANK ID', DCSI_fields, GDB, 'XFMR_BANK_ID', GDB_fields)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 14:29:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-update-cursor-oracle-database-ora-00923/m-p/1224246#M65908</guid>
      <dc:creator>ModernElectric</dc:creator>
      <dc:date>2022-10-21T14:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Update Cursor - Oracle Database - ORA-00923</title>
      <link>https://community.esri.com/t5/python-questions/python-update-cursor-oracle-database-ora-00923/m-p/1224256#M65909</link>
      <description>&lt;P&gt;ORA-00923 means there's something wrong with your ORACLE sql statement:&lt;/P&gt;&lt;P&gt;ORA-00923 occurs when you try to execute a SELECT or REVOKE statement without a FROM keyword in its correct form and place. If you are seeing this error, the keyword FROM is spelled incorrectly, misplaced, or altogether missing. In Oracle, the keyword FROM must follow the last selected item in a SELECT statement or in the case of a REVOKE statement, the privileges. If the FROM keyword is missing or otherwise incorrect, you will see ORA-00923.&lt;/P&gt;&lt;P&gt;Seeing that you dont have a sql statement there in your cursors is interesting... Oracle is a different beast and since the table is non GIS, (which shouldn't make a difference in accessing it through an arcgis connection (I assume you are?) and cursor), you could use a pyodbc sql type connection and cursor using the oracle python package to make the updates.&lt;/P&gt;&lt;P&gt;curious why you are using the old cursors as well.&amp;nbsp; Maybe the .da. versions will handle Oracle better?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 15:03:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-update-cursor-oracle-database-ora-00923/m-p/1224256#M65909</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-10-21T15:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Update Cursor - Oracle Database - ORA-00923</title>
      <link>https://community.esri.com/t5/python-questions/python-update-cursor-oracle-database-ora-00923/m-p/1224263#M65910</link>
      <description>&lt;P&gt;Thank you for the feedback. I will take a closer look at the newer cursor to see if that may get me better results. I looked at the pyodbc sql module and that might be possible as well. Yeah, I am accessing the oracle database thru a ArcGIS connection. I will look into the Oracle Python Package as well to see if that might work better compared to the update cursor.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 15:09:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-update-cursor-oracle-database-ora-00923/m-p/1224263#M65910</guid>
      <dc:creator>ModernElectric</dc:creator>
      <dc:date>2022-10-21T15:09:08Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Update Cursor - Oracle Database - ORA-00923</title>
      <link>https://community.esri.com/t5/python-questions/python-update-cursor-oracle-database-ora-00923/m-p/1224272#M65911</link>
      <description>&lt;P&gt;Jeff:&amp;nbsp;&lt;/P&gt;&lt;P&gt;Wondering, based on the existing code that I have there with the GDB table path and the Oracle table path and the fields, could you assist me with the proper way to write the code for updating the Oracle table via the Update cursor? Would greatly appreciate it since I am struggling with this big time.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 15:31:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-update-cursor-oracle-database-ora-00923/m-p/1224272#M65911</guid>
      <dc:creator>ModernElectric</dc:creator>
      <dc:date>2022-10-21T15:31:06Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Update Cursor - Oracle Database - ORA-00923</title>
      <link>https://community.esri.com/t5/python-questions/python-update-cursor-oracle-database-ora-00923/m-p/1224277#M65912</link>
      <description>&lt;P&gt;Are you using ArcMap or ArcGIS Pro?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 15:48:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-update-cursor-oracle-database-ora-00923/m-p/1224277#M65912</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2022-10-21T15:48:04Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Update Cursor - Oracle Database - ORA-00923</title>
      <link>https://community.esri.com/t5/python-questions/python-update-cursor-oracle-database-ora-00923/m-p/1224279#M65913</link>
      <description>&lt;P&gt;I am using ArcMap. However, this script is being done outside of ArcMap/ArcPro in IDLE, stand-alone Python script that will eventually be combined into a series of Batch file(s).&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 15:50:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-update-cursor-oracle-database-ora-00923/m-p/1224279#M65913</guid>
      <dc:creator>ModernElectric</dc:creator>
      <dc:date>2022-10-21T15:50:33Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Update Cursor - Oracle Database - ORA-00923</title>
      <link>https://community.esri.com/t5/python-questions/python-update-cursor-oracle-database-ora-00923/m-p/1224281#M65914</link>
      <description>&lt;P&gt;Using &lt;FONT face="courier new,courier"&gt;arcpy.SearchCursor&lt;/FONT&gt; and&amp;nbsp;&lt;FONT face="courier new,courier"&gt;arcpy.UpdateCursor&lt;/FONT&gt; instead of &lt;FONT face="courier new,courier"&gt;arcpy.da.SearchCursor&lt;/FONT&gt;&amp;nbsp;and&amp;nbsp;&lt;FONT face="courier new,courier"&gt;arcpy.da.UpdateCursor&lt;/FONT&gt; is not helping your cause. "Old Cursors" are kludgy and mostly only present for reverse compatibility -- they should &lt;U&gt;not&lt;/U&gt; be used for new code (and pre-10.1 code should really be rewritten to not use them).&lt;/P&gt;&lt;P&gt;Whenever I've needed to do large database UPDATEs, I've used UPDATE in SQL statements. The usual procedure is to load the change data into a temporary table via FeatureClassToFeatureClass or TableToTable (or even &lt;FONT face="courier new,courier"&gt;arcpy.da.InsertCursor&lt;/FONT&gt;), then create an &lt;FONT face="courier new,courier"&gt;arcpy.ArcSDESQLExecute&lt;/FONT&gt; cursor to submit the SQL commands.&amp;nbsp; My most recent trick was to add an INSERT TRIGGER on the staging table, and let it do the UPDATE on the target table as each INSERT committed. This of course assumes that the target table is not versioned, though this is sometimes possible with the use of versioned views.&lt;/P&gt;&lt;P&gt;- V&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2022 14:36:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-update-cursor-oracle-database-ora-00923/m-p/1224281#M65914</guid>
      <dc:creator>VinceAngelo</dc:creator>
      <dc:date>2022-10-24T14:36:13Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Update Cursor - Oracle Database - ORA-00923</title>
      <link>https://community.esri.com/t5/python-questions/python-update-cursor-oracle-database-ora-00923/m-p/1224666#M65923</link>
      <description>&lt;P&gt;The direct SQL method is more explicit and would need an overhaul from what you have above. I like &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1060"&gt;@VinceAngelo&lt;/a&gt; 's suggestion to use the ArcSDEExecute method and would follow that route if possible.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think you could get the old data into a dictionary, and then iterate over it looking them up in the new values dictionary if there is a return, plug them into the sql and update.&amp;nbsp; esri provided an Conditional update using a transaction&amp;nbsp; example that I would follow to do this.&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/classes/arcsdesqlexecute.htm" target="_blank" rel="noopener"&gt;arcsdesqlexecute.htm&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2022 13:30:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-update-cursor-oracle-database-ora-00923/m-p/1224666#M65923</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-10-24T13:30:40Z</dc:date>
    </item>
  </channel>
</rss>

