暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Oracle 21c 新特性:数据库多语言引擎 MLE 和原生的 JavaScript 支持

原创 eygle 2020-12-28
1189

Oracle 通过将现代编译器技术和编程语言引入数据处理引擎,加速了数据库对于外部编程语言的支持,Oracle 通过 Walnut项目利用GraalVM,实现了新的编程语言(JavaScript、Python、Java、Ruby、R等)的快速嵌入。

Oracle数据库多语言引擎(MLE)使开发人员能够在他们选择的现代编程语言和开发环境中高效地处理DB数据。因此,MLE是将GraalVM嵌入到Oracle数据库中,专注于(PL/)SQL和客户语言的紧密集成。MLE使用GraalVM与语言无关的Truffle接口,以实现数据库和应用数据类型之间的高效转换,并利用GraalVM Native Image功能进行嵌入。

在数据库中 DBMS_MLE 包实现了这一功能,以下是一个范例:

SQL> l
  1  declare
  2    ctx dbms_mle.context_handle_t;
  3    source clob;
  4    greeting varchar2(100);
  5  begin
  6    ctx := dbms_mle.create_context();
  7    dbms_mle.export_to_mle(ctx, 'YUNHE', '2021');
  8    source := q'~
  9	 var bindings = require("mle-js-bindings");
 10	 var YUNHE = bindings.importValue("YUNHE");
 11	 var greeting = "Hello, " + YUNHE + "!";
 12	 bindings.exportValue("greeting", greeting);
 13    ~';
 14    dbms_mle.eval(ctx, 'JAVASCRIPT', source);
 15    dbms_mle.import_from_mle(ctx, 'greeting', greeting);
 16    dbms_output.put_line('Greetings from MLE: ' || greeting);
 17    dbms_mle.drop_context(ctx);
 18* end;
SQL> /
Greetings from MLE: Hello, 2021!

PL/SQL procedure successfully completed.

dbmsmle.sql 脚本和内容引用如下:


