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 &
IMGScoreUsage: Your cursor referencesimage_sigfrom the table, but theIMGScore(1)call isn't properly tied to theIMGSimilarcheck. Also, the way you're structuring the cursor might not pass yourquery_sigvariable correctly. - Unused Variable: You declared an
imagevariable but never used it—this is harmless but clutters your code. - Incomplete
FETCH: YourFETCH 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
- Proper
IMGScoreBinding:IMGScore(1)is now explicitly tied to theIMGSimilarcall in the same query, and aliased to match the variable we're fetching into. - Removed Clutter: The unused
imagevariable is gone to keep the code clean. - Added Safety Checks: We validate that the input image exists and has a valid signature, with custom error messages for easier debugging.
- Completed
FETCHStatement: TheFETCHnow matches the columns selected in the cursor (addobrazekto theINTOclause if you need to retrieve the image data). - 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:
IMGSimilarrelies on pre-computed image signatures stored in theimage_sigcolumn. 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
ORDSYSschema exists and has the necessary privileges. If you're getting "invalid identifier" errors forORDImageSignature, your database might not have Oracle Multimedia installed/enabled. - Adjust Similarity Parameters: The
textparameter ('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
相关产品推荐
相关产品推荐

