国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

mysql decimal數(shù)據(jù)類型轉(zhuǎn)換的實現(xiàn)

瀏覽:3日期:2023-10-05 18:02:46

最近在工作遇到數(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)文章:
主站蜘蛛池模板: 苍溪县| 昭觉县| 闽清县| 永吉县| 长寿区| 黄石市| 札达县| 女性| 石首市| 界首市| 兴安县| 土默特右旗| 齐河县| 泰兴市| 客服| 威海市| 莒南县| 肥城市| 泗阳县| 赤壁市| 合阳县| 抚远县| 和平区| 白山市| 平武县| 宜章县| 康保县| 恩施市| 内江市| 弥勒县| 栾川县| 黄浦区| 华亭县| 巩义市| 青岛市| 谢通门县| 梧州市| 连州市| 洞口县| 昌都县| 昌图县|