添加 ROWNUM 列时 SQL 查询超时

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

我有第一个有效的查询。但后来我添加了 ROWNUM 列来尝试对结果进行分页。现在似乎只是超时而没有返回任何结果。不明白这里关于Oracle数据库的问题。

// Working
select 
    tablea.* 
from 
    (select 
         vcell.operator_name, vcell.vendor_name, 
         v_territory.territory_label as Region, 
         v_zone.zone_short_name as Zone, v_cluster.cluster_nm, 
         vcell.engineering_number, v_location.loc_site_long_nm as Name,
         vcell.Band infoband, vcell.Freq_Band infofreqband, 
         vcell.Carrier infocarr, vcell.channel_bandwidth infobandwidth, 
         vcell.cell_type infocelltype, vcell.enodeb_id infoenbid, 
         vcell.local_cell_id infocellid, vcell.ecell_name infocellname, 
         vcell.Sector infosector, vcell.Channel infochannel,
         vcell.physical_cell_id infopci, vcell.TAC infotac, 
         tbl.* 
     from
         cim.v_zone v_zone, cim.v_cluster v_cluster, 
         cim.v_territory v_territory, cim.v_location v_location,
         cim.v_cell_lte vcell, netact_b_lnd.SRAN_CELL_LNCEL tbl 
     where
         v_zone.zone_label = '9' 
         and v_location.operator_name = 'Base' 
         and vcell.operator_name = 'Box' 
         and vcell.vendor_name = 'N' 
         and v_zone.zone_id = v_cluster.zone_id 
         and v_territory.territory_id = v_zone.territory_id 
         and v_cluster.cluster_id = v_location.cluster_id 
         and vcell.engineering_number = v_location.engineering_number 
         and SUBSTR(tbl.DISTNAME, INSTR(tbl.DISTNAME,'LNBTS-',1) + 6, 6) = vcell.enodeb_id
         and REPLACE(SUBSTR(tbl.DISTNAME, INSTR(tbl.DISTNAME, 'LNCEL-', 1) + 6, INSTR(SUBSTR(tbl.DISTNAME || '/', INSTR(tbl.DISTNAME,'LNCEL-',1) + 6, 4),'/',1)),'/','') = vcell.local_cell_id 
       order by tbl.distname) tablea

// Not working
select 
    tablea.*, ROWNUM 
from 
    (select
         vcell.operator_name, vcell.vendor_name, 
         v_territory.territory_label as Region, 
         v_zone.zone_short_name as Zone, v_cluster.cluster_nm, 
         vcell.engineering_number, v_location.loc_site_long_nm as Name,
         vcell.Band infoband, vcell.Freq_Band infofreqband, 
         vcell.Carrier infocarr,vcell.channel_bandwidth infobandwidth, 
         vcell.cell_type infocelltype, vcell.enodeb_id infoenbid, 
         vcell.local_cell_id infocellid,vcell.ecell_name infocellname,
         vcell.Sector infosector, vcell.Channel infochannel,
         vcell.physical_cell_id infopci, vcell.TAC infotac, 
         tbl.* 
     from
         cim.v_zone v_zone,cim.v_cluster v_cluster, 
         cim.v_territory v_territory, cim.v_location v_location,
         cim.v_cell_lte vcell, netact_b_lnd.SRAN_CELL_LNCEL tbl 
     where
         v_zone.zone_label = '9'  
         and v_location.operator_name = 'Base' 
         and vcell.operator_name = 'Box' 
         and vcell.vendor_name = 'N' 
         and v_zone.zone_id = v_cluster.zone_id 
         and v_territory.territory_id = v_zone.territory_id 
         and v_cluster.cluster_id = v_location.cluster_id 
         and vcell.engineering_number = v_location.engineering_number 
         and SUBSTR(tbl.DISTNAME, INSTR(tbl.DISTNAME,'LNBTS-',1) + 6, 6) = vcell.enodeb_id
         and REPLACE(SUBSTR(tbl.DISTNAME, INSTR(tbl.DISTNAME,'LNCEL-',1) + 6, INSTR(SUBSTR(tbl.DISTNAME || '/', INSTR(tbl.DISTNAME,'LNCEL-',1) + 6, 4),'/',1)),'/','') = vcell.local_cell_id 
       order by tbl.distname) tablea  
where 
    ROWNUM <= 5

