我需要更新同一表中其他空白列中的列的所有记录

时间:2015-03-14 09:53:01

标签: sql oracle

我想将B.image_path值更新到同一张表中的A.IMAGE_DESC中,请建议它不正常我是对的:

update images_back_13 A
set A.IMAGE_DESC = (SELECT REGEXP_SUBSTR(B.image_path,'([0-9A-Z])\w+')
                    FROM images_back_13 B
                    where A.IMAGE_ID=B.IMAGE_ID            
                    )
where EXISTS (SELECT REGEXP_SUBSTR(B.image_path,'([0-9A-Z])\w+')
              FROM images_back_13 B
              where A.IMAGE_ID=B.IMAGE_ID            
             )

2 个答案:

答案 0 :(得分:2)

你不需要子选择。只需做

UPDATE  images_back_13 A
SET A.IMAGE_DESC = REGEXP_SUBSTR(A.IMAGE_PATH....)
WHERE REGEXP_SUBSTR(A.IMAGE_PATH....) IS NOT NULL

答案 1 :(得分:0)

您可以使用仅包含 UPDATE 子句的 MERGE 语句。

MERGE INTO images_back_13 a 
USING (SELECT Regexp_substr(image_path, '([0-9A-Z])\w+') image_path 
       FROM   images_back_13) b 
ON (a.image_id= b.image_id) 
WHEN matched THEN 
  UPDATE SET a.image_desc = b.image_path;