0

我有以下表结构:

HSM

HSM_EXC_CODE    Y   VARCHAR2(60)
HSM_INSTR_CODE  Y   VARCHAR2(60)
HSM_ISIN    Y   VARCHAR2(60)
HSM_VWD_TICKERSYMBL Y   VARCHAR2(80)

TENFORE_EXCHANGE_MAP

HS_MARKET   Y   VARCHAR2(40)
TF_EXCHANGE Y   VARCHAR2(40)

TFV

TFE_ID  Y   NUMBER(22)
TFE_VSE_CODE    Y   VARCHAR2(1000)

不同的 TFE_ID 可以有相同的 TFE_VSE_CODE!我认为这是我在下面的更新查询中所缺少的。

变频调速

VSD_ON  Y   VARCHAR2(160)
VSD_ISIN    Y   VARCHAR2(15)

这些表的连接方式如下:

TENFORE_EXCHANGE_MAP.HS_MARKET   = HSM.HSM_EXC_CODE
TENFORE_EXCHANGE_MAP.TF_EXCHANGE = TFV.TFE_ID

我正在尝试填写 hsm_isin 和 hsm_on 字段。为了达到目标,我试图从hsm.hsm_exc_code. tfv.tfe_vse_code. 但是我做错了,因为我从主题中得到了错误。这是我尝试过的:

 UPDATE hsm
       SET hsm_isin               =
           (SELECT distinct vsd.vsd_isin
              FROM vsd, tfv, TENFORE_EXCHANGE_MAP
             WHERE vsd.vsd_on = hsm.hsm_instr_code || '.' || tfv.tfe_vse_code
                   AND hsm.hsm_exc_code = TENFORE_EXCHANGE_MAP.HS_MARKET
                   AND TENFORE_EXCHANGE_MAP.TF_EXCHANGE = tfv.tfe_id)
          ,hsm.hsm_vwd_tickersymbl =
           (SELECT distinct vsd.vsd_on
              FROM vsd, tfv, TENFORE_EXCHANGE_MAP
             WHERE vsd.vsd_on = hsm.hsm_instr_code || '.' || tfv.tfe_vse_code
                   AND hsm.hsm_exc_code = TENFORE_EXCHANGE_MAP.HS_MARKET
                   AND TENFORE_EXCHANGE_MAP.TF_EXCHANGE = tfv.tfe_id);
4

1 回答 1

0

第一个或第二个子查询中的 key 必须不止一行:尝试类似:

SELECT hsm.hsm_instr_code, 
     count( distinct( vsd.vsd_on ) ) cnt1, 
     count( distinct( vsd.vsd_isin ) ) cnt2
FROM vsd, tfv, TENFORE_EXCHANGE_MAP, hsm
WHERE vsd.vsd_on = hsm.hsm_instr_code || '.' || tfv.tfe_vse_code
AND hsm.hsm_exc_code = TENFORE_EXCHANGE_MAP.HS_MARKET
AND TENFORE_EXCHANGE_MAP.TF_EXCHANGE = tfv.tfe_id
GROUP BY hsm.hsm_instr_code
HAVING count( distinct( vsd.vsd_on ) ) > 1 OR count( distinct( vsd.vsd_isin ) ) > 1

注意:修复多行问题后,您可以将两个子查询合二为一,如下所示:

UPDATE hsm SET ( hsm_isin, hsm.hsm_vwd_tickersymbl ) =
           (SELECT distinct vsd.vsd_isin, vsd.vsd_on
              FROM vsd, tfv, TENFORE_EXCHANGE_MAP
             WHERE vsd.vsd_on = hsm.hsm_instr_code || '.' || tfv.tfe_vse_code
                   AND hsm.hsm_exc_code = TENFORE_EXCHANGE_MAP.HS_MARKET
                   AND TENFORE_EXCHANGE_MAP.TF_EXCHANGE = tfv.tfe_id); 
于 2013-01-09T17:18:06.793 回答