15.30 OPEN_REMOTE_DML_CONTEXT Function
This function opens a DML context based for a remote database.
Syntax
function open_remote_dml_context (
    p_server_static_id      in varchar2,
    --
    p_columns               in t_columns               default c_empty_columns,
    p_query_type            in t_query_type,
    --     
    p_table_owner           in varchar2                default null,
    p_table_name            in varchar2                default null,
    p_where_clause          in varchar2                default null,  
    --
    p_sql_query             in varchar2                default null,
    p_plsql_function_body   in varchar2                default null,
    --
    p_with_check_option     in boolean                 default true,
    p_optimizer_hint        in varchar2                default null,
    --
    p_dml_table_owner       in varchar2                default null,
    p_dml_table_name        in varchar2                default null,
    p_dml_plsql_code        in varchar2                default null,
    --
    p_lost_update_detection in t_lost_update_detection default null,
    p_lock_rows             in t_lock_rows             default null,
    p_lock_plsql_code       in varchar2                default null,
    --
    p_sql_parameters        in t_parameters            default c_empty_parameters ) return t_context;Parameters
Table 15-28 OPEN_REMOTE_DML_CONTEXT Function Parameters
| Parameter | Description | 
|---|---|
| 
                               
  | 
                           
                               Static ID of the ORDS REST Enabled SQL Instance.  | 
                        
| 
                               
  | 
                           
                               DML columns to pass to the data source.  | 
                        
| 
                               
  | 
                           
                               DML columns to pass to the data source. Indicates the type of the data source: possible values are:
                                  
                           
  | 
                        
| 
                               
  | 
                           
                               For query type TABLE: Table owner  | 
                        
| 
                               
  | 
                           
                               For query type TABLE: Table name  | 
                        
| 
                               
  | 
                           
                               For query type TABLE: where clause  | 
                        
p_sql_query | 
                           
                               For query type SQL QUERY: the query  | 
                        
| 
                               
  | 
                           
                               For query type PLSQL: the PL/SQL function which returns the SQL query  | 
                        
| 
                               
  | 
                           
                               Specify whether to the "WITH CHECK OPTION" should be added to the data source. If set to "  | 
                        
| 
                               
  | 
                           
                               Optimizer hints to be added to the DML clause  | 
                        
| 
                               
  | 
                           
                               When set, DML statements will be executed against this table  | 
                        
| 
                               
  | 
                           
                               When set, DML statements will be executed against this table  | 
                        
| 
                               
  | 
                           
                               Custom PL/SQL code to be executed instead of DML statements  | 
                        
| 
                               
  | 
                           
                               lost-update detection type. Possible values are:
                                  
                           
  | 
                        
| 
                               
  | 
                           
                               Specify whether to lock the rows for the (short) time frame between the lost update detection and the actual DML statement. Possible values are:
                                  
                           
  | 
                        
| 
                               
  | 
                           
                               Custom PL/SQL code to be used to lock the rows  | 
                        
| 
                               
  | 
                           
                               Bind variables to be used  | 
                        
Example
The following inserts one row into the EMP table on a REST Enabled SQL Service.
declare
    l_columns        apex_exec.t_columns;
    l_context        apex_exec.t_context;
begin
    -- I. Define DML columns
    apex_exec.add_column(
       p_columns        => l_columns,
       p_column_name    => 'EMPNO',
       p_data_type      => apex_exec.c_data_type_number,
       p_is_primary_key => true );
    apex_exec.add_column(
       p_columns        => l_columns,
       p_column_name    => 'ENAME',
       p_data_type      => apex_exec.c_data_type_varchar2 );
    apex_exec.add_column(
       p_columns        => l_columns,
       p_column_name    => 'JOB',
       p_data_type      => apex_exec.c_data_type_varchar2 );
    apex_exec.add_column(
       p_columns        => l_columns,
       p_column_name    => 'HIREDATE',
       p_data_type      => apex_exec.c_data_type_date );
    apex_exec.add_column(
       p_columns        => l_columns,
       p_column_name    => 'MGR',
       p_data_type      => apex_exec.c_data_type_number );
    apex_exec.add_column(
       p_columns        => l_columns,
       p_column_name    => 'SAL',
       p_data_type      => apex_exec.c_data_type_number );
    apex_exec.add_column(
       p_columns        => l_columns,
       p_column_name    => 'COMM',
       p_data_type      => apex_exec.c_data_type_number );
    apex_exec.add_column(
       p_columns        => l_columns,
       p_column_name    => 'DEPTNO',
       p_data_type      => apex_exec.c_data_type_number );
    
    -- II. Open the context object
    l_context := apex_exec.open_remote_dml_context(
       p_server_static_id      => '{remote server static id}',
       p_columns               => l_columns,
       p_query_type            => apex_exec.c_query_type_sql_query,
       p_sql_query             => 'select * from emp where deptno = 10',
       p_lost_update_detection => apex_exec.c_lost_update_none );
    
    -- III. Provide DML data
        
    apex_exec.add_dml_row(
       p_context   => l_context,
       p_operation => apex_exec.c_dml_operation_insert );
    
    apex_exec.set_value(
       p_context         => l_context,
       p_column_position => 1,
       p_value           => 4711 );
    apex_exec.set_value(
       p_context         => l_context,
       p_column_position => 2,
       p_value           => 'DOE' );
    apex_exec.set_value(
       p_context         => l_context,
       p_column_position => 3,
       p_value           => 'DEVELOPR' );
    apex_exec.set_value(
       p_context         => l_context,
       p_column_position => 4,
       p_value           => sysdate );
    apex_exec.set_value(
       p_column_position => 6,
       p_value           => 1000 );
    apex_exec.set_value(
       p_context         => l_context,
       p_column_position => 8,
       p_value           => 10 );
    
    -- IV: Execute the DML statement
        
    apex_exec.execute_dml(
       p_context           => l_context,
       p_continue_on_error => false);
    
     apex_exec.close( l_context );
exception 
    when others then
        apex_exec.close( l_context );
        raise;
            
end;Returns
The context object representing the DML handle.
Parent topic: APEX_EXEC