一、oracle
1、用python连接Oracle是总是乱码,最后发现时oracle客户端的字符编码设置不对。
编写的python脚本中需要加入如下几句:
import os
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'
参考来源:https://www.cnblogs.com/chenjianhong/p/4144399.html
2、特殊符号
如果字符中含有&等特殊符号,需要特殊处理;
'kkkkk' || '&' || 'kkkkkk'
3、连接
import cx_Oracle def element(cols,row) elem=dict() for i in range(len(cols)): elem[cols[i]]=row[i] try: db= cx_Oracle.connect(username/passwd@host:port/sevicename) cr=db.cursor() cr.execute(sql) #执行sql rows=cursor.fetchall() #以元组方式返回所有记录,参考:https://www.cnblogs.com/z-x-y/p/9055509.html cols=map(lambda x:x[0],cr.description) #返回该表的每个字段名 result=map(lambda row:elem(cols,row),rows) #返回类似 [{字段名1:字段值1,字段名2:字段值2},{},{}] 的结果 except Exception,e: print 'connect error',e finally: #db.commit() db.close()
db= cx_Oracle.connect(username/passwd@host:port/sevicename) cur=db.cursor() cur.execute(sql.encode("utf-8")) result_list = cur.fetchall() cols = cur.description db.close() col = [i[0] for i in cols] res = [{key: value for key, value in zip(col, i)} for i in result_list]
#返回上面类似的结果
二、redis
import redis con=redis.StricrRedis(host='',port='',db='',password='') print con.get('键') print con.set('键','值') print con.keys('键*')
三、mysql的一些内容
1、pymysql将查询的字段按储存的格式返回:CAST(start_date AS CHAR) AS start_date