Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.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
使用缩写表名时转义Oracle中保留字的语法_Oracle_Oracle Sqldeveloper_Reserved Words - Fatal编程技术网

使用缩写表名时转义Oracle中保留字的语法

使用缩写表名时转义Oracle中保留字的语法,oracle,oracle-sqldeveloper,reserved-words,Oracle,Oracle Sqldeveloper,Reserved Words,我有一个Oracle 11g数据库,表名为“time\u recs”。我需要在SQLDeveloper中运行一个查询,包括一个名为comment的列。 由于评论是一个保留字,我需要避开它,没关系。问题是,当您使用缩写表名时,我找不到正确的语法 例如:如果我运行,请从“时间记录”中选择“评论”;它工作得很好 但是我需要运行的报告粘贴在下面。如果你看到第17行(“tr“.”comment),我尝试了很多不同的方法:引号、双引号等等。但我仍然无法使它工作,因为我一直遇到“无效标识符”错误 任何帮助都将

我有一个Oracle 11g数据库,表名为“time\u recs”。我需要在SQLDeveloper中运行一个查询,包括一个名为comment的列。 由于评论是一个保留字,我需要避开它,没关系。问题是,当您使用缩写表名时,我找不到正确的语法

例如:如果我运行,请从“时间记录”中选择“评论”;它工作得很好

但是我需要运行的报告粘贴在下面。如果你看到第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
  ;
选择
tr.将日期记录为“日期”
,ua4.string_值为“员工编号”
,当p.id_parent='root'时,则p.pname else pp.pname以“父项目名称”结尾
,p.pname为“项目”
,ct.pname作为“工作包”
,tra1.string_值为“成本中心”
,ua1.string_值为“规程”
,当ua3.string_value='Research'然后'R'else'D'以“R或D”结尾时的情况
“不适用”为“子专业”
,tra2.string_值作为“主要指示”
,tra3.string_值为“项目阶段”
,pa1.string_值为“项目模板类型”
,pa2.string_值作为“二次指示”
,pa3.字符串_值为“治疗区域”
,总和(tr.时间和金额)为“小时”
“tr”“comment”
不时地
左上角加入我们
tr.id_user=us.id_user
左连接用户\u属性ua1打开
tr.id_user=ua1.id_user
左键连接项目p on
tr.id_项目=p.id_项目
加入pp上的项目
pp.id\u项目=p.id\u父项目
连接代码\u任务ct on
ct.id\u代码=tr.id\u代码\u任务
左连接时间\u记录\u属性tra1打开
tr.id\u time\u rec=tra1.id\u time\u rec
连接属性\u类型attr1 on
attr1.id\u attr\u type=tra1.id\u attr\u type和attr1.pname='成本中心'
连接上的属性类型atua2
atua2.id_attr_type=ua1.id_attr_type和atua2.pname='规程'
左加入用户\u属性ua3上的
tr.id_user=ua3.id_user
连接上的属性类型atua3
atua3.id_attr_type=ua3.id_attr_type和atua3.pname='Organization'
左连接用户\u属性ua4上
tr.id_user=ua4.id_user和ua4.id_attr_type='D00C6868107154F3FB2B97F47B172CB7F'--员工编号
左连接时间\u记录\u属性tra2打开
tr.id\u time\u rec=tra2.id\u time\u rec
连接上的属性\u类型attr2
attr2.id\u attr\u type=tra2.id\u attr\u type和attr2.pname='主指示'
左连接时间\u记录\u属性tra3打开
tr.ID\u TIME\u REC=tra3.ID\u TIME\u REC
连接属性\u类型attr3 on
attr3.id\u attr\u type=tra3.id\u attr\u type和attr3.pname='项目阶段'
右键连接项目\u attribs pa1 on
tr.id_项目=pa1.id_项目
连接属性类型atpa1 on
atpa1.id\u attr\u type=pa1.id\u attr\u type和atpa1.pname='项目模板类型'
左连接项目\u属性pa2打开
tr.id_项目=pa2.id_项目
连接上的属性类型atpa2
atpa2.id\u attr\u type=pa2.id\u attr\u type和atpa2.pname='辅助指示'
左连接项目\u属性pa3打开
tr.id_项目=pa3.id_项目
连接属性类型atpa3 on
atpa3.id_attr_type=pa3.id_attr_type和atpa3.pname=‘治疗区’
哪里
tr.记录日期>=20190101
和tr.record_日期0
分组
记录日期
,ua4.string_值
,当p.id_parent='root'然后p.pname else pp.pname end
,p.pname
,ct.pname
,tra1.string_值
,ua1.string_值
,当ua3.string_value='Research'然后'R'else'D'结束时的情况
“不适用”
,tra2.string_值
,tra3.string_值
,pa1.string_值
,pa2.string_值
,pa3.string_值
;
你不需要任何东西;按原样使用别名:


谢谢你的评论。嗯,现在我明白了,我必须更加小心地打字。该列名为comment(小写,不带引号)

如果我运行以下简单查询,它就会工作: 从“时间记录”中选择“注释”


然而,我不能让它与缩写表名一起工作我还提供了一个表字段列表

我猜他实际表中的列是大写的,只会因为保留字而给他错误。这是正确的答案,但他的表格实际上可能要求他使用tr.“COMMENT”。我不这么认为,@Patrick。如果列名是大写的,则不必将其括在双引号中,因为Oracle(默认情况下)以大写创建列名。在这种情况下,所有这些选项都会起作用:
select comment,comment,“comment”from…
,但我认为他的问题是
comment
这个词在oracle中是一个保留词。如果创建的表中有一列名为
COMMENT
,则仍然无法选择该列。另外,看看他在同一个表中使用的其他列,它们都不需要小写引号。啊!对不起,我没听懂。当然,您不能将列名创建为注释,但“注释”可以使用。应该让我开动脑筋。或者去睡觉。事实上,我来自科门塔,@thatjeffsmith:)
COMMENT
是一个保留字,
“COMMENT”
不是。是哪一个?
SQL> create table time_recs ("comment" varchar2(10));

Table created.

SQL> insert into time_recs ("comment") values ('Littlefoot');

1 row created.

SQL> select tr."comment"          --> here
  2  from time_recs tr;

comment
----------
Littlefoot

SQL>