Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > Oracle
| Search | Today's Posts | Mark Forums Read
Oracle General Oracle database discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Oracle section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old April 22nd, 2004, 10:02 PM
Registered User
 
Join Date: Apr 2004
Location: Portland, Oregon, USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Oracle Boolean Datatype

If I want to create a function that checks if an employee number exists then check if that employee is a manager Returning a BOOLEAN to my procedure . . .

How would I do that, I am learning and everything I seem to try I am getting errors.

Create function (in parm)
return boolean;
IS
VARIABLE
BEGIN
SELECT EMPNO INTO VARIABLE
FROM EMP
WHERE EMPNO = VARIABLE;

IF VARIABLE EQ EMPNO AND JOB NE MGR THEN
RETURN(TRUE)
ELSIF
VARIABLE EQ EMPNO AND JOB EQ MGR THEN
RETURN (FALSE)
ELSIF RETURN (FALSE)





  #2 (permalink)  
Old April 26th, 2004, 05:46 PM
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Oracle to SQL Server DataType Mapping maulik33 SQL Language 0 November 1st, 2007 02:48 PM
help me with boolean array Un33k Pro Visual Basic 2005 1 June 12th, 2007 11:43 AM
Oracle boolean datatype?? schockp Oracle 13 March 1st, 2007 08:24 PM
boolean starlightt Java Basics 2 April 6th, 2006 05:34 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.