简体   繁体   English

如何在 pl SQL 中将列值设置为列名,但我不知道列值是什么?

[英]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.

相关问题 如果我不知道该如何查找具有列值的表 - how to find tables that have column values if i don't know the table 什么SQL语句将确定集合中的哪些值不在指定的列中? - What SQL statement will determine which values in a set are not in a specified column? 如何基于列值从表中知道列名 - How to know the column name from a table based on the column values PL/SQL 将数据插入一列,其值对应于另一列的值 - PL/SQL insert data into a column with values corresponding to values of another column 如果我没有列对其进行分组,如何对值求和 - How to sum values if I don't have column to group it by 如何在sql中设置列的每个不同值的唯一名称 - how to set unique name of each distinct values of a column in sql SQL查询中列名前面的值是什么? - What are values prepended to column names in an SQL query? PL SQL脚本根据列值进行连接 - PL SQL script to concatenate based on the column values 在 SQL 中,我可以在另一列中获取与它们没有关联的特定值的列中的值吗? - In SQL, can I get the values in one column that don't have a certain value associated to them in another column? 什么 T-SQL 查询会检索 Email 列的所有值,其中 First_Name 和 Last_ Name 列的值位于 Email 列中? - What T-SQL query would retrieve all values of the Email column where values of First_Name and Last_ Name columns are in the Email column?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM