An improperly defined UDF may cause memory violations or may lead to a database server failure. Running a UDF outside the database server, in an external environment, eliminates this risk to the server.
Each environment has its own set of APIs for processing arguments and returning values back to the server. The Java external environment, for example, uses the JDBC API.
The system table SYSEXTERNENV stores the information needed to identify and launch each of the external environments.
The system table SYSEXTERNENVOBJECT stores non-Java external objects.
ALTER EXTERNAL ENVIRONMENT environment-name [ LOCATION location-string ]
Once an external environment is set up to be used on the database server, you can then install objects into the database and create stored procedures and functions that make use of these objects within the external environment. Installing, creating, and using these objects, stored procedures, and stored functions is similar to installing Java classes and creating and using Java stored procedures and functions.
COMMENT ON EXTERNAL ENVIRONMENT environment-name IS comment-string
INSTALL EXTERNAL OBJECT object-name-string [ update-mode ] FROM { FILE file-path | VALUE expression } ENVIRONMENT environment-name
COMMENT ON EXTERNAL [ENVIRONMENT] OBJECT object-name-string IS comment-string
REMOVE EXTERNAL OBJECT object-name-string
CREATE PROCEDURE procedure-name(...) EXTERNAL NAME '...' LANGUAGE environment-name CREATE FUNCTION function-name(...) RETURNS ... EXTERNAL NAME '...' LANGUAGE environment-name
Once these stored procedures and functions are created, you can use them like any other stored procedure or function in the database. The database server, when encountering an external environment stored procedure or function, automatically launches the external environment (if it has not already been started), and sends the necessary information to get the external environment to fetch the external object from the database and execute it. Any result sets or return values resulting from the execution are returned as needed.
START EXTERNAL ENVIRONMENT environment-name STOP EXTERNAL ENVIRONMENT environment-name