如何在Oracle表中选择一行?

时间:2012-12-24 15:19:11

标签: sql oracle oracle11g

我在Oracle中拥有这个庞大的表:

COMPONENTSTATSID    NUMBER(38,0)
COMPONENTTYPEID NUMBER(38,0)
NAME    VARCHAR2(200 BYTE)
SERIALNUMBER    VARCHAR2(150 BYTE)
WEIGHTKG    NUMBER(9,0)
SIZEWEIGHTMILIM NUMBER(6,0)
SIZEWIDTHMILIM  NUMBER(6,0)
ZONECAGE    VARCHAR2(50 BYTE)
SIZELENGHTMILIM NUMBER(6,0)
SIZEDEPTMILIM   NUMBER(6,0)
RAMSLOTS    NUMBER
NETWORKINTERFACE    VARCHAR2(60 BYTE)
RAMSLOTSPEED    VARCHAR2(60 BYTE)
RAMSLOTTYPE VARCHAR2(60 BYTE)
POWERWATT   NUMBER(5,0)
OPERATINGTEMPERATUREMIN NUMBER(4,0)
OPERATINGTEMPERATUREMAX NUMBER(4,0)
STORAGETEMPERATUREMIN   NUMBER(4,0)
STORAGETEMPERATUREMAX   NUMBER(4,0)
DATEFORDECOMISN TIMESTAMP(6)
MANIFACTURECOMPANY  VARCHAR2(100 BYTE)
MANIFACTUREWARRANTY VARCHAR2(100 BYTE)
UFORM   VARCHAR2(30 BYTE)
STATUS  VARCHAR2(30 BYTE)
LOCATION    VARCHAR2(30 BYTE)
HEATEMISIONSBTU NUMBER(10,0)
PRODUCTIONENVIRONMENT   VARCHAR2(30 BYTE)
STANDARTLIFETIME    VARCHAR2(30 BYTE)
OPERATINGHAMIDITYRANGE  VARCHAR2(30 BYTE)
BOUGTHDATE  TIMESTAMP(6)
OPERATINGSYSTEM CLOB
SUPPORTCONTACT  VARCHAR2(100 BYTE)
INTERFACETYPE   VARCHAR2(60 BYTE)
TYPE    VARCHAR2(30 BYTE)
POWERCAPACITYWATT   NUMBER(10,0)
COOLINGCAPACITYBTU  NUMBER(8,0)
DATEADDED   TIMESTAMP(6)
STORAGECONTROLLER   VARCHAR2(60 BYTE)
DATEDEPLOYED    TIMESTAMP(6)
DESCRIPTION CLOB
MAXNUMBERPROCESSORS NUMBER(2,0)
CPUCACHESIZE    VARCHAR2(30 BYTE)
RAMSIZE VARCHAR2(30 BYTE)
USBPORTS    NUMBER(2,0)
CPUCORES    NUMBER
RAIDSUPPORT VARCHAR2(30 BYTE)
EXPANSIONSLOTS  VARCHAR2(60 BYTE)
DISKBAYS    VARCHAR2(60 BYTE)
HOTSWAPCOMPONENTS   VARCHAR2(60 BYTE)
NUMBERPORTS NUMBER(38,0)
PORTSPEED   VARCHAR2(30 BYTE)
MINAMBIENTTEMP  NUMBER(10,4)
MAXAMBIENTTEMP  NUMBER(10,4)
DCALLOWEDWEIGHTKG   NUMBER(10,4)
DCMAXIMUMWEIGHTKG   NUMBER(10,4)
DCALLOWEDPOWERWATT  NUMBER(10,4)
DCMAXPOWERWATT  NUMBER(10,4)
DCALLOWCOOLINGPOWERBTU  NUMBER(10,4)
DCMAXCOOLINGPOWERBTU    NUMBER(10,4)
ISPBGPASNUMBER  VARCHAR2(30 BYTE)
BANDWIDTHUPLOADMB   NUMBER(10,0)
BANDWIDTHDOWNLOADMB NUMBER(10,0)
IPVERSION   VARCHAR2(30 BYTE)
ISPIPRANGE  VARCHAR2(30 BYTE)

我使用这个非常复杂的SQL查询来选择表中的所有行:

    SELECT a.* 
    FROM (SELECT b.*, rownum rn 
    FROM (select y.componentstatsid, y.name, y.status, y.location, y.type, y.powerCapacityWatt, y.coolingCapacityBTU, y.minAmbientTemp, y.maxAmbientTemp, 
    y.operatingHamidityRange, y.dcAllowedWeightKg, y.dcMaximumWeightKg, y.dcAllowedPowerWatt, y.dcMaxPowerWatt, y.dcAllowCoolingPowerBTU, y.dcMaxCoolingPowerBTU, y.datedeployed, y.dateadded, y.description
    FROM component x, componentstats y where x.componentstatsid = y.componentstatsid and y.componenttypeid = 1000 
    ORDER BY %s %s) b 
    WHERE rownum <= ?) a     
    WHERE rn > ?

问题是我如何简化查询以选择componentstatsid = 35的一行?没有order by

1 个答案:

答案 0 :(得分:1)

试试这个,

SELECT a.* 
        FROM (SELECT b.*, rownum rn 
        FROM (select y.componentstatsid, y.name, y.status, y.location, y.type, y.powerCapacityWatt, y.coolingCapacityBTU, y.minAmbientTemp, y.maxAmbientTemp, 
        y.operatingHamidityRange, y.dcAllowedWeightKg, y.dcMaximumWeightKg, y.dcAllowedPowerWatt, y.dcMaxPowerWatt, y.dcAllowCoolingPowerBTU, y.dcMaxCoolingPowerBTU, y.datedeployed, y.dateadded, y.description
        FROM component x, componentstats y where x.componentstatsid = y.componentstatsid and y.componenttypeid = 1000 and y.componentstatsid=35
        ORDER BY %s %s) b 
        WHERE rownum <= ?) a     
        WHERE rn > ?