<?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: Oracle to GDB table copy (using a where clause to limit rows) in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/oracle-to-gdb-table-copy-using-a-where-clause-to/m-p/126012#M9828</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think that I found a solution.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Used MakeQueryTable_management() to make a view to the table with a where clause that limits the rows.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Use TableToTable_conversion() to copy to a table inside the GDB.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This worked in both ArcMap and a stand-alone script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I appreciate you taking the time to help.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 24 Apr 2014 17:47:28 GMT</pubDate>
    <dc:creator>KendallRussell</dc:creator>
    <dc:date>2014-04-24T17:47:28Z</dc:date>
    <item>
      <title>Oracle to GDB table copy (using a where clause to limit rows)</title>
      <link>https://community.esri.com/t5/python-questions/oracle-to-gdb-table-copy-using-a-where-clause-to/m-p/126007#M9823</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am having difficulty finding a way that will copy a subset of rows from a table stored in Oracle to a GDB.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is an example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Source table contains the following fields - "SCHEDULE_TIME", "ADDRESS", "CITY", "STATE", "ZIP_CODE", "ROUTE_ID", "x", "y"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to extract all of the records for a route_id in one zip_code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is what I have tried so far:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1.&amp;nbsp; The following code ended up copying the entire table to the GDB.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt; strZipCode = "72645" strRouteId = "C024"&amp;nbsp; sqlWhereStmt="\"ZIP_CODE\"='{0}' and \"ROUTE_ID\"='{1}'".format(strZipCode, strRouteId)&amp;nbsp; #MAKE A VIEW OF THE TABLE AND LIMIT THE ROWS BY THE WHERE CLAUSE arcpy.MakeTableView_management("SourceRoute_T", "SourceRoute_V", sqlWhereStmt)&amp;nbsp; #COPY THE TABLE BY USING THE VIEW CREATED ABOVE arcpy.TableToTable_conversion("SourceRoute_V", "C:\\DDT\\Work\\work.gdb", "route_72645C024_T") &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2.&amp;nbsp; This following code failed during the call to TableToTable_conversion with an error about the source table not having OIDs&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The only change is that the where clause has been moved to the TableTable_conversion function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt; strZipCode = "72645" strRouteId = "C024"&amp;nbsp; sqlWhereStmt="\"ZIP_CODE\"='{0}' and \"ROUTE_ID\"='{1}'".format(strZipCode, strRouteId)&amp;nbsp; #MAKE A VIEW OF THE TABLE AND LIMIT THE ROWS BY THE WHERE CLAUSE arcpy.MakeTableView_management("SourceRoute_T", "SourceRoute_V")&amp;nbsp; #COPY THE TABLE BY USING THE VIEW CREATED ABOVE arcpy.TableToTable_conversion("SourceRoute_V", "C:\\DDT\\Work\\work.gdb", "route_72645C024_T", sqlWhereStmt) &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Apr 2014 14:29:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/oracle-to-gdb-table-copy-using-a-where-clause-to/m-p/126007#M9823</guid>
      <dc:creator>KendallRussell</dc:creator>
      <dc:date>2014-04-24T14:29:13Z</dc:date>
    </item>
    <item>
      <title>Re: Oracle to GDB table copy (using a where clause to limit rows)</title>
      <link>https://community.esri.com/t5/python-questions/oracle-to-gdb-table-copy-using-a-where-clause-to/m-p/126008#M9824</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Can you copy in your entire code you executed?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you have set your workspace to SDE use a staging area to save your table view.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Apr 2014 14:32:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/oracle-to-gdb-table-copy-using-a-where-clause-to/m-p/126008#M9824</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2014-04-24T14:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: Oracle to GDB table copy (using a where clause to limit rows)</title>
      <link>https://community.esri.com/t5/python-questions/oracle-to-gdb-table-copy-using-a-where-clause-to/m-p/126009#M9825</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Can you copy in your entire code you executed?&lt;BR /&gt;&lt;BR /&gt;If you have set your workspace to SDE use a staging area to save your table view.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
