我遇到动态查询的一个问题。我试图通过在游标中使用动态SQL来更新一个更新语句。
你能帮我解决一下这个问题......
declare
statement varchar2(1000);
begin
for c1 in(select tenant_id from tenant where tenant_id!=0)
loop
for c2 in ( select alignment_id from customer_alignment where affiliation_id is null and tenant_id=c1.tenant_id)
loop
insert into t3 select 1 from dual;
for c3 in ( select *
from ca_primary_address ca,customer_alignemnt ca where ca.affiliation_id is null
and ca.alignment_id=c2.alignment_id
and ca.customer_id=vw.customer_id
and ca.alignment_id=vw.alignment_id
)
loop
statement :='update customer_alignment set affiliation_id='||vw.affiliation_id||' where customer_alignment_id='||customer_alignment_id||';'
execute immediate('begin '||STATEMENT||' end;');
end loop;
end loop;
dbms_output.put_line('Tenant_id '||c1.tenant_id);
end loop;
end;
执行
时低于错误消息ORA-06550:第8行,第10栏: PLS-00402:游标的SELECT列表中需要别名以避免重复的列名
请帮我解决这个问题。
很多非常感谢你的帮助。Sunitha ..
答案 0 :(得分:1)
尝试以下方法:
...
statement :='update customer_alignment set affiliation_id='||c3.affiliation_id||' where customer_alignment_id='||c3.customer_alignment_id;
execute immediate(statement);
...
您必须使用游标变量限定更新查询字符串中使用的变量。