mysql decimal数据类型转换的实现

Frieda ·
更新时间:2024-09-20
· 1435 次阅读

最近在工作遇到数据库中存的数据类型是: decimal(14,4)

遇到的问题是:

当我使用python 读取到内存中时,总是带着 decimal字符, 再写入其它mysql表中时,数据类型为int型,导致数据入库不成功.

import pymysql # 创建数据库连接 con = pymysql.connect() sql = '''select created_time from schma.table LIMIT 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方法来转换

select cast(created_time as signed) AS created_time from schma.table

到此这篇关于mysql decimal数据类型转换的实现的文章就介绍到这了,更多相关mysql decimal数据类型转换内容请搜索软件开发网以前的文章或继续浏览下面的相关文章希望大家以后多多支持软件开发网!

您可能感兴趣的文章:MySQL数据类型DECIMAL用法详解mysql中decimal数据类型小数位填充问题详解深入分析MySQL数据类型 DECIMAL详解MySQL数据类型DECIMAL(N,M)中N和M分别表示的含义MySQL数据类型中DECIMAL的用法实例详解



DECIMAL 类型转换 Mysql

需要 登录 后方可回复, 如果你还没有账号请 注册新账号