![](/img/trans.png)
[英]How to change column names in the resultset by comparing with other resultset values
[英]I want to dynamically change resultset column names
我正在尝试更改结果集中的列名,从 sysdate 动态添加年份。
所以我尝试了这样的事情:
create table TestTable (
name varchar2(30),
age INTEGER
);
insert into TestTable values('johnny1',10);
insert into TestTable values('johnny2',15);
Select qry0.name,qry0.age as to_char("age" || qry1.theyear)
from (Select name,age from TestTable) qry0,
(select to_char(sysdate,('YYYY'))as TheYear from dual)qry1;
我试图得到这样的列标题:
NAME AGE2019
谢谢
如果您使用 SQLPlus 之类的工具来生成报告,并且您只是在报告中查找合适的名称,则可以使用替换变量,例如
SQL> create table TestTable (
2 name varchar2(30),
3 age INTEGER
4 );
Table created.
SQL>
SQL> insert into TestTable values('johnny1',10);
1 row created.
SQL> insert into TestTable values('johnny2',15);
1 row created.
SQL> col xx new_value yy
SQL> select 'AGE'||to_char(sysdate,'YYYY') xx from dual;
XX
-------
AGE2019
SQL> select name, age &&yy from testtable;
NAME AGE2019
------------------------------ ----------
johnny1 10
johnny2 15
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.