I would like to create and deploy this function in DB2, but I got stuck. Could you please help me?
Cheers,
My function code:
CREATE FUNCTION getID(NameIn VARCHAR(255),versionIn varchar(255))
RETURNS varchar(12)
NOT DETERMINISTIC
LANGUAGE SQL
MODIFIES SQL DATA
NO EXTERNAL ACTION
BEGIN
declare IDOut varchar(12);
set IDOut = (select mID
from mIDHolder
where mName = NameIn and version = versionIn);
IF mappingIDOut IS NULL THEN
set IDOut = Hex(GENERATE_UNIQUE());
insert into mIDHolder VALUES (IDOut,NameIn,versionIn);
END IF;
RETURN IDOut;
END
Here is the mIDHolder Table DDL
CREATE TABLE "V"."MIDHOLDER" (
"MID" VARCHAR(12) FOR SBCS DATA NOT NULL,
"MNAME" VARCHAR(255) FOR SBCS DATA WITH DEFAULT NULL,
"VERSION" VARCHAR(255) FOR SBCS DATA WITH DEFAULT NULL
)
What version of DB2 for zOS are you using?
Looking at the documentation for CREATE FUNCTION on version 10, it states that
MODIFIES SQL DATAis incompatible withALLOW PARALLEL. AndALLOW PARALLELis the default when you specifyNO EXTERNAL ACTION. I suspect this is your problem.On the other hand, looking at the documentation for CREATE FUNCTION on version 9.1, I don’t see
MODIFIES SQL DATAmentioned as an option anywhere. In fact, if you look at what they say underREADS SQL DATAit strongly suggests that statements that modify tables are not allowed in functions at all.In my experience, function and procedure definitions are terribly finicky, error messages are opaque, and there are big differences between DB2 versions.