Function is not working

Hi experts.
This function is not working.
ssn is soscial security number.

CREATE OR REPLACE FUNCTION test.tel_to_apply (ssn varchar2(9))
   RETURN varchar2
IS
   myssn   varchar2(9);

BEGIN
   myssn := ssn

   IF myssn in (select * from test.aplicar)
   THEN
      myssn := to_char(to_number(ssn)+1);
   end if;
   RETURN myssn;
END;                                                            
/

RETURN myssn;
Error at line 13
ORA-00900: invalid SQL statement
LVL 8
LindaCAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sdstuberCommented:
>>> IF myssn in (select * from test.aplicar)

that's not legal syntax,  plus you're missing a semicolon on the preceding line

try something like this...


CREATE OR REPLACE FUNCTION test.tel_to_apply(ssn VARCHAR2(9))
    RETURN VARCHAR2
IS
    myssn    VARCHAR2(9);
    v_exists INTEGER;
BEGIN
    myssn := ssn;

    SELECT COUNT(*)
      INTO v_exists
      FROM (SELECT *
              FROM test.aplicar
             WHERE your_column = myssn AND ROWNUM = 1);

    IF v_exists = 1
    THEN
        myssn := TO_CHAR(TO_NUMBER(ssn) + 1);
    END IF;

    RETURN myssn;
END;
/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DavidSenior Oracle Database AdministratorCommented:
Your subordinate select returns every column and every row in the table -- assuming test.aplicar represents the schema.table per Oracle convention.  I might approach this as doing the select and then exiting the procedure if NO_RECORDS_FOUND.
0
LindaCAuthor Commented:
Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.