Cursor in procedure returning more values than query

前端 未结 2 1901
被撕碎了的回忆
被撕碎了的回忆 2020-12-12 08:25

I am using a simple cursor in a procedure that receives a couple of parameters. I then make a cursor on a select query with a where clause with multiple conditions, which ar

2条回答
  •  既然无缘
    2020-12-12 08:48

    In addition to what Alex has said (and I can't second his advice to distinguish variable names from column names enough!), why are you using a cursor for loop to do the insert?

    You could just do your insert in one SQL statement, eg:

    insert into your_table (col1, col2, ...)
    select col1, col2, ...
    from   your_table
    where  ...
    

    That will perform much better than going through the whole dataset and inserting each row one at a time. When it comes to databases, think set-based as much as you can, not procedurally!

提交回复
热议问题