【发布时间】:2019-04-03 19:31:16
【问题描述】:
我有一个名为 "time_recs" 的表的 Oracle 11g 数据库。我需要在 SQL Developer 中运行一个查询,包括一个名为 comment 的列。 由于 comment 是保留字,我需要转义它,没关系。问题是当您使用缩写表名时,我找不到正确的语法。
例如:如果我运行 select "cmets" from "time_recs"; 效果很好。
但我需要运行的报告粘贴在下面。如果您看到第 17 行(“tr”.“comment”),我已经尝试了很多不同的东西:引号、双引号等。我仍然无法使其工作,因为我不断收到“无效标识符”错误
任何帮助将不胜感激。
select
tr.record_date as "Date"
, ua4.string_value as "Employee Number"
, case when p.id_parent = 'root' then p.pname else pp.pname end as "Parent Project Name"
, p.pname as "Project"
, ct.pname as "Work Package"
, tra1.string_value as "Cost Center"
, ua1.string_value as "Discipline"
, case when ua3.string_value = 'Research' then 'R' else 'D' end as "R or D"
, 'N/A' as "Sub Discipline"
, tra2.string_value as "Primary Indication"
, tra3.string_value as "Project Phase"
, pa1.string_value as "Project Template Type"
, pa2.string_value as "Secondary Indication"
, pa3.string_value as "Therapeutic Area"
, sum(tr.time_amount) as "Hours"
, "tr"."comment"
from time_recs tr
left join users us on
tr.id_user = us.id_user
left join users_attribs ua1 on
tr.id_user = ua1.id_user
left join projects p on
tr.id_project = p.id_project
join projects pp on
pp.id_project = p.id_parent
join codes_tasks ct on
ct.id_code = tr.id_code_task
left join time_recs_attribs tra1 on
tr.id_time_rec = tra1.id_time_rec
join attribute_types attr1 on
attr1.id_attr_type = tra1.id_attr_type and attr1.pname = 'Cost Center'
join attribute_types atua2 on
atua2.id_attr_type = ua1.id_attr_type and atua2.pname = 'Discipline'
left join users_attribs ua3 on
tr.id_user = ua3.id_user
join attribute_types atua3 on
atua3.id_attr_type = ua3.id_attr_type and atua3.pname = 'Organization'
left join users_attribs ua4 on
tr.id_user = ua4.id_user and ua4.id_attr_type='D00C686107154F3FB2B97F47B172CB7F' --Employe Number
left join time_recs_attribs tra2 on
tr.id_time_rec = tra2.id_time_rec
join attribute_types attr2 on
attr2.id_attr_type = tra2.id_attr_type and attr2.pname = 'Primary Indication'
left join time_recs_attribs tra3 on
tr.ID_TIME_REC = tra3.ID_TIME_REC
join attribute_types attr3 on
attr3.id_attr_type = tra3.id_attr_type and attr3.pname = 'Project Phase'
right join projects_attribs pa1 on
tr.id_project = pa1.id_project
join attribute_types atpa1 on
atpa1.id_attr_type = pa1.id_attr_type and atpa1.pname = 'Project Template Type'
left join projects_attribs pa2 on
tr.id_project = pa2.id_project
join attribute_types atpa2 on
atpa2.id_attr_type = pa2.id_attr_type and atpa2.pname = 'Secondary Indication'
left join projects_attribs pa3 on
tr.id_project = pa3.id_project
join attribute_types atpa3 on
atpa3.id_attr_type = pa3.id_attr_type and atpa3.pname = 'Therapeutic Area'
where
tr.record_date >= 20190101
and tr.record_date <= 20190131
having sum(tr.time_amount) >0
group by
tr.record_date
, ua4.string_value
, case when p.id_parent = 'root' then p.pname else pp.pname end
, p.pname
, ct.pname
, tra1.string_value
, ua1.string_value
, case when ua3.string_value = 'Research' then 'R' else 'D' end
, 'N/A'
, tra2.string_value
, tra3.string_value
, pa1.string_value
, pa2.string_value
, pa3.string_value
;
【问题讨论】:
-
COMMENT是保留字,"comment"不是。是哪个?
标签: oracle oracle-sqldeveloper reserved-words