declare
-- 创建游标
v_sql varchar2(500);
cursor c_tablecodes is select distinct tablecode from busfw_t_dccolumnnew t where elementsavetype = 'name' ;
begin
-- 循环表
for c_table in c_tablecodes LOOP
v_sql := 'update '||c_table.tablecode||' t set ';
-- 循环字段
for c_column in (select tablecode,columncode,linkcolumn,linkcoltype,datasource,requirement from busfw_t_dccolumnnew t where elementsavetype = 'name' and tablecode =c_table.tablecode) LOOP
--dbms_output.put_line(c_table.tablecode||''','''||c_column.columncode||'''');
v_sql:=v_sql||c_column.columncode||' = (select name from '||c_column.datasource||' where code =t.'||c_column.linkcolumn||'),';
END LOOP;
v_sql:=substr(v_sql,1,len(v_sql)-1);
dbms_output.put_line(v_sql);
END LOOP;
end;