troubleshooting Question

How to create a function that does a dynamic SQL call?

Avatar of mersis
mersis asked on
DB2
9 Comments1 Solution1359 ViewsLast Modified:
Hi, I am trying to create a function that calls some dynamic SQL and then returns some value, like the example one below. I am using DB2 v9 on Windows.

CREATE FUNCTION halloWorld2()
     RETURNS INTEGER
     DETERMINISTIC NO EXTERNAL ACTION CONTAINS SQL
     READS SQL DATA
     BEGIN ATOMIC
     EXECUTE IMMEDIATE 'SOME DYNAMIC SQL HERE';
     RETURN 1;
   END@

However, I am getting some strange error message. Could someone please help me. I have no clue what I am doing wrong here. The error message is:
DB21034E  The command was processed as an SQL statement because it was not a
valid Command Line Processor command.  During SQL processing it returned:
SQL0104N  An unexpected token "EXECUTE IMMEDIATE" was found following "A      
BEGIN ATOMIC ".  Expected tokens may include:  "<compound_return>".  LINE
NUMBER=6.  SQLSTATE=42601

SQL0104N  An unexpected token "EXECUTE IMMEDIATE" was found following "A
     BEGIN ATOMIC
".  Expected tokens may include:  "<compound_return>              ".
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros