国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

python 插入日期數據到Oracle實例

瀏覽:46日期:2022-08-04 16:18:48

啥也不說了,還是看代碼吧!

[root@yyjk DATABASE]# cat DBI.py# -*- coding: utf-8 -*- import cx_Oracle import timeimport datetimeclass DBI (object): def LoadDB(self,a,b): print self conn = cx_Oracle.connect(’tlcbuser/tlcbuser@1.1.1.1/tlyy’) cursor = conn.cursor() #coding:UTF-8 #獲取當前時間 time_now = int(time.time()) #轉換成localtime #time_local = time.localtime(time_now) #print time_local #dt = time.strftime('%Y-%m-%d %H:%M:%S',time_local) dt=datetime.datetime.now() print dt param={’stime’:dt,’message’:a,’phone’:b} print param; cursor.execute(’insert into tlcb_python_sms values(:stime,:message,:phone)’,param) conn.commit() cursor.close python 插入時間到oracle SQL> desc tlcb_python_sms Name Null? Type ----------------------------------------- -------- ---------------------------- STIME DATE MESSAGE VARCHAR2(1000) PHONE VARCHAR2(20) [root@yyjk flask]# python test.py lib.Mojo.Client<lib.Mojo.Client.New object at 0x7f080e371050>2017-11-10 11:37:40.173295{’phone’: ’222’, ’message’: ’111’, ’stime’: datetime.datetime(2017, 11, 10, 11, 37, 40, 173295)}

補充拓展:python 插入uuid 和 時間字段 到oracle數據庫中

看代碼:

import sysimport getConnectionimport datetimeimport uuidimport osos.environ[’NLS_LANG’] = ’SIMPLIFIED CHINESE_CHINA.UTF8’entId=str(uuid.uuid1()).replace('-','')lastDate=datetime.datetime.now().strftime(’%Y-%m-%d %H:%M:%S’)conn = getConnection.getConnOracle114() # 獲取數據連接 , 這是我自己封裝的單獨獲取數據庫鏈接的py文件cursor = conn.cursor() # 獲取游標try: cursor.execute('insert into cp_entinfo(id,last_date) values (’'+entId+'’,to_timestamp(’'+lastDate+'’,’yyyy-mm-dd hh24:mi:ss:ff’))')except Exception, e: print econn.commit() # 這里一定要commit才行,要不然數據是不會插入的cursor.close()conn.close()

以上這篇python 插入日期數據到Oracle實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 合阳县| 平武县| 义乌市| 大埔县| 宁河县| 芷江| 新郑市| 芮城县| 寻甸| 商洛市| 达尔| 鱼台县| 盐边县| 连南| 德惠市| 罗源县| 平和县| 砀山县| 柳河县| 苍溪县| 玉山县| 桂东县| 崇明县| 仪陇县| 饶河县| 三江| 恩施市| 通山县| 陕西省| 浏阳市| 玛曲县| 本溪市| 怀远县| 大渡口区| 延边| 彰化县| 喀喇沁旗| 宁阳县| 南京市| 格尔木市| 西贡区|