gpt4 book ai didi

oracle - 如何将选择结果存储到Oracle过程中的变量中

转载 作者:行者123 更新时间:2023-12-04 05:05:34 24 4
gpt4 key购买 nike

我写了一个简单的程序。我尝试将选择结果存储在变量中。我使用“SELECT INTO”查询,但无法执行此操作。

例子:

DECLARE
v_employeeRecord employee%ROWTYPE;
BEGIN
SELECT * INTO v_employeeRecord
FROM Employee WHERE Salary > 10;
END;

最佳答案

您有几种选择。您可以将该查询转换为游标:

DECLARE
CURSOR v_employeeRecords IS
SELECT * FROM Employee WHERE Salary > 10;
v_employeeRecord employee%ROWTYPE;
BEGIN
FOR v_employeeRecord IN v_employeeRecords LOOP
/* Do something with v_employeeRecord */
END LOOP;
END;

或者,您可以创建一个 TABLE变量:
DECLARE
v_employeeRecord employee%ROWTYPE;
v_employeeRecords IS TABLE OF employee%ROWTYPE;
i BINARY_INTEGER;
BEGIN
SELECT * BULK COLLECT INTO v_employeeRecords
FROM Employee WHERE Salary > 10;

i := v_employeeRecords.FIRST;
WHILE v_employeeRecords.EXISTS(i) LOOP
v_employeeRecord := v_employeeRecords(i);
/* Do something with v_employeeRecord */
i := v_employeeRecords.NEXT(i);
END;
END;

我没有在Oracle中尝试过这些示例,因此您可能会遇到编译器错误...

关于oracle - 如何将选择结果存储到Oracle过程中的变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1347091/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com