Returning the Result of the Last Execution
Use the result
argument to get the outcome of the last
execution.
A variant of the DBMS_MLE.eval()
procedure takes an additional CLOB
argument, result
. Such a call to DBMS_MLE.eval()
appends the outcome of the execution of the last statement in the provided dynamic MLE snippet to the CLOB provided as the
result
parameter.
This option is useful in the implementation of an interactive application, such as a Read-Eval-Print-Loop (REPL) server, to mimic the behavior of a similar REPL session in Node.js.
Example 4-4 Returning the Result of the Last Execution
DECLARE
l_ctx dbms_mle.context_handle_t;
l_snippet CLOB;
l_result CLOB;
BEGIN
dbms_lob.createtemporary(
lob_loc => l_result,
cache => false,
dur => dbms_lob.session
);
l_ctx := dbms_mle.create_context();
l_snippet := q'~
let i = 21;
i *= 2;
~';
dbms_mle.eval(
context_handle => l_ctx,
language_id => 'JAVASCRIPT',
source => l_snippet,
result => l_result
);
dbms_output.put_line('result: ' || l_result);
dbms_mle.drop_context(l_ctx);
EXCEPTION
WHEN OTHERS THEN
dbms_mle.drop_context(l_ctx);
RAISE;
END;
/
Result:
result: 42
Parent topic: Overview of Dynamic MLE Execution