Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Check constraint

abdujaparovOct 20 2008 — edited Oct 20 2008
Hi,

i try to implement a check constraint.
I have written it in this way:
ALTER TABLE SPR_KLERS_IGA_APPO
  ADD CONSTRAINT SPR_KLERS_IGA_APPO_CEG CHECK (
    (SELECT CHECK_IGA_OBJ(SPR_KLERS_IGA_APPO.CODICE_ENTE_GARANTE)
       FROM DUAL) > 0
)
The function named CHECK_IGA_OBJ is
FUNCTION FIN.CHECK_IGA_OBJ(COD_GAR IN VARCHAR2) RETURN NUMBER
IS
    IGA_RESULT NUMBER;
    IEM_RESULT NUMBER;
    BEGIN
         SELECT COUNT(*)
           INTO IGA_RESULT
           FROM SPR_KLERS_IGA_GARANTE
          WHERE ID = COD_GAR;       
         
         SELECT COUNT(*)
           INTO IEM_RESULT
           FROM SPR_KLERS_IEM
          WHERE EMICOD = COD_GAR;
          
          IF IGA_RESULT > IEM_RESULT THEN
             RETURN IGA_RESULT;
          ELSE
             RETURN IEM_RESULT;
          END IF;
          
    END CHECK_IGA_OBJ;
When I try to execute the constraint code I receive the following error:
ORA-02251: subquery not allowed here
.

I would assign this type of constraint to the column 'SPR_KLERS_IGA_APPO.CODICE_ENTE_GARANTE'
because the values, for this column, are contained in two columns of two tables.
My goal is the implementation of an integrity constraint.

Is this the correct way to face the problem?

byebye

Edited by: Abdujaparov on Oct 20, 2008 2:13 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 17 2008
Added on Oct 20 2008
4 comments
663 views