#IMPORTS - PYTHON
import os
#IMPORTS - THIRD PARTY
import arcpy
#IMPORTS - PROJECT

#ESRI - CHECKOUT LICENSE
arcpy.CheckOutExtension("Network")
#ESRI - Set Geoprocessing environments
arcpy.env.XYResolution = "1 Meters"
arcpy.env.XYTolerance = "1 Meters"

#LOCAL GDB
gdbWorkLoc = "D:\\arc10data\\DMS\\Scripts\\Work"
gdbWorkName= "work.gdb"
gdbWorkFull= "{0}\\{1}".format(gdbWorkLoc, gdbWorkName)

#DATABASE PIVOT TABLE
sdeDmsConn = "D:\\arc10data\\DMS\\Scripts\\DBConnections\\DAISGS-DMS.sde"
dbtPivot&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = "{0}\\DMS_ADM.DPIVOT_T".format(sdeDmsConn)

def main():
&amp;nbsp;&amp;nbsp;&amp;nbsp; #ESTABLISH ZIP AND ROUTE TO WORK WITH
&amp;nbsp;&amp;nbsp;&amp;nbsp; strZipCode = "38111"
&amp;nbsp;&amp;nbsp;&amp;nbsp; strCridId&amp;nbsp; = "C061"
&amp;nbsp;&amp;nbsp;&amp;nbsp; strZipCrid = strZipCode + strCridId

&amp;nbsp;&amp;nbsp;&amp;nbsp; #OUTPUT GDB TABLE
&amp;nbsp;&amp;nbsp;&amp;nbsp; tblRouteSingleName = "Route_{0}_T".format(strZipCrid)
&amp;nbsp;&amp;nbsp;&amp;nbsp; tblRouteSingleFull = "{0}\\{1}".format(gdbWorkFull, tblRouteSingleName)

&amp;nbsp;&amp;nbsp;&amp;nbsp; #OUTPUT VIEW OF PIVOT TABLE
&amp;nbsp;&amp;nbsp;&amp;nbsp; viewPivot = "PivotView"

&amp;nbsp;&amp;nbsp;&amp;nbsp; #CREATE OUTPUT GDB
&amp;nbsp;&amp;nbsp;&amp;nbsp; if not os.path.exists(gdbWorkFull):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CreateFileGDB_management(gdbWorkLoc, gdbWorkName)

&amp;nbsp;&amp;nbsp;&amp;nbsp; #BUILD WHERE CLAUSE TO LIMIT ROWS
&amp;nbsp;&amp;nbsp;&amp;nbsp; sqlWhere="\"ZIP_CODE\"='{0}' and \"CRID_ID\"='{1}'".format(strZipCode, strCridId)

&amp;nbsp;&amp;nbsp;&amp;nbsp; #DELETE GDB TABLE IF EXISTS
&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.Exists(tblRouteSingleFull):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(tblRouteSingleFull)

&amp;nbsp;&amp;nbsp;&amp;nbsp; r1=arcpy.MakeTableView_management(dbtPivot, viewPivot, sqlWhere)
&amp;nbsp;&amp;nbsp;&amp;nbsp; r2=arcpy.TableToTable_conversion(viewPivot, gdbWorkFull, tblRouteSingleName)


