<?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 table to file geodatabase in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/oracle-table-to-file-geodatabase/m-p/546178#M42594</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;A few things jump out to me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;First, without seeing what is in the sql query it is rather hard to figure out the input side of the algorithm.&amp;nbsp; Also running raw sql from the command line is a big security hole. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Next your output location is a geodatabase, not a table. Change this statement:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;out_workspace = "C:\Temp\Extraction_Toad\Scratch_Toad.gdb"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;to &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;out_workspace = r"C:\Temp\Extraction_Toad\Scratch_Toad.gdb\" + out_name&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;or &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;out_workspace = "C:\\Temp\\Extraction_Toad\\Scratch_Toad.gdb\\" + out_name&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;or &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;out_workspace = "C:/Temp/Extraction_Toad/Scratch_Toad.gdb/" + out_name&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Multiple versions because Python does not deal well with \ as a directory separator.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would also probably wait to close out the Oracle cursor and connection until the end of the script.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 24 Feb 2012 16:31:49 GMT</pubDate>
    <dc:creator>David_JAnderson</dc:creator>
    <dc:date>2012-02-24T16:31:49Z</dc:date>
    <item>
      <title>Oracle table to file geodatabase</title>
      <link>https://community.esri.com/t5/python-questions/oracle-table-to-file-geodatabase/m-p/546177#M42593</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm a beginner in Python and trying to build a script to perform and extraction from a Oracle database to a file geodatabase with a SQL query. I've been able to etablish the connection to Oracle, select the data with the query, create a new table but I have not been able to successfully output the data to the file Geodatabase.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here the error from the geoprocessing result. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.developpez.net/forums/attachment.php?attachmentid=90158&amp;amp;stc=1&amp;amp;d=1329926530"&gt;&lt;IMG src="http://www.developpez.net/forums/attachment.php?attachmentid=90158&amp;amp;stc=1&amp;amp;d=1329926530" /&gt;&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Voici mon code : &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;#! /usr/bin/env python
#encoding:UTF-8


import cx_Oracle
#import csv
import arcpy
from arcpy import env

# Define workspace
env.workspace = "C:\Temp\Extraction_Toad\Scratch_Toad.gdb"

# Add connections setting
dsn = cx_Oracle.makedsn("XXXX","XXX","X")
orcl = cx_Oracle.connect('XXXXX','XXXXX',dsn)
cursor = orcl.cursor()

# Get the variables
arg1 = arcpy.GetParameterAsText(0)
out_path = arcpy.GetParameterAsText(1)
out_name = arcpy.GetParameterAsText(2)
template = "C:\Temp\Extraction_Toad\Template_vue.dbf"
out_workspace = "C:\Temp\Extraction_Toad\Scratch_Toad.gdb"

# Process the query
sql = arg1
cursor.execute(sql)

rows = cursor.fetchall()

cursor.close()
orcl.close()
 
# Create a new table
arcpy.CreateTable_management(out_path,out_name,template)

# Loading data from the cursor to file g
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyRows_management(row,out_workspace)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for you help&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Feb 2012 17:26:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/oracle-table-to-file-geodatabase/m-p/546177#M42593</guid>
      <dc:creator>Pierre-LucBoivin</dc:creator>
      <dc:date>2012-02-23T17:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: Oracle table to file geodatabase</title>
      <link>https://community.esri.com/t5/python-questions/oracle-table-to-file-geodatabase/m-p/546178#M42594</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;A few things jump out to me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;First, without seeing what is in the sql query it is rather hard to figure out the input side of the algorithm.&amp;nbsp; Also running raw sql from the command line is a big security hole. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Next your output location is a geodatabase, not a table. Change this statement:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;out_workspace = "C:\Temp\Extraction_Toad\Scratch_Toad.gdb"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;to &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;out_workspace = r"C:\Temp\Extraction_Toad\Scratch_Toad.gdb\" + out_name&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;or &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;out_workspace = "C:\\Temp\\Extraction_Toad\\Scratch_Toad.gdb\\" + out_name&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;or &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;out_workspace = "C:/Temp/Extraction_Toad/Scratch_Toad.gdb/" + out_name&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Multiple versions because Python does not deal well with \ as a directory separator.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would also probably wait to close out the Oracle cursor and connection until the end of the script.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Feb 2012 16:31:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/oracle-table-to-file-geodatabase/m-p/546178#M42594</guid>
      <dc:creator>David_JAnderson</dc:creator>
      <dc:date>2012-02-24T16:31:49Z</dc:date>
    </item>
  </channel>
</rss>