我正在关注此页面以在 Oracle 数据库上进行分页。 https://blogs.oracle.com/connect/post/on-rownum-and-limiting-results 这是一个与我构建的分页一起使用的类似查询

 select * from ( select a.*, ROWNUM rnum from ( SELECT vcell.operator_name as Provider, vcell.vendor_name as Vendor, loc.region_id as Region, loc.zone_short_name AS Zone, loc.clust, vcell.engineering_number, loc.loc_site_long_nm AS Name, vcell.Band, vcell.Freq_Band, vcell.Carrier,    
vcell.NRARFCN_DL, vcell.BANDWIDTH_MHZ_DL, vcell.NRARFCN_UL, vcell.BANDWIDTH_MHZ_UL, vcell.cell_type, vcell.gnodeb_id as GNODEBID, vcell.local_cell_id as LOCALCELLID, vcell.cell_name as LOCALCELLNAME, vcell.Sector, vcell.PHYSICALCELLID, vcell.TAC, tbl.* 
FROM netact_b_lnd.SRAN_NRC_NRCELL tbl 
INNER JOIN ( SELECT vcl.gnodeb_id, vcl.cell_id, vcl.cell_name, vcl.engineering_number, vcl.operator_name, vcl.vendor_name, vcl.local_cell_id, vcl.NRDUCELLID, vcl.PHYSICALCELLID, vcl.cell_type, vcl.nci, vcl.sector, vcl.band, vcl.carrier, vcl.freq_band, vcl.TAC,  vcl.NRARFCN_DL, vcl.BANDWIDTH_MHZ_DL,
vcl.NRARFCN_UL, vcl.BANDWIDTH_MHZ_UL FROM cim.v_cell_nr vcl WHERE vcl.operator_name = 'Base' and vcl.vendor_name = 'N') vcell 
ON SUBSTR(tbl.DISTNAME, INSTR(tbl.DISTNAME,'MRBTS-',1) + 6, 7) = vcell.gnodeb_id AND REPLACE(SUBSTR(tbl.DISTNAME, INSTR(tbl.DISTNAME,'NRCELL-',1) + 7, INSTR(SUBSTR(tbl.DISTNAME || '/', INSTR(tbl.DISTNAME,'NRCELL-',1) + 7, 4),'/',1)),'/','') = vcell.local_cell_id 
INNER JOIN (SELECT v_location.engineering_number, v_location.loc_site_long_nm, v_location.operator_name, v_cluster.region_id, v_zone.zone_short_name, v_cluster.cluster_nm AS clust, v_location.province, v_location.region FROM cim.v_zone v_zone 
INNER JOIN cim.v_cluster v_cluster ON v_zone.zone_id = v_cluster.zone_id 
INNER JOIN cim.v_location v_location ON v_cluster.cluster_id = v_location.cluster_id 
WHERE v_location.operator_name = 'Box') loc ON vcell.engineering_number = loc.engineering_number order BY tbl.distname ) a 
      where ROWNUM < 200000 ) 
where rnum  >= 1
sql oracle-sqldeveloper rownum
1个回答
0
投票

除了评论中告诉您的内容之外,您是否尝试使用

row_number
分析函数?使用当前查询作为 CTE 以获得更好的可读性(而不是您使用的内联视图)。

with tablea as
    (select
         row_number() over (order by tbl.distname) rn,
         --
         vcell.operator_name, vcell.vendor_name, 
         v_territory.territory_label as Region, 
         v_zone.zone_short_name as Zone, v_cluster.cluster_nm, 
         vcell.engineering_number, v_location.loc_site_long_nm as Name,
         vcell.Band infoband, vcell.Freq_Band infofreqband, 
         vcell.Carrier infocarr,vcell.channel_bandwidth infobandwidth, 
         vcell.cell_type infocelltype, vcell.enodeb_id infoenbid, 
         vcell.local_cell_id infocellid,vcell.ecell_name infocellname,
         vcell.Sector infosector, vcell.Channel infochannel,
         vcell.physical_cell_id infopci, vcell.TAC infotac, 
         tbl.* 
     from
         cim.v_zone v_zone,cim.v_cluster v_cluster, 
         cim.v_territory v_territory, cim.v_location v_location,
         cim.v_cell_lte vcell, netact_b_lnd.SRAN_CELL_LNCEL tbl 
     where
         v_zone.zone_label = '9'  
         and v_location.operator_name = 'Base' 
         and vcell.operator_name = 'Box' 
         and vcell.vendor_name = 'N' 
         and v_zone.zone_id = v_cluster.zone_id 
         and v_territory.territory_id = v_zone.territory_id 
         and v_cluster.cluster_id = v_location.cluster_id 
         and vcell.engineering_number = v_location.engineering_number 
         and SUBSTR(tbl.DISTNAME, INSTR(tbl.DISTNAME,'LNBTS-',1) + 6, 6) = vcell.enodeb_id
         and REPLACE(SUBSTR(tbl.DISTNAME, INSTR(tbl.DISTNAME,'LNCEL-',1) + 6, INSTR(SUBSTR(tbl.DISTNAME || '/', INSTR(tbl.DISTNAME,'LNCEL-',1) + 6, 4),'/',1)),'/','') = vcell.local_cell_id 
      ) 
select *
from tablea
where rn <= 5
order by rn;
© www.soinside.com 2019 - 2024. All rights reserved.