Rem
Rem $Header: rdbms/admin/dbmsmle.sql /main/5 2020/09/20 19:29:40 habansal Exp $
Rem
Rem dbmsmle.sql
Rem
Rem Copyright (c) 2015, 2020, Oracle and/or its affiliates. 
Rem All rights reserved.
Rem
Rem    NAME
Rem      dbmsmle.sql - DBMS package for Multilingual Engine (MLE)
Rem
Rem    DESCRIPTION
Rem      This package provides access to MLE functionality, including dynamic 
Rem      MLE execution.
Rem
Rem    NOTES
Rem      The procedural option is needed to use this package.
Rem      This package must be created under SYS.
Rem      The operations provided by this package are performed under the current
Rem      calling user, not under the package owner SYS.
Rem 
Rem BEGIN SQL_FILE_METADATA API
Rem SQL_SOURCE_FILE: rdbms/admin/dbmsmle.sql
Rem SQL_SHIPPED_FILE: rdbms/admin/dbmsmle.sql
Rem SQL_PHASE: DBMSMLE
Rem SQL_STARTUP_MODE: NORMAL
Rem SQL_IGNORABLE_ERRORS: NONE
Rem SQL_CALLING_FILE: rdbms/admin/catpdbms.sql
Rem END SQL_FILE_METADATA
Rem
Rem    MODIFIED   (MM/DD/YY)
Rem    hkasture    09/15/20 - 31897491: rename eval parameter
Rem    habansal    08/03/20 - adding pragma
Rem    lbraun      06/15/20 - remove unnecessary use of execute immediate
Rem    lbraun      05/29/20 - build on all platforms
Rem    hkasture    04/30/20 - Add get_error_stack
Rem    lbraun      04/27/20 - build only if on LINUX_64
Rem    lbraun      04/27/20 - add get_available_languages, remove JSON support
Rem    lbraun      12/12/19 - made dbms_mle part of db build
Rem    bschlege    11/13/19 - added language object initialization
Rem    lbraun      11/12/19 - re-enable JSON import/export
Rem    lbraun      01/22/19 - refactor DBMS_MLE API, remove execute_snippet
Rem    lbraun      12/21/18 - extending type support
Rem    lbraun      12/07/18 - split body from definition, refactor repl api
Rem    lbraun      10/02/18 - removing uid from all dyn_script calls
Rem    jonmuell    09/14/18 - Adding REPL server
Rem    lbraun      09/11/18 - more dynamic MLE functionality, grant to PUBLIC
Rem    pfender     09/07/18 - Removing create/drop_script related functionality
Rem    ldaynes     02/06/18 - Library create/drop through authid definer rights 
Rem    ldaynes     02/05/18 - Remove obsolete functions
Rem    bschlege    02/01/18 - Add python as language
Rem    ldaynes     01/23/18 - Rename xxxUDFScriptSrc to xxxMLESCriptSrc
Rem    akanduku    01/12/18 - Dynamic MLE Script - move to new package
Rem    akanduku    12/13/17 - Dynamic JS support
Rem    bhossbac    11/16/17 - merge MLE changes from old PT
Rem    mbrantne    11/13/17 - revert grant to MLE_USER
Rem    ldaynes     11/13/17 - Fix library name for debugger api
Rem    mbrantne    11/07/17 - rename walnut to mle in user facing APIs
Rem    ldaynes     11/03/17 - Change api to pass port and path
Rem    ldaynes     10/30/17 - Add api for enabling/disabling debugging
Rem    ldaynes     07/06/17 - Remove parseScript0
Rem    ldaynes     04/10/17 - Fixed exception number used
Rem    akanduku    04/04/17 - Fix error handling
Rem    ldaynes     03/01/17 - Remove load_script_file
Rem    ldaynes     02/09/17 - Check conflict of script name with existing
Rem                           object name (table,procedure, etc.)
Rem    ldaynes     12/08/15 - Add trusted functions for setting walnut runtime
Rem                           options
Rem    ldaynes     11/10/15 - Add trusted function to WalnutUDFAPI
Rem    ldaynes     10/02/15 - Use exception to report errors
Rem    ldaynes     09/29/15 - Support longer metadata for UDF call spec
Rem    ldaynes     09/18/15 - Walnut package for UDF support
Rem    ldaynes     09/18/15 - Created
Rem

@@?/rdbms/admin/sqlsessstart.sql

REM  ************************************************************
REM  THIS PACKAGE MUST NOT BE MODIFIED BY THE CUSTOMER.  DOING SO
REM  COULD CAUSE INTERNAL ERRORS AND CORRUPTIONS IN THE RDBMS.
REM  ************************************************************

REM  ***************************************
REM  THIS PACKAGE MUST BE CREATED UNDER SYS.
REM  ***************************************

Rem ----------------------------------------------------
Rem DBMS_MLE package
Rem ----------------------------------------------------

CREATE OR REPLACE PACKAGE DBMS_MLE AUTHID CURRENT_USER IS
-- Pragma is added for DBMS_ROLLING, it does not change the functionality
-- for the package
PRAGMA SUPPLEMENTAL_LOG_DATA(default, UNSUPPORTED);

$if utl_ident.is_oracle_server <> TRUE $then
  $error 'dbms_mle is not supported in this environment' $end
