mysql decimal數(shù)據(jù)類(lèi)型轉(zhuǎn)換的實(shí)現(xiàn)
最近在工作遇到數(shù)據(jù)庫(kù)中存的數(shù)據(jù)類(lèi)型是: decimal(14,4)
遇到的問(wèn)題是:當(dāng)我使用python 讀取到內(nèi)存中時(shí),總是帶著 decimal字符, 再寫(xiě)入其它mysql表中時(shí),數(shù)據(jù)類(lèi)型為int型,導(dǎo)致數(shù)據(jù)入庫(kù)不成功.
import pymysql# 創(chuàng)建數(shù)據(jù)庫(kù)連接con = pymysql.connect()sql = ’’’selectcreated_timefrom schma.tableLIMIT 10’’’try: cur = con.cursor(cursor=pymysql.cursors.DictCursor) cur.execute(sql)except Exception as e: print(e)else: data = cur.fetchall()finally: cur.close() con.close()for d in data: created_time = d.get(’created_time’) print(created_time)解決方案:
使用mysql的cast方法來(lái)轉(zhuǎn)換
selectcast(created_time as signed) AS created_time from schma.table
到此這篇關(guān)于mysql decimal數(shù)據(jù)類(lèi)型轉(zhuǎn)換的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)mysql decimal數(shù)據(jù)類(lèi)型轉(zhuǎn)換內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. MySQL插入數(shù)據(jù)時(shí),如果記錄不存在則insert,如果存在則update2. 數(shù)據(jù)庫(kù)Oracle9i的企業(yè)管理器簡(jiǎn)介3. 如何監(jiān)控Oracle索引的使用完全解析4. VS自帶的SQL server修改密碼并連接使用5. Windwos下MySQL 64位壓縮包的安裝方法學(xué)習(xí)記錄6. 用 SQL 查詢(xún) DB2 XML 數(shù)據(jù)(1)7. Mysql故障排除:Starting MySQL. ERROR! Manager of pid-file quit without updating file8. Windows下不能啟動(dòng)mysql服務(wù)--錯(cuò)誤總結(jié)9. MySQL存儲(chǔ)過(guò)程in、out和inout參數(shù)示例和總結(jié)10. DB2數(shù)據(jù)庫(kù)為單個(gè)會(huì)話(huà)鎖定技巧
