1.从Oracle中读取数据
1 import pandas as pd 2 from sqlalchemy import create_engine 3 import os 4 os.environ["NLS_LANG"] = "GERMAN_GERMANY.UTF8" #解决中文乱码 5 conn_string=‘oracle+cx_oracle://用户名:密码@hostIP:端口号/数据库名‘ 6 engine = create_engine(conn_string,echo=True) 7 data=pd.read_sql(sql , con = engine)
2. 向Oracle中写数据
1 from sqlalchemy import create_engine 2 import pandas as pd 3 import os 4 os.environ[‘NLS_LANG‘] = ‘SIMPLIFIED CHINESE_CHINA.UTF8‘ 5 conn_string=‘oracle+cx_oracle://用户名:密码@IP:端口号/数据库名字‘ 6 engine = create_engine(conn_string, echo=True,encoding=‘utf8‘) 7 data=pd.Dataframe({‘name‘:[‘lily‘]}) 8 data.to_sql(dbName, con=engine, if_exists=‘replace‘) 9 10 sql="SELECT * FROM ISC_USER" 11 d=engine.execute(sql).fetchmany(1) #查看数据表 12 print(d) 13 14 sql="delete from table_name" 15 engine.execute(sql) # 删除指定表 16
3. 解决中文乱码问题
import os os.environ["NLS_LANG"] = "GERMAN_GERMANY.UTF8" #解决中文乱码
原文地址:https://www.cnblogs.com/havelucky/p/12530050.html
时间: 2024-11-08 19:10:31