CREATE OR REPLACE PROCEDURE multirowupdate AS
TYPE t_record IS TABLE OF employees%ROWTYPE;
t_record record_t;
BEGIN
UPDATE employees
SET salary = salary + 10
RETURNING first_name, salary INTO record_t;
FOR i IN 1..record_t.count
LOOP
dbms_output.put_line(record_t(i).first_name);
dbms_output.put_line(record_t(i).salary);
END LOOP;
END;
执行后,我收到错误:
Error(11,7): PLS-00201: identifier 'RECORD_T' must be declared
当我明确声明这是声明部分时,为什么我收到此错误。
我在HR模式中使用employees表
答案 0 :(得分:2)
你的声明似乎有些混乱。
您声明了一种t_record类型,但是然后将其用作变量的名称?
我认为你可能想做的是:
create or replace procedure
MultiRowUpdate
as
type t_record is table of employees%rowtype;
-- This is not correct: t_record record_t;
record_t t_record;
begin
update employees
set salary=salary + 10
returning first_name,salary
into record_t;
for I in 1..record_t.count
loop
dbms_output.put_line(record_t(I).first_name);
dbms_output.put_line(record_t(I).salary);
end loop;
end;
希望有所帮助
答案 1 :(得分:1)
变量的正确声明应如下所示:
record_t t_record;
在变量前面加上它的类型。但是这种修正会引发另一个错误:
PLS-00642: local collection types not allowed in SQL statements
这意味着不允许在类型声明中混合使用PL / SQL和SQL上下文。这个问题要解决得更复杂。为避免重复,我不会在此处发布解决方案。相反,请阅读in the answers to this question解释,这似乎与您的需求非常相似。