mysql decimal數(shù)據(jù)類型轉(zhuǎn)換的實現(xiàn)
最近在工作遇到數(shù)據(jù)庫中存的數(shù)據(jù)類型是: decimal(14,4)
遇到的問題是:當我使用python 讀取到內(nèi)存中時,總是帶著 decimal字符, 再寫入其它mysql表中時,數(shù)據(jù)類型為int型,導(dǎo)致數(shù)據(jù)入庫不成功.
import pymysql# 創(chuàng)建數(shù)據(jù)庫連接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方法來轉(zhuǎn)換
selectcast(created_time as signed) AS created_time from schma.table
到此這篇關(guān)于mysql decimal數(shù)據(jù)類型轉(zhuǎn)換的實現(xiàn)的文章就介紹到這了,更多相關(guān)mysql decimal數(shù)據(jù)類型轉(zhuǎn)換內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. Oracle數(shù)據(jù)庫刪除表中重復(fù)記錄的常見方法2. 詳解MySQL InnoDB存儲引擎的內(nèi)存管理3. Oracle REGEXP_LIKE模糊查詢用法例子4. Oracle 學習過程中的筆記以及幾個問題5. Oracle listagg去重distinct的三種方式總結(jié)6. sql中的if和else使用及說明7. mybatis 返回Map類型key改為小寫的操作8. 基于mysql的論壇(5)9. SQL Server 2000之日志傳送功能-設(shè)定10. 清除SQL Server數(shù)據(jù)庫日志(ldf文件)的方法匯總
