登录
sqlplus /nolog
conn username/passwd
登录如果报错,需要在后面添加sid,
conn username/passwd@sid
ps -ef|grep ckpt 查询数据库的实例
python 连接oracle
1. cx_Oracle
conn = cx_Oracle(user,passwd,sid)
cursor = conn.cursor()
cursor.execute(sql)
data = cursor.fetchall()
2. sqlalchemy
from sqlalchemy import create_engine
oracle_url = 'oracle+cx_oracle://user:password@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=host)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=sid)))'
engine = create_engine(oracle_url)
with engine.connect() as conn, conn.begin():
response = conn.execute(sql)
data = response.fetchall()
return data