GDAL – Error Exporting Data from Oracle to SHP using ogr2ogr

gdalogr2ogroracle-spatialshapefile

I have an oracle table which I would like to query/make a selection. I would then like to export the selection to a shp file.

I'm using gdal and ogr2ogr.

Following the guidelines here and here I have come up with the following:

ogr2ogr -f "ESRI Shapefile" c:/Testing/Scratch/GDAL/symbol.shp OCI:dbusername/db_password@tns_name -sql "SELECT* FROM tablename where VERSION_DATE >= CURRENT_DATE -8" -progress

I then get the following error: "Unable to open datasource 'OCI:dbusername/db_password@tns_name' with the following drivers"

There is then a long list of drivers including "ESRI Shapefile".

I have now added " after OCI as suggested.

ogr2ogr -f "ESRI Shapefile" c:/Testing/Scratch/GDAL/symbol.shp OCI:"dbusername/db_password@tns_name -sql "SELECT* FROM tablename where VERSION_DATE >= CURRENT_DATE -8" -progress

I no longer get the errors about it being unable to open the datasource with the drivers. I now just get an "Access in denied".

I have a working connection to the database in ArcGIS using the same username & password.
Does gdal generate its own user?

Best Answer

No, gdal doesn't generate any user.

You should find '-> "OCI" (read/write)' in the Supported Formats list if "OCI driver" is installed/configured properly. At this point the following syntax (you have to customize a little bit) should work:

ogr2ogr <srs> -f "ESRI Shapefile" /favourite/path/test.shp OCI:"<oracle user>/<oracle password>@(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = <hostname>)(PORT = <port number>)))(CONNECT_DATA = (SID =<sid name>))):<oracle schema>.<oracle table>"