我试图从一个包含两列的表中读取 - 客户号码& Directors_name并写入另一个表。挑战在于,单个客户编号与第一个表中的许多董事相关联,最多有10个董事。我将其重新写入另一个表,以便在一行中拥有唯一的客户编号和所有董事。最终表的表结构是Customer No,Director1,Director2,.... Director10。这些表位于Oracle数据库中。
答案 0 :(得分:0)
试试这个,
create or replace function addcolval(input in number) return varchar2 is
colval varchar2(32000);
begin
for c in (select Directors_Name from "your 2nd table" where Customer_No=input) loop
colval := colval||c.Directors_name||',';
end loop;
return rtrim(colval,',');
end;
然后
insert into "your 2nd table"(Customer_No) select distinct Customer_No from "your 1st table";
update "your 2nd table" as t1 set t1.Directors_Name =addcolval(t1.Customer_No);