1、 install cx_Oracle library
pip install cx_Oracle
2、 download Oracle Driver file
https://www.oracle.com/database/technologies/instant-client/downloads.html
And extract it to the local directory , Here's an example
D:\oracle_client\instantclient_18_5
3、 operating system ,windows 10
connOracle.py
# encoding=utf-8
import os
import cx_Oracle as cx
# Set up ORACLE Driving position
os.environ['path'] = r'D:\oracle_client\instantclient_18_5'
def oraConn():
try:
# Super management account must be used
conn = cx.connect('system', '*******', 'localhost:1521/orcl')
c = conn.cursor()
sql = 'select count(*) from v$process'
c.execute(sql)
row = c.fetchone()
print(row[0])
c.close()
conn.close()
except Exception as e:
print(e)
if __name__ == '__main__':
oraConn()
select count(*) from v$process -- The current number of database connections
select value from v$parameter where name = 'processes'-- The maximum number of connections allowed by the database
select count(*) from v$session -- Current session The number of connections
select count(*) from v$session where status='ACTIVE' -- Number of concurrent connections