ORA-00923执行查询时出错

时间:2017-11-08 14:23:27

标签: sql oracle

我正在使用以下查询以查看输出但我收到以下错误消息。请你帮帮我吧。

查询:

SELECT REGEXP_SUBSTR(pr.Asset, '(.+):.+@',1,1,'i',1) as pr.instancename ,
upper(REGEXP_SUBSTR(pr.Asset, '.+@(.+)s-',1,1,'i',1)) as pr.Servername,
Asset,asset_type,check_category,check_desc,custom_attributes,check_id,db_attributes,occurances,organization,result_status,risk
FROM table1 pr
left join table2 ser on pr.Servername = ser.server_component_name

输出错误:

ORA-00923: FROM keyword not found where expected
00923. 00000 -  "FROM keyword not found where expected"
*Cause:    
*Action:
Error at Line: 1 Column: 59

有人可以帮助我。

此致

Bharath Vikas

1 个答案:

答案 0 :(得分:0)

有些事情是错的。

  • 如果您对计算值使用别名,则不要将表别名添加到其中。它不是表格中的列。
  • 您无法将表直接加入计算值的别名。但将其包装在子查询中,您可以使用它。

示例:

SELECT *
FROM (
 select 
   REGEXP_SUBSTR(Asset, '(.+):.+@',1,1,'i',1) as InstanceName,
   upper(REGEXP_SUBSTR(Asset, '.+@(.+)s-',1,1,'i',1)) as ServerName,
   Asset, asset_type, check_category, check_desc,custom_attributes, 
   check_id, db_attributes, occurances, organization, result_status, 
   risk
 from table1
) pr
left join table2 ser on (pr.ServerName = ser.server_component_name);

免责声明:仅在记事本中进行测试

一些简化的例子:

-- BAD : an alias using an alias
select UPPER(f.bar) as f.UberBar 
from Foo f

-- BAD : Foo doesn't have an UberBar column
select UPPER(bar) as UberBar 
from Foo 
where UberBar = 'BAR'

-- OK : wrapped in a subquery and using the alias in the outer query
select * from (
   select UPPER(bar) as UberBar 
   from Foo
) as Q 
where Q.UberBar = 'BAR'

-- OK : repeat the calculation of the value in the ON of the JOIN, or the WHERE clause
select UPPER(bar) as UberBar 
from Foo
where UPPER(bar) = 'BAR'