【发布时间】:2017-05-30 20:45:20
【问题描述】:
我的表有一个定义的列 ID。 虽然相同的查询独立运行良好,但是当我尝试在游标中声明它时,它显示无效列。
declare
type PA_1 is record (PI number);
calc number;
row_container PA_1;
begin
for row_container in
(
select distict t1.pi , t2.id
from table1 t1, table2 t2
where t1.Pi=t2.pi
);
Loop
select calculation to calc
from table1 t1
where t1.pi=row_container.pi and t2.id=row_container.id;
end loop;
commit;
end;
否则内部查询运行良好。请帮忙
【问题讨论】:
-
declare type PA_1 is record (PI number); calc number; row_container PA_1; begin for row_container in (select distict t1.pi , t2.id from table1 t1, table2 t2 where t1.Pi=t2.pi); Loop select calculation to calc from table1 t1 where t1.pi=row_container.pi and t2.id=row_container.id; end loop; commit; end;否则内部查询运行良好。请帮忙 -
除了我在回答中显示的语法错误之外,您不应再使用这种旧的连接语法。它在 25 年前就被淘汰了。请改用
from table1 t1 inner join table2 t2 on t1.Pi = t2.pi。 -
顺便说一句,这个代码块应该做什么?许多任务可以用纯 SQL 编写,不需要 PL/SQL。
-
嗨..请原谅我的语法错误..匆忙提交..代码块是一个巨大表更新的一部分..我想更新列“calc”使用我从加入中获得的值。虽然我可以通过将其声明为同义词来消除无列的“id”问题。我得到的“calc”值太多。 id 是唯一的列。我仍然得到太多的价值
-
但是,如果这不是您遇到问题的实际代码,那么发布它是没有意义的。
标签: plsql oracle10g oracle-sqldeveloper