Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > Oracle
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #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
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:57 PM.


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