24.34 OPEN_LOCAL_DML_CONTEXT Function
This function opens a DML context based for a local database.
Syntax
FUNCTION OPEN_LOCAL_DML_CONTEXT (
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 24-29 OPEN_LOCAL_DML_CONTEXT Function Parameters
Parameter | Description |
---|---|
|
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_local_dml_context(
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