mysql decimal數(shù)據(jù)類型轉(zhuǎn)換的實現(xiàn)
最近在工作遇到數(shù)據(jù)庫中存的數(shù)據(jù)類型是: decimal(14,4)
遇到的問題是:當我使用python 讀取到內(nèi)存中時,總是帶著 decimal字符, 再寫入其它mysql表中時,數(shù)據(jù)類型為int型,導致數(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. SQL server分頁的四種方法思路詳解(最全面教程)2. MariaDB Spider 數(shù)據(jù)庫分庫分表實踐記錄3. 使用sqlserver官方驅(qū)動包調(diào)用存儲過程遇到的坑及解決方法4. Microsoft Office Access創(chuàng)建一個表的子表的方法5. Sql Server中通過sql命令獲取cpu占用及產(chǎn)生鎖的sql6. 詳解MySQL的Seconds_Behind_Master7. Microsoft Office Access調(diào)整字段位置的方法8. Windows系統(tǒng)徹底卸載SQL Server通用方法(推薦!)9. SQLite 實現(xiàn)if not exist 類似功能的操作10. SQL Server如何通過SQL語句直接操作另一臺服務器上的SQL SERVER的數(shù)據(jù)
