Oracle 使用PL/SQL从一个表中读取并重新写入另一个具有不同结构的表

Oracle 使用PL/SQL从一个表中读取并重新写入另一个具有不同结构的表,oracle,Oracle,我试图从一个有两列Customer No&Directors\u name的表中读取数据,然后写入另一个表。挑战在于,单个客户编号与第一个表中的多个控制器绑定,最多10个控制器。我将把它重新写入另一个表中,以便在一行中有唯一的客户编号和所有董事。最后一个表的表结构是Customer No、Director1、Director2、…Director10。这些表位于Oracle数据库中 试试这个 create or replace function addcolval(input in number

我试图从一个有两列Customer No&Directors\u name的表中读取数据,然后写入另一个表。挑战在于,单个客户编号与第一个表中的多个控制器绑定,最多10个控制器。我将把它重新写入另一个表中,以便在一行中有唯一的客户编号和所有董事。最后一个表的表结构是Customer No、Director1、Director2、…Director10。这些表位于Oracle数据库中

试试这个

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);

不需要在这里大喊大叫为什么你认为你需要一个存储过程?对我来说听起来像是一个支点…这就是要求。如果你有其他的方法,你可以帮助解决这个问题。用listagg进行简单的修复。OP甚至没有在谷歌上搜索过。