| 关键词: 语句 变量 如果 方式 tbname col nbsp where SQL 秒钟 |
尽量使用绑定变量的方式执行动态的SQL语句,减少SQL语句预编译次数,例如在拼凑SQL语句时,将语句书写为下面的方式: - "select col1, col2 from tbname where col1=? and col3=?" - "insert into tbname values(?,?,?)" - "update tbname set col1=? where col2=?" - "delete from tbname where col3=?" 如果使用CLI编程,请使用SQLBindParameter()函数绑定变量;如果使用SQL/C,请使用execute s1 using <变量1>, <变量2>。 这种编程方式对性能十分重要,例如我们在存储过程stored procedure中往一个数据表中插入数据,如果使用绑定变量的insert语句,可以在一秒钟插入5000条记录;如果使用非绑定变量的方式,只能在一秒钟插入不到150条记录。 |
|
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系
[邮箱地址] 删除
|