Informix 不支持那种带有 JOIN 的 UPDATE — 请参阅IBM Informix 11.70 InfoCenter for UPDATE 的语法。当遇到无法识别的语法时,它会给出错误 -201。
如果 Informix 不支持通过连接进行更新,那么如何连接表?无论如何,我稍后必须将此查询转换为 Hibernate。
我现在想进入休眠状态,拜托……你的意思是,你想让我解释你的查询并弄清楚该怎么做?没有表的模式(主键、外键特别相关!)?您肯定必须在 Hibernate 中修复它;我从来没有使用过它。
这是您的查询,重新格式化以使我觉得更好的可读性。
UPDATE a
SET a.export_flag ='Y'
FROM sc_ob_temp_audit AS a
JOIN sc_ob_allocation AS b
ON a.sc_ob_profile_code = b.sc_ob_profile_code
AND a.sc_orig_country= b.sc_orig_country
LEFT JOIN sc_fac_group AS f
ON b.sc_orig_country = f.sc_orig_country
AND b.sc_orig_sf_group_code = f.sc_fac_group_code
LEFT JOIN sc_ob_prod_group AS d -- ON clause missing (but there was a comma here)
JOIN gbl_produce AS e
ON d.sc_prod_cont_code = e.gp_cnt_cd
AND b.sc_orig_country= d.sc_orig_country -- Part of missing ON clause?
AND b.sc_prod_cont_group_code = d.sc_prod_group_code -- Part of missing ON clause?
WHERE a.sc_orig_country ='MY'
AND a.export_flag='N';
对我未经训练的眼睛来说,这看起来像是一种非常复杂的写作方式:
UPDATE sc_ob_temp_audit
SET export_flag = 'Y'
WHERE sc_orig_country = 'MY'
AND export_flag = 'N'
但是,大概所有的连接都做了一些有用的事情,以某种方式限制了更新的行集。所以,我们可以猜测它的意思是这样的:
UPDATE sc_ob_temp_audit
SET export_flag = 'Y'
WHERE sc_orig_country = 'MY'
AND export_flag = 'N'
AND sc_primary_key IN -- Guessed at column; no schema for the DB; no keys!
(SELECT a.sc_primary_key
FROM sc_ob_temp_audit AS a
JOIN sc_ob_allocation AS b
ON a.sc_ob_profile_code = b.sc_ob_profile_code
AND a.sc_orig_country = b.sc_orig_country
LEFT JOIN sc_fac_group AS f
ON b.sc_orig_country = f.sc_orig_country
AND b.sc_orig_sf_group_code = f.sc_fac_group_code
LEFT JOIN sc_ob_prod_group AS d
ON b.sc_orig_country = d.sc_orig_country
AND b.sc_prod_cont_group_code = d.sc_prod_group_code
JOIN gbl_produce AS e
ON d.sc_prod_cont_code = e.gp_cnt_cd
)
如果实际上您在表上没有单列主键,则sc_ob_temp_audit
必须使用带有 EXISTS 的相关子查询:
UPDATE sc_ob_temp_audit
SET export_flag = 'Y'
WHERE sc_orig_country = 'MY'
AND export_flag = 'N'
AND EXISTS
(SELECT * -- It does not matter what you list here in an EXISTS sub-query
FROM sc_ob_temp_audit AS a
JOIN sc_ob_allocation AS b
ON a.sc_ob_profile_code = b.sc_ob_profile_code
AND a.sc_orig_country = b.sc_orig_country
LEFT JOIN sc_fac_group AS f
ON b.sc_orig_country = f.sc_orig_country
AND b.sc_orig_sf_group_code = f.sc_fac_group_code
LEFT JOIN sc_ob_prod_group AS d
ON b.sc_orig_country = d.sc_orig_country
AND b.sc_prod_cont_group_code = d.sc_prod_group_code
JOIN gbl_produce AS e
ON d.sc_prod_cont_code = e.gp_cnt_cd
WHERE a.pk_column1 = sc_ob_temp_audit.pk_column1
AND a.pk_column2 = sc_ob_temp_audit.pk_column2
AND ...
)
我认为这有可能奏效;子查询上的 WHERE 子句应使用a
标识子查询中的审计表,并使用全名标识 UPDATE 语句中的审计表。但是考虑到晚上的时间,我有可能会误会。