[英]How to set column values as column name in pl SQL but I don't know what what will be the column values?
I want to populate few aa.one, aa.two, aa.three columns from aa table and when I put aa.one = 'abc' in where condition I want to rename these column names as column values will populate.我想从 aa 表中填充几个 aa.one、aa.two、aa.three 列,当我将 aa.one = 'abc' 放在 where 条件中时,我想重命名这些列名,因为列值将填充。 But one thing I don't know what value will populate through out the table但有一件事我不知道表中会出现什么值
The only way out is dynamic SQL
as you have to compose the whole statement dynamically and run it using execute immediate
.唯一的出路是dynamic SQL
因为您必须动态地编写整个语句并使用execute immediate
运行它。
Note that it is difficult to maintain;注意维护难度大; might be OK for very simple cases, but for complex queries ... I'd think twice before actually doing something about it.对于非常简单的情况可能没问题,但对于复杂的查询......在实际做一些事情之前我会三思而后行。
Something like this:像这样的东西:
declare
l_str varchar2(200);
begin
l_str := 'update ' || par_table_name || ' set ' ||
par_column_1 || ' = ' || par_value_1 ||
' where ' || par_column_where_1 || ' = ' || par_column_where_value_1;
execute immediate l_str;
end;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.