如何 select 存储过程中的 ID 并立即使用该 ID 和 return 更新某些列?

How to select ids in stored procedure and update some columns using that ids at once and return the ids?

我面临的问题是如何将 select 查询的结果存储在存储过程中的变量中以执行更新,然后 return 变量作为结果。

大致与您用通俗易懂的英语解释的一样;只需将其转换为代码即可。例如:

SQL> create or replace procedure p_test (par_deptno in number, par_var out number
  2  is
  3    l_maxsal number;
  4  begin
  5    -- store result of SELECT into a variable
  6    select max(sal)
  7      into l_maxsal
  8      from emp
  9      where deptno = par_deptno;
 10
 11    -- perform UPDATE
 12    update emp set
 13      sal = l_maxsal
 14      where deptno = par_deptno;
 15
 16    -- return its value
 17    par_var := l_maxsal;
 18  end;
 19  /

Procedure created.

测试:初始table内容:

SQL> select deptno, ename, sal from emp where deptno = 10;

    DEPTNO ENAME             SAL
---------- ---------- ----------
        10 CLARK            2450
        10 KING             5001
        10 MILLER           1300

调用程序;因为它是 returns 一个 OUT 参数,所以你必须声明一个接受它的变量:

SQL> set serveroutput on
SQL> declare
  2    l_var number;
  3  begin
  4    p_test(par_deptno => 10, par_var => l_var);
  5    dbms_output.put_line('Procedure returned ' || l_var);
  6  end;
  7  /
Procedure returned 5001

PL/SQL procedure successfully completed.

结果:

SQL> select deptno, ename, sal from emp where deptno = 10;

    DEPTNO ENAME             SAL
---------- ---------- ----------
        10 CLARK            5001
        10 KING             5001
        10 MILLER           5001

SQL>

创建过程getOrderForMarketBuyExecution(输出响应文本) 开始 设置 @uids := 0; UPDATE test SET processing = true WHERE id IN (SELECT t.id from test WHERE processing = false) AND ( SELECT @uids := CONCAT_WS(',', id, @uids) ); 设置响应= @uids; 结束