c***@cslucas.com.sg
2007-09-27 11:32:34 UTC
How do you retrieve a single values from a select statement and assign it to a variable in a UDF.
Example (not a real business case)
CREATE FUNCTION MYFUNCTION(id INT)
RETURNS INT
LANGUAGE SQL
BEGIN ATOMIC
DECLARE v_age INT;
SELECT S.AGE FROM STAFF S WHERE S.STAFFID = id;
<how to assign S.AGE to v_age so that the value can be returned.>
RETURN v_age;
END
The SELECT statement will always return a single row.
Currently I construct the Select into a SQL string and then pass it to a to a helper UDF that then calls a store procedure. The store procedure then prepare the statement, Open, Fetch and return the required value. I think the overhead doing it like this is quite large. I now got the following error SQL0101N The statement is too long or too complex. SQLSTATE=54001. Not sure if its related.
Thanks!
JJ
Example (not a real business case)
CREATE FUNCTION MYFUNCTION(id INT)
RETURNS INT
LANGUAGE SQL
BEGIN ATOMIC
DECLARE v_age INT;
SELECT S.AGE FROM STAFF S WHERE S.STAFFID = id;
<how to assign S.AGE to v_age so that the value can be returned.>
RETURN v_age;
END
The SELECT statement will always return a single row.
Currently I construct the Select into a SQL string and then pass it to a to a helper UDF that then calls a store procedure. The store procedure then prepare the statement, Open, Fetch and return the required value. I think the overhead doing it like this is quite large. I now got the following error SQL0101N The statement is too long or too complex. SQLSTATE=54001. Not sure if its related.
Thanks!
JJ