title: Oracle check constraint, call function
body: <p>I am trying to query a table(wishlist_table) to see how many times a member appears in it.</p>
  
  <p>The business rule I am trying to implement is that a member can have at most five items on there wishlist at any one time.</p>
  
  <p>I have been told to do this as a domain constraint so i have created a function to check how many time a membersId appear in the wishlist table but i get an error when calling the from my check constraint</p>
  
  <pre><code>CREATE TABLE WishlistTest
  (
  WishlistId NUMERIC(6) NOT NULL PRIMARY KEY,
  CONSTRAINT chk_Wishlist CHECK (sw3.wishListUpToFiveItems() &gt;= 0 AND sw3.wishListUpToFiveItems() &lt; 5)
  );
  
  
  CREATE OR REPLACE FUNCTION functionWishListUpToFiveItems
  RETURN number IS
  total number(1) := 0;
  BEGIN
  SELECT count(*) into total
  FROM Member
  WHERE MemberId = 1;
  
  IF total &lt; 5 THEN
      return total;
  ELSE RETURN -1;
  END IF;
  END;
  </code></pre>
  
  <p>If someone could tell me a better way of going about this or see what I am doing wrong it would be great</p>