python数据库教程

2023年 8月 12日 83.3k 0

import dbi, odbc # ODBC modulesimport time # standard time module

dbc = odbc.odbc( # open a database connection 'sample/monty/spam' # 'datasource/user/password' )crsr = dbc.cursor() # create a cursorcrsr.execute( # execute some SQL """ SELECT country_id, name, insert_change_date FROM country ORDER BY name """ )print 'Column descriptions:' # show column descriptionsfor col in crsr.description: print ' ', colresult = crsr.fetchall() # fetch the results all at onceprint 'First result row: ', result[0] # show first result rowprint 'Date conversions:' # play with dbiDate objectdate = result[0][-1]fmt = ' %-25s%-20s'print fmt % ('standard string:', str(date))print fmt % ('seconds since epoch:', float(date))timeTuple = time.localtime(date)print fmt % ('time tuple:', timeTuple)print fmt % ('user defined:', time.strftime('%d %B %Y', timeTuple))-------------------------------output--------------------------------

Column descriptions: ('country_id', 'NUMBER', 12, 10, 10, 0, 0) ('name', 'STRING', 45, 45, 0, 0, 0) ('insert_change_date', 'DATE', 19, 19, 0, 0, 1)

First result row: (24L, 'ARGENTINA', )

Date conversions: standard string: Fri Dec 19 01:51:53 1997 seconds since epoch: 882517913.0 time tuple: (1997, 12, 19, 1, 51, 53, 4, 353, 0) user defined: 19 December 1997

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论