【发布时间】:2022-11-16 22:05:03
【问题描述】:
我有这个表包含主键和外键作为对它的引用 如图所示
表名 = ACV_FOLDERS_INFO
列 = ID --------------------------PK
所有者
姓名
ALT_NAME
类别
描述
图标
已删除
FDR_PUBLIC
INHERIT_PARENT_ACL
评论
FIO_ID ---------------------- FK 引用 PK(当 FIO_ID 为 null 时,表示该记录是主文件夹)
OTHER_ID
年
参考文献
像这样构建表以创建一个 TREE
我正在尝试根据 ID 引用的 FIO_ID 复制整行(文件夹)及其子文件夹,但我仍然遇到问题
/*** lasted code .
declare
l_ID number;
begin
for i in (select case
when connect_by_isleaf = 1 then
0
when level = 1 then
1
else
-1
end as status,
level,
f.*
from acv_folders_info f,
(SELECT *
FROM acv_folder_acl
WHERE privilege = 'B'
and ERD_ID = 483) a
where F.ID = A.FIO_ID
and acv_get_validation.have_upd(p_erd_id => 483,
p_fio_id => a.FIO_ID) = 'Y'
and A.ERD_ID = 483
and year = 2020
start with F."FIO_ID" is null
connect by prior f."ID" = F."FIO_ID"
order by status desc, level) loop
begin
insert into acv_folder_info x
(x.ID,
x.OWNER,
x.NAME,
x.ALT_NAME,
x.CATEGORY,
x.DESCRIPTION,
x.ICON,
x.DELETED,
x.FDR_PUBLIC,
x.INHERIT_PARENT_ACL,
x.REMARKS,
x.FIO_ID,
x.OTHER_ID,
x.YEAR,)
values
(null,
483,
i.name || ' - 2020 / 2021',
i.alt_name || ' - 2020 / 2021',
i.category,
i.description,
i.icon,
i.deleted,
i.fdr_public,
i.inherit_parent_acl,
i.remarks,
nvl(i.ID, l_ID),
i.other_id,
2020);
returning id
into l_ID;
exception
when others then
dbms_output.put_line(i.id || ' - ' || l_ID || sqlerrm);
end loop;
end;
【问题讨论】:
-
“我还是有问题” 但是,你还没有告诉我们问题是什么。
-
您似乎缺少
END;(在END LOOP;之前)来终止循环内的 PL/SQL 块。INSERT的列列表中多了一个逗号。 -
我无法获得新 ID 以将其作为 FK 外键的参考 您可以查看图像以查看数据排列
-
您总是将
null插入到id列中,然后将该null值返回到l_idpl/sql 变量中。目前还不清楚您如何期望该值是null以外的任何值。 -
男人来吧,(ID 为空,但它在触发器 BIS/BIR 上工作,如果它为空,它将调用一个 sequence.nextval)-循环是基于主文件夹到子文件夹到子文件夹到子文件夹排序我得到主文件夹 id 并插入到下一级的外部并获取下一级 id 并插入到 fio_id