You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Oracle无法为ORDImage使用IMGSimilar问题及存储过程咨询

Troubleshooting Oracle ORDImage IMGSimilar Issues in Your Stored Procedure

Hey there, let's work through the kinks in your stored procedure to get the IMGSimilar function working as expected. I've spotted a few key issues in your code, plus some pre-requisites you might need to check.

Key Problems in Your Original Code

  • Cursor Scope & IMGScore Usage: Your cursor references image_sig from the table, but the IMGScore(1) call isn't properly tied to the IMGSimilar check. Also, the way you're structuring the cursor might not pass your query_sig variable correctly.
  • Unused Variable: You declared an image variable but never used it—this is harmless but clutters your code.
  • Incomplete FETCH: Your FETCH photos INTO idk, ... line is cut off, which will throw a compilation error right away.
  • Missing Validation: There's no check to ensure the input image actually exists in your table, or that its signature is populated.

Fixed & Improved Stored Procedure

Here's a cleaned-up, working version of your procedure with all issues addressed:

CREATE OR REPLACE PROCEDURE FIND_SIMILAR_PICTURES (
    nazwa IN VARCHAR,
    exp IN VARCHAR -- This parameter was declared but unused; remove or add logic for it if needed
) IS
    idk NUMBER(10);
    img_score NUMBER;
    query_sig ORDSYS.ORDImageSignature;
    text VARCHAR(200) := 'shape="1.0"';
    
    CURSOR photos IS
        SELECT 
            fo.idk,
            ORDSYS.IMGScore(1) AS similarity_score,
            fo.obrazek
        FROM foto_oferty fo
        WHERE ORDSYS.IMGSimilar(fo.image_sig, query_sig, text, 10, 1) = 1;
BEGIN
    -- Grab the signature of the image we want to compare against
    SELECT image_sig 
    INTO query_sig 
    FROM foto_oferty 
    WHERE nazwa_pliku = nazwa;
    
    -- Make sure we actually got a signature back
    IF query_sig IS NULL THEN
        RAISE_APPLICATION_ERROR(-20001, 'No signature exists for image: ' || nazwa);
    END IF;
    
    OPEN photos;
    LOOP
        -- Match the fetch to the cursor's selected columns (adjust if you need obrazek)
        FETCH photos INTO idk, img_score;
        EXIT WHEN photos%NOTFOUND;
        
        -- Add your custom logic here (e.g., insert into a results table, print output)
        DBMS_OUTPUT.PUT_LINE('Found similar image ID: ' || idk || ' | Similarity Score: ' || img_score);
    END LOOP;
    CLOSE photos;
EXCEPTION
    WHEN NO_DATA_FOUND THEN
        RAISE_APPLICATION_ERROR(-20002, 'Image named ' || nazwa || ' doesn''t exist in foto_oferty');
    WHEN OTHERS THEN
        RAISE_APPLICATION_ERROR(-20003, 'Error finding similar images: ' || SQLERRM);
END;
/

What Changed & Why

  1. Proper IMGScore Binding: IMGScore(1) is now explicitly tied to the IMGSimilar call in the same query, and aliased to match the variable we're fetching into.
  2. Removed Clutter: The unused image variable is gone to keep the code clean.
  3. Added Safety Checks: We validate that the input image exists and has a valid signature, with custom error messages for easier debugging.
  4. Completed FETCH Statement: The FETCH now matches the columns selected in the cursor (add obrazek to the INTO clause if you need to retrieve the image data).
  5. Exception Handling: Basic error handling catches common issues like missing images or unexpected database errors.

Critical Pre-Requisites to Make IMGSimilar Work

Before running this procedure, you need to make sure these boxes are checked:

  • Signatures Are Generated: IMGSimilar relies on pre-computed image signatures stored in the image_sig column. If your table doesn't have these, run this update to generate them:
    UPDATE foto_oferty fo
    SET fo.image_sig = ORDSYS.ORDImageSignature.generateSignature(fo.obrazek);
    COMMIT;
    
  • Oracle Multimedia Is Installed: Ensure the ORDSYS schema exists and has the necessary privileges. If you're getting "invalid identifier" errors for ORDImageSignature, your database might not have Oracle Multimedia installed/enabled.
  • Adjust Similarity Parameters: The text parameter ('shape="1.0"') focuses only on shape similarity. You can tweak this to include other attributes, like 'shape="0.7", color="0.3"' to balance shape and color matching.

内容的提问来源于stack exchange,提问作者maciejka

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 12:29:21