mysql decimal數(shù)據(jù)類型轉(zhuǎn)換的實現(xiàn)
最近在工作遇到數(shù)據(jù)庫中存的數(shù)據(jù)類型是: decimal(14,4)
遇到的問題是:當(dāng)我使用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. MySql分組后隨機獲取每組一條數(shù)據(jù)的操作2. SQLite3 API 編程手冊3. 巧用SQL語言在ACCESS數(shù)據(jù)庫中批量替換內(nèi)容4. Microsoft Office Access用宏調(diào)用VBA的方法5. Oracle災(zāi)難防護的關(guān)鍵技術(shù)6. CentOS安裝和設(shè)置MariaDB的教程7. Microsoft Office Access重新編號的方法8. Mysql入門系列:在MYSQL結(jié)果集上執(zhí)行計算9. Microsoft Office Access創(chuàng)建一個表的子表的方法10. sql server的cube操作符使用詳解
