Skip to content

External Subroutines

SQL allows us to define functions that run in external languages, like Java, C#, C, or C++ * These may be more efficient than SQL functions, or be able to perform operations not possible in SQL

Example

CREATE PROCEDURE dept_count_proc(IN dept_name varchar(20)
                                 OUT dept_count integer)
LANGUAGE C
EXTERNAL NAME '/usr/yash/bin/dept_count_proc'

CREATE FUNCTION dept_count(dept_name varchar(20))
RETURNS integer
LANGUAGE C
EXTERNAL NAME '/usr/yash/bin/dept_count'

Security Measures

It is recommended to use sandboxing while calling an external subroutine. Java doesn't allow the subroutine to access or damage other parts of the database code, by wrapping this code in a sandbox.

Alternatively, we can run this external processing in a separate process, and communicate information via IPC methods.