$end

  ------------
  --  OVERVIEW
  --
  --  This package provides access to  Multilingual
  --  Engine (MLE) functionality, including the execution of dynamic MLE
  --  language code.
  --
  --  The flow of dynamic MLE execution will typically look like this:
  --
  --                     -------------
  --                   | create_context |
  --                     -------------
  --                           |
  --                           |
  --                           v
  --                           |
  --          ---------------->|
  --         |                 |-----
  --         |                 v     |
  --         |          ---------------
  --         |-------->| export_to_mle |
  --         |     ^    ---------------
  --         |     |           |     |
  --         |      -----------|     |
  --         |                 |<-----
  --         |                 |
  --         |                 v
  --         |                ----
  --         |------------->| eval |
  --         |                ----
  --         |                 |
  --         |                 |
  --         |                 v
  --         |         -----------------
  --         |    --->| import_from_mle |
  --         |   |     -----------------
  --         |   |             |
  --         |    -------------|
  --         |                 |
  --          -----------------|
  --                           |
  --                           v
  --                     ------------
  --                   | drop_context |
  --                     ------------
  --
  --  An MLE context encapsulates all runtime state associated with the
  --  execution of MLE language code. For example, this corresponds to
  --  the ECMAScript Execution Context for JavaScript code executed in MLE.
  --
  --  ORA-04153 is raised when any DBMS_MLE function or procedure is called
  --  with an invalid context handle. When this error is raised, an alert is
  --  issued to the alert log and DBMS_MLE becomes inoperable for the life of
  --  the session.

  SUBTYPE context_handle_t IS RAW(16);     /* type for context handle */

  SUBTYPE language_t     IS VARCHAR2(64);  /* type for language identifier */
  TYPE languages_t IS TABLE OF language_t; /* table of language identifiers */

  TYPE error_frame_t IS RECORD
  (
    func VARCHAR2(4000),
    source VARCHAR2(4000),
    line PLS_INTEGER,
    col PLS_INTEGER
  ); /* type for each error frame returned by get_(ctx_)error_stack */

  TYPE error_frames_t IS TABLE OF error_frame_t; /* collection of error frames*/

  /*
     Function: create_context
   
       Create an MLE context for executing code in any MLE language.

       Executing this function requires the EXECUTE DYNAMIC MLE privilege.

     Returns
       A handle that identifies a context within a session for use with
       subsequent calls to MLE functions or procedures (e.g., eval).
    
       An MLE context has a lifetime limited to the session in which it
       was created. When a session is terminated, all the contexts created
       in that session are dropped.

       All MLE contexts created in a session are also dropped when the session
       state is reset (e.g., DBMS_SESSION.RESET_PACKAGE).

       MLE language code will be evaluated using the user, roles,
       and schema that are in effect at the time of context creation.

     The procedure may raise the following errors:
       - ORA-01031 if the caller does not have sufficient privileges
   */
  FUNCTION create_context
  RETURN context_handle_t;

  /*
     Procedure: drop_context
     
       Drop the MLE context identified by the context handle. After executing
       drop_context, the context handle is no longer valid and can not be
       used anymore.

       Executing this procedure requires the EXECUTE DYNAMIC MLE privilege.

     Parameters
       context_handle
         handle to an MLE context

      The procedure may raise the following errors:
       - ORA-01031 if the caller does not have sufficient privileges
   */
  PROCEDURE drop_context(context_handle IN context_handle_t);

   /*
     Procedure: eval

       Executes MLE language code within the context identified by the context
       handle.
       
       Evaluated code has access to all previous modifications to the state of
       the context, including variables defined by code previously evaluated in 
       the context and values exported through export_to_mle(). The evaluated 
       code can also import MLE built-in modules such as the MLE SQL driver.
       
       Executing this procedure requires the EXECUTE DYNAMIC MLE privilege.
       It also requires the EXECUTE ON privilege for the given language
       (e.g., EXECUTE ON JAVASCRIPT).

     Parameters
       context_handle
         handle to an MLE context
       language_id
         language of the provided source code, e.g. 'JAVASCRIPT'
       source
         source code to be executed
       result [optional]
         non-NULL buffer to which the result of the evaluation of the code
         gets appended.

      The procedure may raise the following errors:
       - ORA-01031 if the caller does not have sufficient privileges
       - ORA-04108: if the current container, the current user, or the
         currently enabled roles are different from those in effect at
         the time of context creation.
   */
  PROCEDURE eval(
    context_handle IN context_handle_t,
    language_id    IN language_t,
    source         IN CLOB,
    result         IN OUT NOCOPY CLOB CHARACTER SET ANY_CS
  );

  PROCEDURE eval(
    context_handle IN context_handle_t,
    language_id    IN language_t,
    source         IN VARCHAR2,
    result         IN OUT NOCOPY CLOB CHARACTER SET ANY_CS
  );

  PROCEDURE eval(
    context_handle IN context_handle_t,
    language_id    IN language_t,
    source         IN CLOB
  );

  PROCEDURE eval(
    context_handle IN context_handle_t,
    language_id    IN language_t,
    source         IN VARCHAR2
  );

  /*
     Procedure: import_from_mle
       
       Retrieves the value of the named property from the MLE context and
       converts it to the requested PL/SQL type.

       Executing this procedure requires the EXECUTE DYNAMIC MLE privilege.

     Parameters
       context_handle
         handle to an MLE context
       property_name
         name of the property
       target
         PL/SQL variable into which the retrieved property should be stored

      The procedure may raise the following errors:
       - ORA-01031: if the caller does not have sufficient privileges.
       - ORA-04108: if the current container, the current user, or the
         currently enabled roles are different from those in effect at
         the time of context creation.
       - ORA-04157: if the value of the passed property_name is
         NULL or an empty string.
       - ORA-04205: the value cannot be converted to the target PL/SQL type.
       - ORA-06502: the buffer of the PL/SQL variable is too small for
         holding the retrieved value.
   */
  PROCEDURE import_from_mle(
    context_handle IN context_handle_t,
    property_name  IN VARCHAR2,
    target         OUT NOCOPY BINARY_INTEGER
  );

  PROCEDURE import_from_mle(
    context_handle IN context_handle_t,
    property_name  IN VARCHAR2,
    target         OUT NOCOPY BINARY_DOUBLE
  );

  PROCEDURE import_from_mle(
    context_handle IN context_handle_t,
    property_name  IN VARCHAR2,
    target         OUT NOCOPY BINARY_FLOAT
  );

  PROCEDURE import_from_mle(
    context_handle IN context_handle_t,
    property_name  IN VARCHAR2,
    target         OUT NOCOPY BLOB
  );

  PROCEDURE import_from_mle(
    context_handle IN context_handle_t,
    property_name  IN VARCHAR2,
    target         OUT NOCOPY BOOLEAN
  );

  PROCEDURE import_from_mle(
    context_handle IN context_handle_t,
    property_name  IN VARCHAR2,
    target         OUT NOCOPY CLOB CHARACTER SET ANY_CS
  );

  PROCEDURE import_from_mle(
    context_handle IN context_handle_t,
    property_name  IN VARCHAR2,
    target         OUT NOCOPY DATE
  );

  PROCEDURE import_from_mle(
    context_handle IN context_handle_t,
    property_name  IN VARCHAR2,
    target         OUT NOCOPY DSINTERVAL_UNCONSTRAINED
  );

  PROCEDURE import_from_mle(
    context_handle IN context_handle_t,
    property_name  IN VARCHAR2,
    target         OUT NOCOPY NUMBER
  );

  PROCEDURE import_from_mle(
    context_handle IN context_handle_t,
    property_name  IN VARCHAR2,
    target         OUT NOCOPY TIMESTAMP_TZ_UNCONSTRAINED
  );

  PROCEDURE import_from_mle(
    context_handle IN context_handle_t,
    property_name  IN VARCHAR2,
    target         OUT NOCOPY TIMESTAMP_UNCONSTRAINED
  );

  PROCEDURE import_urowid(
    context_handle IN context_handle_t,
    property_name  IN VARCHAR2,
    target         OUT NOCOPY UROWID
  );

  PROCEDURE import_from_mle(
    context_handle IN context_handle_t,
    property_name  IN VARCHAR2,
    target         OUT NOCOPY VARCHAR2 CHARACTER SET ANY_CS
  );

  PROCEDURE import_from_mle(
    context_handle IN context_handle_t,
    property_name  IN VARCHAR2,
    target         OUT NOCOPY YMINTERVAL_UNCONSTRAINED
  );

  PROCEDURE import_char(
    context_handle IN context_handle_t,
    property_name  IN VARCHAR2,
    target         OUT CHAR CHARACTER SET ANY_CS
  );

  PROCEDURE import_raw(
    context_handle IN context_handle_t,
    property_name  IN VARCHAR2,
    target         OUT RAW
  );

  /*
     Procedure: export_to_mle
       
       Assign the given value, with appropriate conversion, to the named
       property in the MLE context. The property is created if it is not
       already present.

       Executing this procedure requires the EXECUTE DYNAMIC MLE privilege.

     Parameters
       context_handle
         handle to an MLE context
       property_name
         name of the target property to be assigned
       property_value
         value to which the property should be set

      The procedure may raise the following errors:
       - ORA-01031: if the caller does not have sufficient privileges.
       - ORA-04157: if the value of the passed property_name is
         NULL or an empty string.
       - ORA-04108: if the current container, the current user, or the
         currently enabled roles are different from those in effect at
         the time of context creation.
   */
  PROCEDURE export_to_mle(
    context_handle  IN context_handle_t,
    property_name   IN VARCHAR2,
    property_value  IN BINARY_INTEGER
  );

  PROCEDURE export_to_mle(
    context_handle  IN context_handle_t,
    property_name   IN VARCHAR2,
    property_value  IN BINARY_DOUBLE
  );

  PROCEDURE export_to_mle(
    context_handle  IN context_handle_t,
    property_name   IN VARCHAR2,
    property_value  IN BINARY_FLOAT
  );

  PROCEDURE export_to_mle(
    context_handle  IN context_handle_t,
    property_name   IN VARCHAR2,
    property_value  IN BLOB
  );

  PROCEDURE export_to_mle(
    context_handle  IN context_handle_t,
    property_name   IN VARCHAR2,
    property_value  IN BOOLEAN
  );

  PROCEDURE export_to_mle(
    context_handle  IN context_handle_t,
    property_name   IN VARCHAR2,
    property_value  IN CLOB CHARACTER SET ANY_CS
  );

  PROCEDURE export_to_mle(
    context_handle  IN context_handle_t,
    property_name   IN VARCHAR2,
    property_value  IN DATE
  );

  PROCEDURE export_to_mle(
    context_handle  IN context_handle_t,
    property_name   IN VARCHAR2,
    property_value  IN DSINTERVAL_UNCONSTRAINED
  );

  PROCEDURE export_to_mle(
    context_handle  IN context_handle_t,
    property_name   IN VARCHAR2,
    property_value  IN NUMBER
  );

  PROCEDURE export_to_mle(
    context_handle  IN context_handle_t,
    property_name   IN VARCHAR2,
    property_value  IN TIMESTAMP_TZ_UNCONSTRAINED
  );

  PROCEDURE export_to_mle(
    context_handle  IN context_handle_t,
    property_name   IN VARCHAR2,
    property_value  IN TIMESTAMP_UNCONSTRAINED
  );

  PROCEDURE export_urowid(
    context_handle  IN context_handle_t,
    property_name   IN VARCHAR2,
    property_value  IN UROWID
  );

  PROCEDURE export_to_mle(
    context_handle  IN context_handle_t,
    property_name   IN VARCHAR2,
    property_value  IN VARCHAR2 CHARACTER SET ANY_CS
  );

  PROCEDURE export_to_mle(
    context_handle  IN context_handle_t,
    property_name   IN VARCHAR2,
    property_value  IN YMINTERVAL_UNCONSTRAINED
  );

  PROCEDURE export_char(
    context_handle  IN context_handle_t,
    property_name   IN VARCHAR2,
    property_value  IN CHAR CHARACTER SET ANY_CS
  );

  PROCEDURE export_raw(
    context_handle  IN context_handle_t,
    property_name   IN VARCHAR2,
    property_value  IN RAW
  );

  /*
     Procedure: set_stdout
     
       Redirect the stdout stream of all MLE contexts to the given CLOB.
       This applies to all existing contexts and contexts created in the
       future.

       Executing this function requires the EXECUTE DYNAMIC MLE privilege.

     Parameters
       sink
         the CLOB to redirect stdout to.

     Notes:
       Any output that was buffered so far gets flushed to the pre-existing
       sink before redirecting to the new sink.

     The procedure may raise the following errors:
       - ORA-01031 if the caller does not have sufficient privileges
       - ORA-06530 if the sink is NULL
   */
  PROCEDURE set_stdout(
    sink       IN OUT NOCOPY CLOB CHARACTER SET ANY_CS
  );

  /*
     Procedure: set_ctx_stdout
       
     Redirect the stdout stream of the MLE context to the given CLOB.
     
     Executing this function requires the EXECUTE DYNAMIC MLE privilege.

     Parameters
       context_handle
         handle to an MLE context in the current session
       sink
         the CLOB sink to redirect stdout to. Providing a NULL value will result
         in an ORA-06530 error being thrown.
       
     Notes:
       Any output that was buffered so far gets flushed to the pre-existing
       sink before redirecting to the new sink.

     The procedure may raise the following errors:
      - ORA-01031 if the caller does not have sufficient privileges
      - ORA-06530 if the sink is NULL
   */
  PROCEDURE set_ctx_stdout(
    context_handle IN context_handle_t,
    sink           IN OUT NOCOPY CLOB CHARACTER SET ANY_CS
  );

  /*
     Procedure: set_stdout_to_dbms_output
       
       Redirect the stdout stream of all MLE contexts to DBMS_OUTPUT.
       This applies to all existing contexts and contexts created in the
       future.

       Executing this function requires the EXECUTE DYNAMIC MLE privilege.

     Notes:
       Any output that was buffered so far gets flushed to the pre-existing
       sink before redirecting to DBMS_OUTPUT.

     The procedure may raise the following errors:
      - ORA-01031 if the caller does not have sufficient privileges
   */
  PROCEDURE set_stdout_to_dbms_output;

  /*
     Procedure: set_ctx_stdout_to_dbms_output

       Redirect the stdout stream of the MLE context to DBMS_OUTPUT.

       Executing this function requires the EXECUTE DYNAMIC MLE privilege.

     Parameters
       context_handle
         handle to an MLE context in the current session

     Notes:
       Any output that was buffered so far gets flushed to the pre-existing
       sink before redirecting to DBMS_OUTPUT.

     The procedure may raise the following errors:
       - ORA-01031 if the caller does not have sufficient privileges
   */
  PROCEDURE set_ctx_stdout_to_dbms_output(context_handle IN context_handle_t);

  /*
     Procedure: disable_stdout
     
       Disable the stdout stream of all MLE contexts, so that future writes to
       stdout are discarded. This applies to all existing contexts and contexts
       created in the future.

       Executing this function requires the EXECUTE DYNAMIC MLE privilege.

     Notes:
       Any output that was buffered so far gets flushed to the pre-existing
       sink.

     The procedure may raise the following errors:
       - ORA-01031 if the caller does not have sufficient privileges
   */
  PROCEDURE disable_stdout;

  /*
     Procedure: disable_ctx_stdout
     
       Disable the stdout stream of the specified MLE context, so that future
       writes to stdout are discarded.

       Executing this function requires the EXECUTE DYNAMIC MLE privilege.

     Parameters
       context_handle
         handle to an MLE context in the current session
    
     Notes:
       Any output that was buffered so far gets flushed to the pre-existing
       sink.

     The procedure may raise the following errors:
       - ORA-01031 if the caller does not have sufficient privileges

   */
  PROCEDURE disable_ctx_stdout(context_handle IN context_handle_t);

  /*
     Procedure: set_stderr
     
       Redirect the stderr stream of all MLE contexts to the given CLOB.
       This applies to all existing contexts and contexts created in the
       future.

       Executing this function requires the EXECUTE DYNAMIC MLE privilege.

     Parameters
       sink
         the CLOB to redirect stdout to.

     Notes:
       Any output that was buffered so far gets flushed to the pre-existing
       sink before redirecting to the new sink.

     The procedure may raise the following errors:
       - ORA-01031 if the caller does not have sufficient privileges
       - ORA-06530 if the sink is NULL
   */
  PROCEDURE set_stderr(
    sink       IN OUT NOCOPY CLOB CHARACTER SET ANY_CS
  );

  /*
     Procedure: set_ctx_stderr
       
     Redirect the stderr stream of the MLE context to the given CLOB.
     
     Executing this function requires the EXECUTE DYNAMIC MLE privilege.

     Parameters
       context_handle
         handle to an MLE context in the current session
       sink
         the CLOB sink to redirect stderr to. Providing a NULL value will result
         in an ORA-06530 error being thrown.
       
     Notes:
       Any output that was buffered so far gets flushed to the pre-existing
       sink before redirecting to the new sink.

     The procedure may raise the following errors:
      - ORA-01031 if the caller does not have sufficient privileges
      - ORA-06530 if the sink is NULL
   */
  PROCEDURE set_ctx_stderr(
    context_handle IN context_handle_t,
    sink       IN OUT NOCOPY CLOB CHARACTER SET ANY_CS
  );

  /*
     Procedure: set_stderr_to_dbms_output
       
       Redirect the stderr stream of all MLE contexts to DBMS_OUTPUT.
       This applies to all existing contexts and contexts created in the
       future.

       Executing this function requires the EXECUTE DYNAMIC MLE privilege.

     Notes:
       Any output that was buffered so far gets flushed to the pre-existing
       sink before redirecting to DBMS_OUTPUT.

     The procedure may raise the following errors:
       - ORA-01031 if the caller does not have sufficient privileges
   */
  PROCEDURE set_stderr_to_dbms_output;

  /*
     Procedure: set_ctx_stderr_to_dbms_output

       Redirect the stderr stream of the MLE context to DBMS_OUTPUT.

       Executing this function requires the EXECUTE DYNAMIC MLE privilege.

     Parameters
       context_handle
         handle to an MLE context in the current session

     Notes:
       Any output that was buffered so far gets flushed to the pre-existing
       sink before redirecting to DBMS_OUTPUT.

     The procedure may raise the following errors:
       - ORA-01031 if the caller does not have sufficient privileges
   */
  PROCEDURE set_ctx_stderr_to_dbms_output(context_handle IN context_handle_t);

  /*
     Procedure: disable_stderr
     
       Disable the stderr stream of all MLE contexts, so that future writes to
       stderr are discarded. This applies to all existing contexts and contexts
       created in the future.

       Executing this function requires the EXECUTE DYNAMIC MLE privilege.

     Notes:
       Any output that was buffered so far gets flushed to the pre-existing
       sink.

     The procedure may raise the following errors:
       - ORA-01031 if the caller does not have sufficient privileges
   */
  PROCEDURE disable_stderr;

  /*
     Procedure: disable_ctx_stderr
     
       Disable the stderr stream of the specified MLE context, so that future
       writes to stderr are discarded.

       Executing this function requires the EXECUTE DYNAMIC MLE privilege.

     Parameters
       context_handle
         handle to an MLE context in the current session

     Notes:
       Any output that was buffered so far gets flushed to the pre-existing
       sink.
    
     The procedure may raise the following errors:
       - ORA-01031 if the caller does not have sufficient privileges

   */
  PROCEDURE disable_ctx_stderr(context_handle IN context_handle_t);

  /*
    Function: get_ctx_error_stack

      Retrieves the MLE language stack trace for the most recent application
      error in the given execution context.


    Parameters
      ctx
        handle to an MLE context in the current session

    Returns
      A collection of error stack frames, each of type error_frame_t.
      An empty collection is returned if there is no error stack to report.

    The procedure may raise the following errors:
      - ORA-01031 if the caller does not have sufficient privileges
  */
  FUNCTION get_ctx_error_stack(context_handle IN context_handle_t) 
  RETURN error_frames_t;

  /*
     Function: get_available_languages
     
       Returns the set of available MLE languages.

     Returns
       The set of available MLE languages as a table of language identifiers as
       they can be used as an argument to dbms_mle.eval().

    The procedure may raise the following errors:
      - ORA-01031 if the caller does not have sufficient privileges
   */
  FUNCTION get_available_languages RETURN languages_t;
  -- overriding default pragma setting to READ_ONLY 
  PRAGMA SUPPLEMENTAL_LOG_DATA(get_available_languages, READ_ONLY);

END DBMS_MLE;
/
show errors;

CREATE OR REPLACE PUBLIC synonym DBMS_MLE FOR SYS.DBMS_MLE;
show errors;

GRANT EXECUTE ON DBMS_MLE TO PUBLIC;

CREATE LANGUAGE JAVASCRIPT;
show errors;

@?/rdbms/admin/sqlsessend.sql
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论