补充:小心设置cursor_sharing=force参数

转载自:http://www.itpub.net/351520,2.html
摘自:expert one-on-one oracle  (P554)
設置cussor_sharing=force之後,會有以下的情況:
• Optimizer related issues – CURSOR_SHARING will remove all character string
and numeric constants from the query; the optimizer will have less information to
work with. This may very well result in different query plans.
• Query output related issues – The lengths of columns that your query fetches will
unexpectedly change. Queries that used to return a VARCHAR2(5) and a
NUMBER(2), might start returning a VARCHAR2(30) and a NUMBER(5). The
actual size of the data returned wonʹt change, but the application will be told the
potential for a 30 byte column is there – reports and other related applications may
be affected.
• Query plans are harder to evaluate – This is due to the fact that EXPLAIN PLAN
will ʹseeʹ a different query than the database does. This makes query tuning more
difficult. Features like AUTOTRACE in SQL*PLUS are unreliable with
CURSOR_SHARING.




来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/267265/viewspace-82784/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/267265/viewspace-82784/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在python里mysql重构这段代码import sqlite3 class TeacherDatabase: def __init__(self): # 连接数据库 self.conn = sqlite3.connect('teacher.db') # 获取游标 self.cursor = self.conn.cursor() # 创建表 self.cursor.execute(''' CREATE TABLE IF NOT EXISTS scetc_teacher ( teacher_id VARCHAR(32) PRIMARY KEY, teacher_name VARCHAR(16), teacher_profession VARCHAR(64), teacher_tech VARCHAR(64), teacher_post VARCHAR(32) ); ''') self.conn.commit() def add_teacher(self): # 从控制台输入教师信息 teacher_id = input('请输入工号:') teacher_name = input('请输入姓名:') teacher_profession = input('请输入从事专业:') teacher_tech = input('请输入职称:') teacher_post = input('请输入职位:') # 判断工号是否已存在 self.cursor.execute('SELECT * FROM scetc_teacher WHERE teacher_id=?', (teacher_id,)) if self.cursor.fetchone(): print('该工号已存在,请重新输入!') return # 将教师信息写入数据库 self.cursor.execute('INSERT INTO scetc_teacher VALUES (?, ?, ?, ?, ?)', (teacher_id, teacher_name, teacher_profession, teacher_tech, teacher_post)) self.conn.commit() print('教师信息添加成功!') def query_teacher(self): # 查询所有教师信息并在控制台打印显示 self.cursor.execute('SELECT * FROM scetc_teacher') teachers = self.cursor.fetchall() if not teachers: print('暂无教师信息!') else: for teacher in teachers: print('工号:%s,姓名:%s,从事专业:%s,职称:%s,职位:%s' % teacher) def __del__(self): # 关闭连接 self.cursor.close() self.conn.close() if __name__ == '__main__': db = TeacherDatabase() db.add_teacher() db.query_teacher()
05-24
可以使用 Python 中的 PyMySQL 模块来重构这段代码,如下所示: ```python import pymysql class TeacherDatabase: def __init__(self): # 连接数据库 self.conn = pymysql.connect( host='localhost', user='username', password='password', db='teacher' ) # 获取游标 self.cursor = self.conn.cursor() # 创建表 self.cursor.execute(''' CREATE TABLE IF NOT EXISTS scetc_teacher ( teacher_id VARCHAR(32) PRIMARY KEY, teacher_name VARCHAR(16), teacher_profession VARCHAR(64), teacher_tech VARCHAR(64), teacher_post VARCHAR(32) ); ''') self.conn.commit() def add_teacher(self): # 从控制台输入教师信息 teacher_id = input('请输入工号:') teacher_name = input('请输入姓名:') teacher_profession = input('请输入从事专业:') teacher_tech = input('请输入职称:') teacher_post = input('请输入职位:') # 判断工号是否已存在 self.cursor.execute('SELECT * FROM scetc_teacher WHERE teacher_id=%s', (teacher_id,)) if self.cursor.fetchone(): print('该工号已存在,请重新输入!') return # 将教师信息写入数据库 self.cursor.execute('INSERT INTO scetc_teacher VALUES (%s, %s, %s, %s, %s)', (teacher_id, teacher_name, teacher_profession, teacher_tech, teacher_post)) self.conn.commit() print('教师信息添加成功!') def query_teacher(self): # 查询所有教师信息并在控制台打印显示 self.cursor.execute('SELECT * FROM scetc_teacher') teachers = self.cursor.fetchall() if not teachers: print('暂无教师信息!') else: for teacher in teachers: print('工号:%s,姓名:%s,从事专业:%s,职称:%s,职位:%s' % teacher) def __del__(self): # 关闭连接 self.cursor.close() self.conn.close() if __name__ == '__main__': db = TeacherDatabase() db.add_teacher() db.query_teacher() ``` 这里我们使用了 PyMySQL 来连接 MySQL 数据库,对于表的创建和数据的操作与原来的代码基本相同。只需要修改连接数据库的方式和 SQL 语句中的占位符即可。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值