程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python gets the current number of Oracle connections

編輯:Python

Environmental preparation :

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

Code implementation

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()

  Related query statement

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 

 


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved