Unable to resolve what appears to be syntax error trying to build User Defned Function. What am I doing wrong?

Hi all,
I am getting this error when I tried to build the a User defined Function. The code and error message is as follows:
       CODE:
CREATE FUNCTION fnIsVowel
(
                                 c            CHAR(1)
)
RETURNS SMALLINT
SPECIFIC  fnIsVowel
BEGIN ATOMIC
      IF ( c = 'A' ) OR ( c = 'E' ) OR ( c = 'I' ) OR ( c = 'O' ) OR ( c = 'U' ) OR ( c = 'Y' ) THEN
                  RETURN  1;
      END IF;
      RETURN  0;
END

CREATE FUNCTION fnSlavoGermanic
(
                                 Word         CHAR(50)
)
RETURNS SMALLINT
SPECIFIC  fnSlavoGermanic
BEGIN ATOMIC
      
--Catch NULL also...
      IF ( LOCATE('W', Word) > 0 ) OR ( LOCATE('K', Word) > 0 ) OR ( LOCATE('CZ', Word) > 0 ) THEN
            RETURN  1;
      END IF;
      
                   RETURN  0;
END
  ERROR MESSAGE
:
DB2ADMIN.fnIsVowel - Build started.
Create user-defined function returns -104.
DB2ADMIN.fnIsVowel: 20: [IBM][CLI Driver][DB2/LINUX] SQL0104N  An unexpected token "CHAR" was found following "Word    ".  Expected tokens may include:  ".".  LINE NUMBER=20.  SQLSTATE=42601

DB2ADMIN.fnIsVowel - Build failed.
DB2ADMIN.fnIsVowel - Roll back completed successfully.

Can someone point out what is wrong with this statements?

Thanks
             
EnudaAsked:
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.

Kent OlsenData Warehouse Architect / DBACommented:
Hi Enuda,

Are you trying to create both functions at once?  If so, you'll need a statement terminator after the END statement that terminates the first function.

Note that the error message indicates that the parser is still processing code as if it were in the first function.  It hasn't detected the end of the function.

Try creating them one at a time or put a terminator at the end of the function.  It's tempting to try and use the ';' character, but in this case you can't.  It is the separator within the function so you need to choose another character and of course, the client needs to be set to use this other character.  The snippet below shows one way to create both functions at once.


Good Luck,
Kent

CREATE FUNCTION fnIsVowel
(
  c          CHAR(1)
)
RETURNS SMALLINT
SPECIFIC  fnIsVowel
BEGIN ATOMIC
 
   IF ( c = 'A' ) OR ( c = 'E' ) OR ( c = 'I' ) OR ( c = 'O' ) OR ( c = 'U' ) OR ( c = 'Y' ) THEN
      RETURN  1;
   END IF;
   RETURN  0;
END@
 
CREATE FUNCTION fnSlavoGermanic
(
  Word         CHAR(50)
)
RETURNS SMALLINT
SPECIFIC  fnSlavoGermanic
BEGIN ATOMIC
      
--Catch NULL also...
  IF ( LOCATE('W', Word) > 0 ) OR ( LOCATE('K', Word) > 0 ) OR ( LOCATE('CZ', Word) > 0 ) THEN
     RETURN  1;
  END IF;
  RETURN  0;
END@
 
Assuming that you're on *nix, copy the source above into a file.
 
cat db2file | db2 -dt@
quit@
 
And of course, you can also pass the file name via the command line.

Open in new window

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
EnudaAuthor Commented:
Kent,
Thank you for your response...this UDF thingy is driving me nuts...but I look on the bright side, I am learning something along the way. What you have here is a T-SQL translation of a phonetic search algorithm that I am trying to convert to DB2 SQL. Oh yes, I have tried using IBM's Migration Toolkit and a trial version AdventNet SwisSQL T-SQL to DB2 converter. But neither of the product produces anything that the DB2 SP/Function Builder likes... just an all around pain in the neck this weekend...

I am going to try your recommendation see if that helps...

0
EnudaAuthor Commented:
Hi Kent,
I have just tried the snippet and find the same error...this time, it does not even like the first create function...

DB2ADMIN.fnIsVowel - Build started.
Create user-defined function returns -104.
DB2ADMIN.fnIsVowel: 16: [IBM][CLI Driver][DB2/LINUX] SQL0104N  An unexpected token "c  CHAR(1))     RETURNS SMALLINT     LANG" was found following "FUNCTION FNISVOWEL (".  Expected tokens may include:  "<space>".  LINE NUMBER=16.  SQLSTATE=42601

DB2ADMIN.fnIsVowel - Build failed.
DB2ADMIN.fnIsVowel - Roll back completed successfully.

0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

EnudaAuthor Commented:
Hi Kent,
I have just tried the snippet using the command editor instead of the Development Center and the code compiled successfully. So, you were right, I had to change the statement termination character for it to work. So, it seems that my Development center features is not working properly. I will deal with that later. Now, on to the rest of my code...wish me luck
0
EnudaAuthor Commented:
The @ Statement terminator solved that problem for me...thanks.
0
Kent OlsenData Warehouse Architect / DBACommented:

Hi Enuda,

Good Luck.  :)

I avoid the Command Center when I can.  For some things, like creating Federated object, it's the easiest, but for most development it's clearly not.

The successor product, the Developer Workbench (released with UDB version 9) is the tool that IBM should have distributed all along.  It's an excellent product.

In the meantime, I usually use the Aqua Data Studios client for most things.  It provides a common interface for my IBM, Oracle, and MySQL databases, though it doesn't have a good Procedure Editor, either.

Again, good luck,
Kent
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
DB2

From novice to tech pro — start learning today.