Skip Headers

# Using a StoredFunctionCall

Previous

Next

You use a `StoredProcedureCall` to invoke stored procedures defined on databases that support them. You can also use a `StoredFunctionCall` to invoke stored functions defined on databases that support them, that is, on databases for which the `DatabasePlatform` method `supportsStoredFunctions` returns `true`.

In general, both stored procedures and stored functions let you specify input parameters, output parameters, and input and output parameters. For more information, see "Using a StoredProcedureCall". However, stored procedures need not return values, while stored functions always return a single value.

The `StoredFunctionCall` class extends `StoredProcedureCall` to add one new method: `setResult`. Use this method to specify the name (and alternatively both the name and type) under which TopLink stores the return value of the stored function.

When TopLink prepares a `StoredFunctionCall`, it validates its SQL and throws a `ValidationException` under the following circumstances:

- If your current platform does not support stored functions. Stored functions are supported only for Oracle.

- If you fail to specify the return type

In Example: Creating a StoredFunctionCall, note that the name of the stored function is set using `StoredFunctionCall` method `setProcedureName`.

Creating a StoredFunctionCall

    StoredFunctionCall functionCall = new StoredFunctionCall();
    functionCall.setProcedureName("CHECK_VALID_EMPLOYEE");
    functionCall.addNamedArgument("EMP_ID");
    functionCall.setResult("FUNCTION_RESULT", String.class);
    ValueReadQuery query = new ValueReadQuery();
    query.setCall(functionCall);
    query.addArgument("EMP_ID");
    Vector args = new Vector();
    args.addElement(new Integer(44));
    String valid = (String) session.executeQuery(query, args);