> I'm trying to create a simple UDF like so:
>
[quoted text clipped - 3 lines]
> NO EXTERNAL ACTION
> RETURN SELECT DEPT_NAME FROM ABC.DEPT WHERE DEPT.USR_ID = USR_ID;
You return a scalar subquery. Try wrapping it into braces:
RETURN (SELECT DEPT_NAME FROM ABC.DEPT WHERE DEPT.USR_ID = USR_ID);
DB2 for LUW is more relaxed here because it supports table functions.
DB2 zOS does not so:
RETURN <expr>
<expr> = [.... | ( <subselect> )]
Cheers
Serge

Signature
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Amit - 18 Apr 2006 20:44 GMT
Thanks for your reply, I made some progress. I tried putting
parenthesis around the SELECT statement but now I get this error:
[IBM][DB2] SQL0214N An expression in the ORDER BY clause in the
following position, or starting with "0" in the "RETURN" clause is not
valid. Reason code = "7". SQLSTATE=42822
This is the exact sql:
CREATE FUNCTION MYSCHEMA.GETUSERDEPT(
USR_ID INTEGER)
RETURNS VARCHAR ( 256 )
LANGUAGE SQL
NO EXTERNAL ACTION
RETURN (SELECT DEPT_NM FROM ABC.DEPT WHERE DEPT.USR_ID = USR_ID);
-Amit
Serge Rielau - 18 Apr 2006 21:24 GMT
Well, we got past the syntax error.. That's good.
Staring at the zOS docs I see:
The expression cannot contain a scalar fullselect.
Bummer...

Signature
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Amit - 18 Apr 2006 21:32 GMT
D'oh! That sucks.
Thanks anyways!
-Amit