if __name__ == '__main__':
&amp;nbsp;&amp;nbsp;&amp;nbsp; main()
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:09:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/oracle-to-gdb-table-copy-using-a-where-clause-to/m-p/126009#M9825</guid>
      <dc:creator>KendallRussell</dc:creator>
      <dc:date>2021-12-11T07:09:54Z</dc:date>
    </item>
    <item>
      <title>Re: Oracle to GDB table copy (using a where clause to limit rows)</title>
      <link>https://community.esri.com/t5/python-questions/oracle-to-gdb-table-copy-using-a-where-clause-to/m-p/126010#M9826</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This is the code that exports the entire table? Nothing looks glaringly wrong. What version of ArcGIS are you using?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The first thing I would try is removing the maketableview completely. Use the query parameter for the tabletotable function instead to see if you get any different results. I would also change your query to something like this. Also verify that your query is valid and returns the expected results using ArcMap.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sqlWhere = "{0} = '{1}' AND {2} = '{3}'".format(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddFieldDelimiters(dbtPivot, 'ZIP_CODE'), strZipCode,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddFieldDelimiters(dbtPivot, 'CRID_ID'), strCridId)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I just have a few other minor suggestions.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You shouldn't need the r1= and r2= parts. Also try setting your workspace to your output GDB. And, os.path.join is a better way of joining paths, yours seem like they should be fine and you would be getting some different errors if that was the issue. But it is something to keep in mind.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:09:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/oracle-to-gdb-table-copy-using-a-where-clause-to/m-p/126010#M9826</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-11T07:09:56Z</dc:date>
    </item>
    <item>
      <title>Re: Oracle to GDB table copy (using a where clause to limit rows)</title>
      <link>https://community.esri.com/t5/python-questions/oracle-to-gdb-table-copy-using-a-where-clause-to/m-p/126011#M9827</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, this is the code that ends up exporting the entire table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is what I have done so far and the results:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Added AddFieldDelimiters() to the build of the where clause.&amp;nbsp; This built the where clause differently - no double quotes around the field names.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Result:&amp;nbsp; No difference, the entire table was exported to the GDB.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Note:&amp;nbsp; I ran these steps in ArcMAP - MakeTableView_management() with the where clause then TableToTable_conversion() and it did the same thing.&amp;nbsp; The entire table was exported to the GDB.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. I moved the where clause from the MakeTableView_management() to the TableToTable_conversion() function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeTableView_management(dbtPivot, viewPivot)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.TableToTable_conversion(viewPivot, gdbWorkFull, tblRouteSingleName, sqlWhere)
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Result: Execution Error&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"ExecuteError: ERROR 000339: Input DMS_ADM.DPIVOT_T does not have OIDs&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Failed to execute (TableToTable)"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Note: same results when ran in ArcMap&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;3. I removed MakeTableView() (I left in the AddFieldDelimiters()) and I just called TableToTable_conversion using the name of the &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;table in Oracle as the input.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
#&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeTableView_management(dbtPivot, viewPivot)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.TableToTable_conversion(dbtPivot, gdbWorkFull, tblRouteSingleName, sqlWhere)
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Result: Execution Error&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"ExecuteError: ERROR 000339: Input DMS_ADM.DPIVOT_T does not have OIDs&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Failed to execute (TableToTable)"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Note: Same results when ran in ArcMap&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:09:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/oracle-to-gdb-table-copy-using-a-where-clause-to/m-p/126011#M9827</guid>
      <dc:creator>KendallRussell</dc:creator>
      <dc:date>2021-12-11T07:09:59Z</dc:date>
    </item>
    <item>
      <title>Re: Oracle to GDB table copy (using a where clause to limit rows)</title>
      <link>https://community.esri.com/t5/python-questions/oracle-to-gdb-table-copy-using-a-where-clause-to/m-p/126012#M9828</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think that I found a solution.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Used MakeQueryTable_management() to make a view to the table with a where clause that limits the rows.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Use TableToTable_conversion() to copy to a table inside the GDB.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This worked in both ArcMap and a stand-alone script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I appreciate you taking the time to help.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Apr 2014 17:47:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/oracle-to-gdb-table-copy-using-a-where-clause-to/m-p/126012#M9828</guid>
      <dc:creator>KendallRussell</dc:creator>
      <dc:date>2014-04-24T17:47:28Z</dc:date>
    </item>
  </channel>
</rss>

