且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

预备语句,同时获取预备语句

更新时间:2022-06-17 21:47:44

如果您尝试执行此操作,则将杀死DB(如果拥有DBA,则DBA将杀死您).问题是您要执行的操作是每行向数据库发送一个插入请求.您必须为每一行数据一次又一次地创建和处理所有这些命令.那是昂贵的.

You are going to kill your DB (and if you have a DBA your DBA is going to kill you) if you try to do this. The problem is that what you want to do is send one inser request per line to the database. You have to create and dispose of all these commands over and over again for each line of data. That is expensive.

如果您很难做到这一点,那么什么都不会阻止您在从第一个循环读取的循环中创建第二个预备语句(当然具有不同的名称),但是我强烈建议您这样做.至少要缓冲传入的数据并一次插入几百行.

If you are hard-set on doing it, Nothing prevents you from creating a second prepared statement (with a different name of course) within a loop which reads from the first, but I highly advise against it. At the very least, buffer your incoming data and insert a few hundred rows at a time.