View Single Post
  #2 (permalink)  
Old April 26th, 2004, 05:46 PM
Justin Cave Justin Cave is offline
Authorized User
 
Join Date: Apr 2004
Location: Boise, ID, USA.
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oracle doesn't have a BOOLEAN data type... The basic logic for your function would be

Code:
CREATE OR REPLACE FUNCTION isMgr( p_empno IN NUMBER )
  RETURN VARCHAR2
AS
  cnt NUMBER;
BEGIN
  SELECT COUNT(*)
    INTO cnt
    FROM emp
   WHERE empno = p_empno
     AND job = 'MANAGER';
  IF( cnt != 0 )
  THEN
    RETURN 'true';
  ELSE
    RETURN 'false';
  END IF;
END;
which yields

Code:
SQL> column ismgr(empno) format a15;
SQL> SELECT empno, job, isMgr( empno ) 
  2    FROM emp;

     EMPNO JOB       ISMGR(EMPNO)
---------- --------- ---------------
      7369 CLERK     false
      7499 SALESMAN  false
      7521 SALESMAN  false
      7566 MANAGER   true
      7654 SALESMAN  false
      7698 MANAGER   true
      7782 MANAGER   true
      7788 ANALYST   false
      7839 PRESIDENT false
      7844 SALESMAN  false
      7876 CLERK     false

     EMPNO JOB       ISMGR(EMPNO)
---------- --------- ---------------
      7900 CLERK     false
      7902 ANALYST   false
      7934 CLERK     false
         2           false
        11           false

Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC