Using “IN” in a WHERE clause where the number of items in the set is very large

前端 未结 10 2402
梦毁少年i
梦毁少年i 2021-02-13 05:30

I have a situation where I need to do an update on a very large set of rows that I can only identify by their ID (since the target records are selected by the user and have noth

10条回答
  •  别那么骄傲
    2021-02-13 06:15

    If you were on Oracle, I'd recommend using table functions, similar to Marc Gravell's post.

    -- first create a user-defined collection type, a table of numbers
    create or replace type tbl_foo as table of number;
    
    declare
      temp_foo tbl_foo;
    begin
      -- this could be passed in as a parameter, for simplicity I am hardcoding it
      temp_foo := tbl_foo(7369, 7788);
    
      -- here I use a table function to treat my temp_foo variable as a table, 
      -- and I join it to the emp table as an alternative to a massive "IN" clause
      select e.*
        from emp e,
             table(temp_foo) foo
       where e.empno = foo.column_value;
    end;
    

提交回复
热议问题