列定义不明确,但为什么呢? (ORA-00918)

问题描述 投票:0回答:2

我正在创建一个为我们运行 SQL 查询的应用程序。我已经从正在运行的脚本中复制了此查询,但是当我将其粘贴到 SQL Developer 或 vs Code 中时,它给了我一个 ORA-00918: 列定义不明确的错误。我找不到问题出在哪里。希望有人能看到它并解释出了什么问题。

    select to_char(STARTTIMESTAMP, 'yyyymmdd hh24:mi:ss DY') as "DATE",
       bridgeid,
       requestType,
       RequestSpecification,
       bfa.faultdescription,
       case
         when requestMessage is not null then
          dbms_lob.substr(substr(bMes.requestMessage,
                                 INSTR(bMes.requestMessage, 'SourceSystem', 1) +
                                 length('SourceSystem') + 1,
                                 (INSTR(bMes.requestMessage,
                                        'SourceSystem',
                                        1,
                                        2) - INSTR(bMes.requestMessage,
                                                    'SourceSystem',
                                                    1) -
                                 length('SourceSystem') - 3)))
       end as sourceSystem,
       case
         when requestMessage is not null then
          dbms_lob.substr(substr(bMes.requestMessage,
                                 INSTR(bMes.requestMessage, 'EventId', 1) +
                                 length('EventId') + 1,
                                 (INSTR(bMes.requestMessage, 'EventId', 1, 2) -
                                 INSTR(bMes.requestMessage, 'EventId', 1) -
                                 length('EventId') - 3)))
       end as EventId,
       bint.MessageId,
       bint.relatesto,
       systimestamp
  from baseintegrationheaders bint
  left join baseMessages bMes
    on bMes.relatesto = bint.relatesto
  left join basefaults bfa
    on bfa.relatesto = bint.relatesto
where 1 = 1
   and STARTTIMESTAMP Between
       (trunc(systimestamp, 'hh') +
       floor(to_char(systimestamp, 'mi') / 15) * 15 / 1440) - 15 / 1440 And
       trunc(systimestamp, 'hh') +
       floor(to_char(systimestamp, 'mi') / 15) * 15 / 1440
   and bint.technicaldomain = 'WB'
   and bint.bridgeid in ('AST_GPSBatch_Reply-bridge',
                          'AST_GPSOnline_Reply-bridge',
                          'AST_GPS_Request-bridge')
   and requestType not in ( 'WorkerRunning'
                          , 'BridgeEnd'
                          , 'BridgeStart'
                          , 'WorkerEnd'
                          , 'WorkerMQEnd'
                          , 'WorkerMQStart'
                          , 'WorkerProducerEnd'
                          , 'WorkerProducerStart'
                          , 'WorkerReaderEnd'
                          , 'WorkerReaderStart'
                          , 'WorkerStart'
                          , 'WorkerStop'
                          )
   and ((requestType = 'BridgeRequest' and faultindication = 'true') or
       (requestType <> 'BridgeRequest'))
order by bint.MessageId, 1
;
sql oracle oracle-sqldeveloper
2个回答
0
投票

ORA-00918: column ambiguously defined error
意味着在你的sql中,你连接了两个具有相同列的表,但你不知道要哪个
select


0
投票

Oracle 中的 ORA-00918 错误通常在 SQL 查询中的列名称不明确时发生。这意味着查询中引用的列存在于多个表中,而 Oracle 不知道该使用哪一个。要解决此问题,您需要为查询中的每一列指定表或别名以消除歧义。

基本上,为查询中使用的所有列提供别名,以确保您从正确的表中获取它。

© www.soinside.com 2019 - 2024. All rights reserved.