17.4 ADD_COLUMN Procedure

This procedure adds a column to the column collection. Column collections can be passed to the EXPORT calls in order to return only a subset of the columns in the export. If an empty column collection (or no column collection) passes, all columns defined in the Query Context are added to the export.

Syntax


PROCEDURE ADD_COLUMN (
  p_columns             IN OUT NOCOPY t_columns,
  p_name                IN            apex_exec.t_column_name,
  p_heading             IN            VARCHAR2                  DEFAULT NULL,
  p_format_mask         IN            VARCHAR2                  DEFAULT NULL,
  p_heading_alignment   IN            t_alignment               DEFAULT NULL,
  p_value_alignment     IN            t_alignment               DEFAULT NULL,
  p_width               IN            NUMBER                    DEFAULT NULL,
  p_is_column_break     IN            BOOLEAN                   DEFAULT FALSE,
  p_is_frozen           IN            BOOLEAN                   DEFAULT FALSE,
  p_column_group_idx    IN            PLS_INTEGER               DEFAULT NULL );

Parameters

Parameter Description
p_columns Column collection.
p_name Column name.
p_heading Column heading text.
p_format_mask Format mask to apply. Useful for XLSX exports where native datatypes are used.
p_heading_alignment Column heading alignment. Valid values are: LEFT, CENTER, RIGHT.
p_value_alignment Column value alignment. Valid values are: LEFT, CENTER, RIGHT.
p_width PDF only. The column width. By default the units are as percentage. The units can be modified by updating the width_units of the print config.
p_is_column_break Whether to use this column for control breaks
p_is_frozen XLSX only. Whether the column is frozen.
p_column_group_idx The index of a column group. If used, this column will part of the column group.

Examples

DECLARE
    l_context               apex_exec.t_context;

    l_export                apex_data_export.t_export;
    l_columns               apex_data_export.t_columns;

BEGIN
    l_context := apex_exec.open_query_context(
        p_location    => apex_exec.c_location_local_db,
        p_sql_query   => 'select * from emp' );

    apex_data_export.add_column(
        p_columns             => l_columns,
        p_name                => 'ENAME',
        p_heading             => 'Name' );

    apex_data_export.add_column(
        p_columns             => l_columns,
        p_name                => 'JOB',
        p_heading             => 'Job' );

    apex_data_export.add_column(
        p_columns             => l_columns,
        p_name                => 'SAL',
        p_heading             => 'Salary',
        p_format_mask         => 'FML999G999G999G999G990D00' );

    l_export := apex_data_export.export (
        p_context               => l_context,
        p_format                => apex_data_export.c_format_html,
        p_columns               => l_columns,
        p_file_name             => 'employees' );

    apex_exec.close( l_context );

    apex_data_export.download( p_export => l_export );

EXCEPTION
    WHEN others THEN
        apex_exec.close( l_context );
        raise;
END;