Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.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_Oracle - Fatal编程技术网

Sql 从列名中删除引号

Sql 从列名中删除引号,sql,oracle,Sql,Oracle,假设我有下表: create table t1( clid number, category varchar2(100) ); insert into t1 values(1, 'A'); insert into t1 values(1, 'B'); insert into t1 values(2, 'A'); insert into t1 values(2, 'C'); insert into t1 values(3, 'A'); insert into t1 values(

假设我有下表:

create table t1(
    clid number,
    category varchar2(100)
);

insert into t1 values(1, 'A');
insert into t1 values(1, 'B');
insert into t1 values(2, 'A');
insert into t1 values(2, 'C');
insert into t1 values(3, 'A');
insert into t1 values(3, 'B');
我需要旋转此表并计算每个CLID值的次数。因此,为了实现这一点,我使用以下代码:

select * from t1
pivot(
    count(item)
    for item in('A', 'B', 'C')
)
并得到结果:

CLID  'A' 'B' 'C'
1     1   1   0
2     1   0   0
3     1   1   0
除了在新栏目名称中加引号外,一切都很棒。我尝试了下一个代码:

alter table t1 rename column 'A' to A
它会引发以下错误:

Error starting at line : 537 in command -
alter table t1 rename column 'A'
Error report -
ORA-00904: : invalid identifier
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:
所以,我的问题是,如何重命名引号中的列名(这样就可以去掉引号)


感谢您的帮助。

使用条件聚合怎么样

select sum(case when item = 'A' then 1 else 0 end) as A,
       sum(case when item = 'B' then 1 else 0 end) as B,
       sum(case when item = 'C' then 1 else 0 end) as C       
from t1;

只使用条件聚合如何

select sum(case when item = 'A' then 1 else 0 end) as A,
       sum(case when item = 'B' then 1 else 0 end) as B,
       sum(case when item = 'C' then 1 else 0 end) as C       
from t1;

列名似乎是
类别
,而不是

因此:


列名似乎是
类别
,而不是

因此:


不幸的是,这种方法在实际数据中不够方便,因为我有数百个项目,所以将所有项目放入条件聚合中需要花费太多时间。不幸的是,这种方法在实际数据中不够方便,因为我有数百个项目,因此,将所有这些项放入条件聚合将花费太多的时间。您同意pivot并仍在寻找答案吗?您同意pivot并仍在寻找答案吗?