Problem in createing a simple function

oracle India
  • 14 years ago

    Hai..

    I have got a simple problem for Oracle Guru. I am createing a simple function for checking the gender from the database. In my database i have saved M for Male & F for Female. But when I will display it to the user it should show Male/Female. For that I have create a function... which is given below. I am unable to create the function. Please Help me out

     

    CREATE OR REPLACE FUNCTION FN_GENDER(GTYPE VARCHAR2) RETURN VARCHAR2 IS
    ARGS VARCHAR2;
    BEGIN
     IF GTYPE='M' THEN
       ARGS := MALE;
       RETURN ARGS;
     ELSE
       ARGS := FEMALE;
       RETURN ARGS;
     ENS IF;
    END;









     

    Thanks a lot in advance.

  • 14 years ago

    Try this one:

    CREATE OR REPLACE FUNCTION FN_GENDER(GTYPE VARCHAR2) RETURN VARCHAR2 IS
    ARGS VARCHAR2;
    BEGIN
     IF (GTYPE='M') THEN
       ARGS := 'MALE';
       RETURN ARGS;
     ELSE
       ARGS := 'FEMALE';
       RETURN ARGS;
     END IF;
    END;









    Or this:

    CREATE OR REPLACE FUNCTION GENDER(g VARCHAR2)
       RETURN NUMBER DETERMINISTIC IS
    BEGIN
      IF (g='M') THEN
       RETURN 'MALE';
     ELSE
       RETURN 'FEMALE';
     END IF;
    END;







    I didn’t test them.

  • 14 years ago

    Thanks a lot..

    I have try the following code with a littlt bit changing. & it works fine now..

     

    CREATE OR REPLACE FUNCTION FN_GENDER(GTYPE VARCHAR2) RETURN VARCHAR2 IS
    ARGS VARCHAR2(6);

    BEGIN
     IF (GTYPE='M') THEN
       ARGS := 'MALE';
       RETURN ARGS;
     ELSE
       ARGS := 'FEMALE';
       RETURN ARGS;
     END IF;
    END;










    Thanks again a lot.

  • 14 years ago

    Hai

     

    But when I am trying to create function using if-else-if. It shows me the error

    Here are the codes

    create or replace FUNCTION FN_USTS(GTYPE VARCHAR2) RETURN VARCHAR2 IS
    ARGS VARCHAR2(20);
    BEGIN
     IF (GTYPE='S') THEN
       ARGS := 'Short Listed';
       RETURN ARGS;
     ELSEIF (GTYPE='R') THEN
       ARGS :='Rejected';
       RETURN ARGS;
     ELSE
       ARGS := 'Probable';
       RETURN ARGS;
     END IF;
    END;














    Thanks a lot

  • 14 years ago

    Hi,

    Try this one:

    create or replace FUNCTION FN_USTS(GTYPE VARCHAR2) RETURN VARCHAR2 IS
    ARGS VARCHAR2(20);
    BEGIN
     IF (GTYPE='S') THEN
      ARGS := 'Short Listed';
        RETURN ARGS;
     ELSE
     IF (GTYPE='R') THEN
         ARGS :='Rejected';
         RETURN ARGS;
      ELSE
         ARGS := 'Probable';
         RETURN ARGS;
     END IF;
     END IF;
    END;














  • 14 years ago
    Thanks a lot .

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Walking on water and developing software from a specification are easy if both are frozen.” - Edward V Berard