oracle 游标,与循环运行图连接
我想使用游标通过 Oracle 的 Connect By Prior 循环浏览管理报告链。然后顺序颠倒过来,因此 VP 位于顶部,而我开始的记录位于底部 (A.Corpid)。
顶部有一个游标 C1,它按照特定条件检索 corpid
从该表返回的每个规范名称(假设它有 6 行)我想存储在定义的 TIER1、TIER2、TIER3 变量中。
不知怎的,我不知道如何将单词“TIER”与行号结合起来,
DECLARE
cursor c1 is
select distinct corpid, cn from Mytable where Country ='ITA';
master varchar2(50);
Tier1 varchar2(50);
Tier2 varchar2(50);
Tier3 varchar2(50);
Tier4 varchar2(50);
Tier5 varchar2(50);
Tier6 varchar2(50);
Tier7 varchar2(50);
Tier8 varchar2(50);
Begin
for rec in c1
loop
dbms_output.put_line(rec.cn);
DECLARE
Cursor C2 is
SELECT CN FROM Mytable A CONNECT BY PRIOR A.reportsto=A.corpid
START WITH A.corpid=rec.corpid
order by rownum desc;
Begin
open C2;
for i in 1..8 loop
fetch C2 into master;
dbms_output.put_line(master);
'Tier'||to_char(i)) :=master ;
end loop;
end;
if TIER1 is null then
TIER1:='';
end if;
*/ remmed out until the variable assignments work */
-- update mytable set VP_TIER1=TIER1 where corpid=rec.corpid;
end loop;
end;
Oracle 抱怨“||”
(ORA-06550:第 33 行,第 31 列: PLS-00103:遇到符号“|”当预期出现以下情况之一时: := 。 (@%; )
我也尝试过连接,但这也不起作用
ORA-06550:第 33 行,第 26 列: PLS-00306:调用“CONCAT”时参数数量或类型错误
I want to use a cursor to loop through a management reporting chain using the Connect By Prior from Oracle. The order is then reversed so the VP is at the top and the record i started with is at the bottom (A.Corpid).
there's a cursor C1 on top that retrieves corpid following certain criteria
Each Canonical Name returned from that table (say f.i it has 6 rows) i want to store in defined TIER1,TIER2, TIER3 variables.
Somehow i can't figure out how to combine the word 'TIER' with the row number i
DECLARE
cursor c1 is
select distinct corpid, cn from Mytable where Country ='ITA';
master varchar2(50);
Tier1 varchar2(50);
Tier2 varchar2(50);
Tier3 varchar2(50);
Tier4 varchar2(50);
Tier5 varchar2(50);
Tier6 varchar2(50);
Tier7 varchar2(50);
Tier8 varchar2(50);
Begin
for rec in c1
loop
dbms_output.put_line(rec.cn);
DECLARE
Cursor C2 is
SELECT CN FROM Mytable A CONNECT BY PRIOR A.reportsto=A.corpid
START WITH A.corpid=rec.corpid
order by rownum desc;
Begin
open C2;
for i in 1..8 loop
fetch C2 into master;
dbms_output.put_line(master);
'Tier'||to_char(i)) :=master ;
end loop;
end;
if TIER1 is null then
TIER1:='';
end if;
*/ remmed out until the variable assignments work */
-- update mytable set VP_TIER1=TIER1 where corpid=rec.corpid;
end loop;
end;
Oracle complains about the '||'
(ORA-06550: line 33, column 31:
PLS-00103: Encountered the symbol "|" when expecting one of the following:
:= . ( @ % ;
)
I've tried as well to concat but that didn't work either
ORA-06550: line 33, column 26:
PLS-00306: wrong number or types of arguments in call to 'CONCAT'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的文字和变量的串联不会像您希望的那样计算为变量 TIER1 。尝试使用数组代替:
可能还有一种更基于集合的方法来执行此操作,这将是更可取的,但如果这只是一次性需求,那么这应该可行。
Your concatenation of the literal and variable aren't going to evaluate to the variable TIER1 like you are hoping. Try using arrays instead:
There is also probably a more set-based approach to doing this which would be much preferred, but this should work if it is just a one-time need.