Skip to Main Content
Feature Request FR-4425
Product Area APIs
Status CLOSED

9 Voters

Add p_file_charset Parameter to APEX_DATA_EXPORT.EXPORT to Control Output Encoding

osvaldo gonzález Public
· Apr 24 2025

Context:
The APEX_DATA_PARSER package provides a p_file_charset parameter, which is extremely useful for parsing files in ANSI (Windows-1252), ISO-8859-1, and other encodings. However, the APEX_DATA_EXPORT package lacks a similar option for defining the character set of the output when exporting data—especially relevant for CSV or text formats.

This limitation can cause issues when generating files for legacy systems or third-party applications that do not support UTF-8. Developers are then forced to use workarounds, such as manual conversion with tools like Notepad++, or custom PL/SQL logic.

Proposal:
Add an optional parameter p_file_charset to the apex_data_export.export procedure to allow explicit control over the output encoding of exported files.

Example Usage (CSV Export with Encoding Control):

DECLARE
    l_context apex_exec.t_context; 
    l_export  apex_data_export.t_export;
BEGIN
    l_context := apex_exec.open_query_context(
        p_location    => apex_exec.c_location_local_db,
        p_sql_query   => 'select * from emp' );
    l_export := apex_data_export.export (
        p_context       => l_context,
        p_format        => apex_data_export.c_format_csv,
        p_file_charset  => 'WE8MSWIN1252'  -- ← Proposed enhancement
    );
    apex_exec.close( l_context );
    apex_data_export.download( p_export => l_export );

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

Benefits:

  • Enables compatibility with systems that require specific encodings (e.g., ANSI or Latin-1).
  • Eliminates the need for external encoding conversion tools or custom PL/SQL workarounds.
  • Ensures consistency with the flexibility already provided by apex_data_parser.
  • Helps deliver a better developer experience and supports broader integration use cases.
This is a great idea! You can already achieve this in APEX today with a slightly different approach.

Comments

Comments

  • edgar.corona OP 11 months ago

    Excelente! Buena mejora

  • edgar.corona OP 11 months ago

    Tremenda mejora

  • carsten.czarski APEX Team OP 11 months ago

    Hmmm … the PL/SQL “workaround” is actually very very simple. I even think that the below code is more expressive, as it becomes crystal-clear that the exported data must be held in a BLOB when a different character set it chosen. But all in all the below code looks very straightforward to me, especially as you're in a PL/SQL procedural context anyway.

        :
        l_export := apex_data_export.export (
            p_context       => l_context,
            p_as_clob       => true,
            p_format        => apex_data_export.c_format_csv );
        apex_exec.close( l_context );
    
        --
        -- use APEX_UTIL.CLOB_TO_BLOB to convert to a BLOB, but respecting the charset
        --
        l_export.content_blob := apex_util.clob_to_blob(
            p_clob          => l_export.content_clob,
            p_charset       => 'WE8MSWIN1252' );
        l_export.as_clob := false;
    
        apex_data_export.download( p_export => l_export );
        :