HomeНаука и техникаRelated VideosMore From: Subhroneel Ganguly

How to connect to Oracle database using Python in Windows.

61 ratings | 36361 views
How to connect to Oracle database using Python in Windows. Program will connect to Oracle 12c database and retrieve data from a table. Link to Oracle 12c client library : https://pypi.python.org/pypi/cx_Oracle/5.1.3 Just chose your version matching your installed python
Html code for embedding videos on your blog
Text Comments (38)
Paul Schuster (1 month ago)
Your audio is horribly overdriven. Not understandable without ear pain
Bishnupad tripathy (1 year ago)
without instant client how it is working
Subhroneel Ganguly (1 year ago)
+Bishnupad tripathy Instant client is necessary, it is not mentioned in the video.
Siddharth baranwal (1 year ago)
am unable to insert date into table by using variable in python 3.6.1. If i pass the value hard-coded, it is working, but the same is not working if i give it a variable name. Below line of code is working : **cursor.execute("INSERT INTO telm VALUES('rahul')")** But if i pass as variable : *cursor.execute("INSERT INTO telm VALUES(fname)")...giving error ORA-00984: column not allowed here*
Subhroneel Ganguly (1 year ago)
+Siddharth baranwal if fname is you local variable you must put it in a concatenated format
Subhroneel Ganguly (1 year ago)
+Siddharth baranwal don't you think you are using fname as a string inside query. Try concatenat string with fname.
Kuladip Sahu (1 year ago)
Hi, I have used Python 3.6.1 and Oracle 11g in Windows 7(64 bit). Now I want to connect Python to Oracle database. I have done the following - 1. Download Oracle instant Client instantclient-basic-windows.x64-12.2.0.1.0.zip 2. Unzip it and Set the path in Environment Variable -> System Variable -> path -> c:\<path> -> Ok 3. Download cx_Oracle-5.3-11g.win-amd64-py3.6-2.exe and install It But still I am facing ImportError: DLL load failed: The specified module could not be found. Please let me know the solution. Thanks !!
Bec AR (1 year ago)
the below steps worked for me 1. Download Oracle instant Client "instantclient-basic-windows.x64-11.2.0.4.0.zip" 2. Unzip it and Set the path in Environment Variable -> System Variable -> path -> c:\<path> -> Ok 3. Insatall CX "python -m pip install cx_Oracle --pre"
Kuladip Sahu (1 year ago)
Hi Subhroneel, Thanks for the reply. My python 3.6.1 version is 64 bit. Oracle 11.2.0.4 also 64 bit. I have done the following - 1. Download Oracle instant Client "instantclient-basic-windows.x64-11.2.0.4.0.zip" 2. Unzip it and Set the path in Environment Variable -> System Variable -> path -> c:\<path> -> Ok 3. Download "cx_Oracle-5.3-11g.win-amd64-py3.6-2.exe" and install It But still I am facing ImportError: DLL load failed: The specified module could not be found. Please let me know the solution.
Subhroneel Ganguly (1 year ago)
+Kuladip Sahu It seems you are using wrong bit version. May be you are using 64 bit windows and installed 32 bit cx_Oracle or vise versa.
Subhrasish Mallik (2 years ago)
I'm able to connect to Oracle using cx_oracle. I want to know if there is any way to connect using pyodbc ??
Nimit Shah (2 years ago)
hi, i'm getting the below error: cx_Oracle.DatabaseError: ORA-12154: TNS:could not resolve the connect identifier specified i have entered ('user'/'password'@'hostname':'port'/'servicename') hwoever if i try the same in java it works. any idea what can be the error? m using it on win32 machine on eclipse ide.
Subhroneel Ganguly (2 years ago)
ur wc
Nimit Shah (2 years ago)
+Subhroneel Ganguly it worked, just that i declared it under makedsn and used the command .replace('SID','SERVICE_NAME'). thanks
Subhroneel Ganguly (2 years ago)
No, it works with direct connection with ipaddress and sid,
Nimit Shah (2 years ago)
So service name won't work at all? I have put all in one quotes but don't have the Sid.
Subhroneel Ganguly (2 years ago)
+Nimit Shah con = cx_Oracle.connect('username/[email protected][ipaddress or hostname]/SID'). Nor service name, SID and put all connectionstring under one quote.
Dhanraj V (2 years ago)
Hi, After downloading the cx_Oracle file, I installed. when i am trying to import, i am getting below error ImportError: DLL load failed: %1 is not a valid Win32 application.
Dhanraj V (2 years ago)
+Subhroneel Ganguly its showing win32 but my OS is 64bit only.. i checked the properties as well. it is 64bit OS
Subhroneel Ganguly (2 years ago)
+Dhanraj V why are you using a 64 bit sw in 32 nit os.
Subhroneel Ganguly (2 years ago)
+Dhanraj V why are you using a 64 bit sw in 32 nit os.
Dhanraj V (2 years ago)
+Subhroneel Ganguly here is the version which i am using, Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 20:40:30) [MSC v.1500 64 bit (AMD64)] on win32 could you please suggest me which cx_Oracle i need to download..!!
Subhroneel Ganguly (2 years ago)
+Dhanraj V because you are nit installing the correct version. Version should match php version and windows bit version 32 / 64 bit.
Pretty Printed (2 years ago)
Thanks for this. I've had trouble installing Oracle_cx in the past. Are there alternative methods for connecting to an Oracle database?
Pretty Printed (2 years ago)
Thanks. I'll try that.
Subhroneel Ganguly (2 years ago)
+Pretty Printed It's cx_Oracle. And the problem is not with cx_Oracle, the problem is with oracle instant client. Install the oracle instant client and set it's path in environment variable. (Path) and then install cx_Oracle.
Baptiste Cochin (3 years ago)
Hi, Thank you for this tutorial. I don't succeed in connecting to my Oracle DB 10.2.0.5 64bits with python using your method. Error message : Unable to acquire Oracle environment handle Do you know how to fix this ?
Baptiste Cochin (3 years ago)
+Subhroneel Ganguly I thank you for this reply. I work on windows. Indeed, I was trying with a 32 bits version of cx_oracle. I finally succed in installing the 64bits version and it works well. Thanks again
Subhroneel Ganguly (3 years ago)
+Baptiste Cochin You have not mentioned the OS you using. Assuming that you are using windows, you can do one thing. Goto My Computer -> Properties -> Advanced -> Environment Variable -> and set oracle home path and network\admin path and try connecting again. If this does not solve the problem then check another thing i.e. make sure your cx_oracle, python is 64 bit version. And the third problem can arise is that cx_oracle for 10g version is not available right now. So if you are using cx_oracle for higher oracle version that might be a problem. So without jumping into conclusion just try the above two solution. Path for cx_oracle download - https://pypi.python.org/pypi/cx_Oracle/5.2
Vlad Bilenko (3 years ago)
Thanks so much for the video. I spent bunch of time on research as how to connect to Oracle using Python with no success and your video solved the problem withing 3 minutes! Thanks again! :-)
Subhroneel Ganguly (3 years ago)
+Vlad Bilenko It's my pleasure. I need more suggestion about what type of tutorial you want to view. Please suggest.
Taha Kazi (3 years ago)
would this work for mac, as well?
Taha Kazi (3 years ago)
Great, thanks!!
Subhroneel Ganguly (3 years ago)
+Taha Kazi Yes it should work but not as cool as it is in windows. You need to download oracle instant client and cx_Oracle source package and configure it, may be I will publish one tutorial on youtube on this later , but till then you can try this guide.http://joelvasallo.com/?p=276
Subhroneel Ganguly (3 years ago)
Subhroneel Ganguly (3 years ago)
Subhroneel Ganguly (3 years ago)
Subhroneel Ganguly (4 years ago)

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.