Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在SQL中动态更改列标题?_Sql_Relational Database_Db2 Luw - Fatal编程技术网

如何在SQL中动态更改列标题?

如何在SQL中动态更改列标题?,sql,relational-database,db2-luw,Sql,Relational Database,Db2 Luw,我有两张桌子 UI_COMPONENT UI_ID LABEL_ID UI_Name 01 Label1 Custom_Name 02 Label2 Random_text 03 Label3 Dummy_Label 这意味着html页面将有3个文本框,它们将有标签,如自定义\名称、随机\文本和虚拟\标签。 例: 自定义名称:___________________ 随机文本:___________________ 虚拟标签:

我有两张桌子

UI_COMPONENT
UI_ID   LABEL_ID    UI_Name
01      Label1      Custom_Name
02      Label2      Random_text
03      Label3      Dummy_Label
这意味着html页面将有3个文本框,它们将有标签,如自定义\名称、随机\文本和虚拟\标签。 例:

自定义名称:___________________

随机文本:___________________

虚拟标签:___________________

我们在这些文本框中填写的内容都存储在另一个表中:

UI_COMPONENT_VALUES:
ID      Label1      Label2      Label3
111     John        Doe         Millers
222     David                   Gabriel
管理员有权重命名UI_组件标签。 我需要创建一个视图,在该视图中,我可以使用动态标题显示UI_组件_值中的值。 或者至少你能帮我做一个SQL查询,用下面提到的方式检索数据吗

预期产出:

UI_COMPONENT_VALUES_VIEW:
ID      Custom_Name     Random_text     Dummy_Label
111     John            Doe             Millers
222     David                           Gabriel

不幸的是,视图的列名是DDL的一部分,这意味着要修改它,必须执行DDL语句。@TimBiegeleisen已经提到的第二种方法是动态生成脚本。但这意味着您不能通过view来执行,它必须是存储过程。正如前面提到的,存储过程可能是执行您想要的操作的最佳方式,但请注意,将编译数据库遇到的每一条不同的语句,这有时会比语句执行时间长。