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. MySQL存储过程例子(包含事务、参数、嵌套调用、游标循环等)2. SQL Script tips for MS SQL Server3. mysql变量用法实例分析【系统变量、用户变量】4. 带你深入了解IBM DB2的通信与连接过程5. SQL Server 2005使用基于行版本控制的隔离级别初探(3) -- SNAPSHOT6. MySQL基础教程3 —— 数据类型之字符串类型7. SQL SERVER的ROWCOUNT关键字8. MySQL/MariaDB 如何实现数据透视表的示例代码9. mysql 大表批量删除大量数据的实现方法10. Mysql入门系列:需要避免的MYSQL客户机程序设计错误