python 插入日期數(shù)據(jù)到Oracle實(shí)例
啥也不說了,還是看代碼吧!
[root@yyjk DATABASE]# cat DBI.py # -*- coding: utf-8 -*- import cx_Oracle import time import datetime class 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 #獲取當(dāng)前時(shí)間 time_now = int(time.time()) #轉(zhuǎn)換成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 插入時(shí)間到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)}
補(bǔ)充拓展:python 插入uuid 和 時(shí)間字段 到oracle數(shù)據(jù)庫(kù)中
看代碼:
import sys import getConnection import datetime import uuid import os os.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() # 獲取數(shù)據(jù)連接 , 這是我自己封裝的單獨(dú)獲取數(shù)據(jù)庫(kù)鏈接的py文件 cursor = conn.cursor() # 獲取游標(biāo) 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 e conn.commit() # 這里一定要commit才行,要不然數(shù)據(jù)是不會(huì)插入的 cursor.close() conn.close()
以上這篇python 插入日期數(shù)據(jù)到Oracle實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- python從Oracle讀取數(shù)據(jù)生成圖表
- python安裝cx_Oracle和wxPython的方法
- python針對(duì)Oracle常見查詢操作實(shí)例分析
- python實(shí)現(xiàn)Oracle查詢分組的方法示例
- 基于python連接oracle導(dǎo)并出數(shù)據(jù)文件
- Python連接Oracle之環(huán)境配置、實(shí)例代碼及報(bào)錯(cuò)解決方法詳解
- python實(shí)現(xiàn)自動(dòng)化報(bào)表功能(Oracle/plsql/Excel/多線程)
- 解決python3捕獲cx_oracle拋出的異常錯(cuò)誤問題
- Python3連接SQLServer、Oracle、MySql的方法
- Python讀寫及備份oracle數(shù)據(jù)庫(kù)操作示例
- Python使用cx_Oracle模塊操作Oracle數(shù)據(jù)庫(kù)詳解
- 用python對(duì)oracle進(jìn)行簡(jiǎn)單性能測(cè)試
相關(guān)文章
python通過Matplotlib繪制常見的幾種圖形(推薦)
這篇文章主要介紹了使用matplotlib對(duì)幾種常見的圖形進(jìn)行繪制方法的相關(guān)資料,需要的朋友可以參考下2021-08-08一文詳細(xì)介紹Python中的OrderedDict對(duì)象
OrderedDict是Python標(biāo)準(zhǔn)庫(kù)collections模塊的一部分,下面這篇文章主要給大家介紹了關(guān)于Python中OrderedDict對(duì)象的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-08-08python中django框架通過正則搜索頁面上email地址的方法
這篇文章主要介紹了python中django框架通過正則搜索頁面上email地址的方法,涉及django框架及正則表達(dá)式的使用技巧,需要的朋友可以參考下2015-03-03解決使用PyCharm時(shí)無法啟動(dòng)控制臺(tái)的問題
今天小編就為大家分享一篇解決使用PyCharm時(shí)無法啟動(dòng)控制臺(tái)的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-01-01Python使用os.listdir()和os.walk()獲取文件路徑與文件下所有目錄的方法
今天小編就為大家分享一篇關(guān)于Python使用os.listdir()和os.walk()獲取文件路徑與文件下所有目錄的方法,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-04-04python批量從es取數(shù)據(jù)的方法(文檔數(shù)超過10000)
今天小編就為大家分享一篇python批量從es取數(shù)據(jù)的方法(文檔數(shù)超過10000),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-12-12對(duì)django 2.x版本中models.ForeignKey()外鍵說明介紹
這篇文章主要介紹了對(duì)django 2.x版本中models.ForeignKey()外鍵說明介紹,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-03-03