之前上传的图片会消失,将图片插入Oracle表中

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

我有一个存储过程,我在其中插入或上传一些行。插入时,如果第二次插入同一行,则较早的行将与其他行一起删除。我想在插入新行时保留这些行。

这是查询:

IF TBL_INSERT > 0 THEN
BEGIN
    SELECT COUNT(*) INTO V_PANAROMICIMG_COUNT 
    FROM TBL_VSAT_IMAGE_DETAIL 
    WHERE IMG_TYPE = 'Panaromic' AND IMG_ID = TBL_INSERT;
       
    IF V_PANAROMICIMG_COUNT > 0 THEN
    BEGIN        
        DELETE FROM TBL_VSAT_IMAGE_DETAIL 
        WHERE IMG_TYPE = 'Panaromic' AND IMG_ID = TBL_INSERT;  
    END;        
END IF;  
       
IF P_PANORAMIC_IMAGES IS NOT NULL THEN
BEGIN
    FOR PMULTIFIELDS IN (SELECT REGEXP_SUBSTR(P_PANORAMIC_IMAGES,'[^,]+', 1, LEVEL) AS IMAGES FROM DUAL
                                      CONNECT BY REGEXP_SUBSTR(P_PANORAMIC_IMAGES, '[^,]+', 1, LEVEL) IS NOT NULL
                                    )
    LOOP
        INSERT INTO TBL_VSAT_IMAGE_DETAIL (IMG_ID, IMG_NAME, IMG_TYPE, IMG_UPLOADED_DATE, UPLOADED_BY)
        VALUES (TBL_INSERT, PMULTIFIELDS.IMAGES, 'Panaromic', SYSDATE, P_CREATED_BY);
    END LOOP;
END;
       
END IF;

更新

Table desc: TBL_VSAT_IMAGE_DETAIL

Name              Null?    Type            
----------------- -------- --------------- 
IMG_ID            NOT NULL NUMBER          
IMG_NAME                   NVARCHAR2(2000) 
IMG_TYPE                   NVARCHAR2(100)  
IMG_UPLOADED_DATE          DATE            
UPLOADED_BY                NVARCHAR2(100)  
ID                NOT NULL NUMBER  

示例图像名称为

90.jpg
120.jpg
。因此,如果表由图像名称和
90.jpg
组成,那么它应该更新图像名称或删除并插入具有相同图像名称的新图像
    

oracle stored-procedures
1个回答
0
投票
ID

语句来指定

MERGE
INSERT
UPDATE

注意:您可能不想事先

IF P_PANORAMIC_IMAGES IS NOT NULL THEN MERGE INTO TBL_VSAT_IMAGE_DETAIL dst USING ( SELECT REGEXP_SUBSTR(P_PANORAMIC_IMAGES,'[^,]+', 1, LEVEL) AS image_name FROM DUAL CONNECT BY REGEXP_SUBSTR(P_PANORAMIC_IMAGES, '[^,]+', 1, LEVEL) IS NOT NULL ) src ON ( dst.img_id = TBL_INSERT AND dst.image_name = src.image_name ) WHEN MATCHED THEN UPDATE SET img_type = 'Panoramic', img_uploaded_date = SYSDATE, uploaded_by = P_CREATED_BY WHEN NOT MATCHED THEN INSERT INTO (IMG_ID, IMG_NAME, IMG_TYPE, IMG_UPLOADED_DATE, UPLOADED_BY) VALUES (TBL_INSERT, src.image_name, 'Panaromic', SYSDATE, P_CREATED_BY); END IF; ,因此请尝试删除第一个

DELETE
语句 - 但是您的业务逻辑尚未完全解释,因此您这样做可能是有原因的。

    

© www.soinside.com 2019 - 2024. All rights reserved.