mysql decimal數據類型轉換的實現
最近在工作遇到數據庫中存的數據類型是: decimal(14,4)
遇到的問題是:當我使用python 讀取到內存中時,總是帶著 decimal字符, 再寫入其它mysql表中時,數據類型為int型,導致數據入庫不成功.
import pymysql# 創建數據庫連接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方法來轉換
selectcast(created_time as signed) AS created_time from schma.table
到此這篇關于mysql decimal數據類型轉換的實現的文章就介紹到這了,更多相關mysql decimal數據類型轉換內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!
相關文章:
1. Windwos下MySQL 64位壓縮包的安裝方法學習記錄2. mysql-bin.000001文件的來源及處理方法3. Access數據庫安全的幾個問題4. mysql命令行客戶端結果分頁瀏覽5. DB2 V9.5工作負載管理之閾值(THRESHOLD)6. 數據庫相關的幾個技能:ACCESS轉SQL7. mysql啟動時報錯 ERROR! Manager of pid-file quit without8. MySQL收歸Oracle 開源數據庫或將很受傷9. SQL Server EXEC和sp_executesql的區別10. MongoDB啟動報錯 28663 Cannot start server

網公網安備