Get Started

AI, Claude and APEXlang: Fusion Data Extraction (RODS) to ATP as Typed Tables

Fusion Data Extraction (RODS) to ATP with Claude and APEXlang

Difficulty: Advanced  |  Stack: Oracle Fusion Data Extraction, OCI Object Storage, Autonomous Database (ATP), BI Publisher, APEX 26 / APEXlang, Claude

TL;DR

  • Problem: Fusion Data Extraction (RODS) drops zipped CSV files in Object Storage with no data types and no keys. Loading them into a database as-is gives you text tables that nobody wants to query.
  • Finding: Oracle already publishes the missing metadata every quarter (the Business Object Views to BICC mapping). A BI Publisher report on Fusion can join it with the Fusion data dictionary and return types, lengths, scale and primary keys for tens of thousands of attributes.
  • Result: One PL/SQL package in ATP, authenticated with the database resource principal (no stored credentials), loads every Fusion Data Extraction extract into strongly typed tables with Fusion column names. Adding a new extract means adding an object in Fusion. Nothing else changes. The admin app is an APEX app of about a dozen pages written in APEXlang, and most of the code was produced with Claude.

Note: all code is simplified and anonymized. Object names, prefixes, the workspace and the customer are neutral placeholders, and error handling is shortened for readability. Versions used: Fusion 26D, APEX 26.x, Autonomous Database on OCI.

This post describes an approach we built for a customer (who stays anonymous, as in my other posts) to land Oracle Fusion extracts in Autonomous Database. I will show the architecture, the real code patterns, the prompts and iterations that worked with AI, and the places where APEXlang still has rough edges.

Credit: The solution was designed and implemented by Serhii Kononov of the CID team. My role was the architecture direction, the Fusion side and the review. Serhii did the hard engineering work, in the loader, the BIP data model and the APEXlang application, and he drove the AI-assisted workflow described below.

Fusion Data Extraction to ATP architecture: data path and metadata path

1. The challenge with Fusion Data Extraction

Fusion Data Extraction (the RODS service) is a clean way to get Fusion data out without BICC extract jobs or REST paging. You define an extract, select view objects and attributes, and Fusion writes a zip per object into an OCI bucket. Each zip holds a data CSV and a metadata CSV. The metadata CSV lists column names, but it has no data types, no lengths and no keys.

That matters. If you create tables from this, every column becomes VARCHAR2 and you lose date handling, numeric sorting, joins on numeric keys and sane indexing. You also cannot merge an incremental extract, because you do not know the primary key. We wanted the ATP tables to look like Fusion: same column names, same types, same keys.

Extract definition in Fusion Data Extraction with the selected objects and attribute counts
The extract definition in Fusion Data Extraction: each object with the number of selected attributes. Adding an object here is all a new extract needs.

2. Fusion Data Extraction to ATP: architecture in one paragraph

Two independent paths serve the Fusion Data Extraction files. The data path runs every five minutes inside ATP: a scheduler job finds new zips in the bucket, unzips them, stages the CSV, exposes it through an external table and loads a typed table. The metadata path runs when Oracle publishes a new quarterly mapping: the Excel file is uploaded in the APEX admin app, converted to JSON, stored in a Fusion custom object, and a BI Publisher report on Fusion enriches it with the real Fusion data dictionary. The result lands in two reference tables in ATP. The loader consults those tables on every load.

3. Zero stored credentials: resource principal

The first design decision for the Fusion Data Extraction loader was to avoid any credential in the database and any inbound REST endpoint. ATP can talk to Object Storage as itself, using its resource principal. Enable it once as ADMIN, then for the loader schema:

-- as ADMIN
begin
  dbms_cloud_admin.enable_resource_principal();                       -- instance level
  dbms_cloud_admin.enable_resource_principal(username => '&target_schema');
end;
/
grant execute on dbms_cloud to &target_schema;
grant read, write on directory data_pump_dir to &target_schema;
grant create job to &target_schema;
grant execute on dbms_lock to &target_schema;

A dynamic group that matches the database and a policy that lets this group use the bucket are all the IAM you need (see below). Once they exist, every DBMS_CLOUD call simply uses OCI$RESOURCE_PRINCIPAL as the credential name. No wallet, no API key, nothing to rotate.

-- dynamic group (matching rule)
ALL {resource.type = 'autonomousdatabase', resource.id = '<atp_ocid>'}

-- policy
Allow dynamic-group <atp-dg> to manage objects in compartment <compartment>
  where target.bucket.name = '<extract_bucket>'
Allow dynamic-group <atp-dg> to read buckets in compartment <compartment>

4. The scheduler jobs

The whole loader is one package. Two DBMS_SCHEDULER jobs drive it: a poll job every 5 minutes and a nightly cleanup at 02:00. The jobs are created by an idempotent ensure_jobs procedure so a deployment can safely re-run it:

dbms_scheduler.create_job(
  job_name            => C_JOB_POLL,
  job_type            => 'STORED_PROCEDURE',
  job_action          => 'APP_LOADER.POLL_AND_PROCESS',
  number_of_arguments => 4,
  repeat_interval     => 'FREQ=MINUTELY; INTERVAL=5',
  enabled             => false,
  auto_drop           => false,
  comments            => 'Poll bucket, register, load, archive');

-- cleanup
repeat_interval => 'FREQ=DAILY; BYHOUR=2'

The poll procedure is deliberately boring. A run lock prevents overlapping runs, each phase is a separate procedure, and any exception rolls back, releases the lock, logs and re-raises so the scheduler shows the failure:

procedure poll_and_process(...) is
begin
  take_run_lock;            -- DBMS_LOCK, one run at a time
  register_new_files;       -- list bucket, insert new zips into the queue
  evaluate_batches;         -- group files into batches, strict time order
  process_ready_batches;    -- stage + load each batch
  archive_loaded;           -- move loaded zips to the archive prefix
  release_run_lock;
exception
  when others then
    rollback;
    release_run_lock;
    log_error(sqlerrm);
    raise;
end;

Batches are processed in strict time order per entity. An incremental extract must never be applied before an earlier one, so a failed batch blocks later batches of the same entity until someone looks at it. In the admin app that shows up as a FAILED batch with the error and a retry button.

Loader dashboard with scheduler jobs and batches by status
The APEXlang admin app dashboard: the two scheduler jobs (5-minute poll and nightly cleanup) and batches by status.

5. Reading Fusion Data Extraction zips without leaving the database

Each zip is fetched with DBMS_CLOUD, opened with APEX_ZIP, header-checked, and the CSV is written back to a staging prefix without its header row. An external table over the staged file is created on the fly:

l_blob := dbms_cloud.get_object(
            credential_name => 'OCI$RESOURCE_PRINCIPAL',
            object_uri      => l_zip_uri);

l_files := apex_zip.get_files(p_zipped_blob => l_blob);
for i in 1 .. l_files.count loop
  if l_files(i) like '%.csv' and l_files(i) not like '%metadata%' then
    l_csv := apex_zip.get_file_content(l_blob, l_files(i));
    -- header must match the metadata file, otherwise stop the batch
    if not header_matches(l_csv, l_meta) then
      raise_application_error(-20022, 'Header mismatch in ' || l_files(i));
    end if;
    dbms_cloud.put_object(
      credential_name => 'OCI$RESOURCE_PRINCIPAL',
      object_uri      => l_stage_uri,
      contents        => strip_header(l_csv));
  end if;
end loop;

dbms_cloud.create_external_table(
  table_name      => l_ext_table,
  credential_name => 'OCI$RESOURCE_PRINCIPAL',
  file_uri_list   => l_stage_uri,
  column_list     => l_column_list,   -- built from resolved types, section 7
  field_list      => l_field_list,
  format          => json_object('type' value 'csv', 'skipheaders' value 0));

6. The missing metadata: BI Publisher to the rescue

RODS gives names only. Oracle, however, publishes a quarterly Excel file that maps Business Object Views to their BICC database objects (Oracle Support note KA1401). It knows which view attribute comes from which table column. What it does not contain is the physical type. For that we need the Fusion data dictionary, and the only place that has it is Fusion itself.

The pipeline, driven from one APEX page:

  • The user uploads the Excel file on the Fusion Reference page. APEX_DATA_PARSER converts it to JSON.
  • The JSON is stored through the Fusion REST API in a custom object (one record, one large text field).
  • An ESS job schedules a BI Publisher report. The report reads the JSON, joins it with ALL_TAB_COLUMNS for the Fusion schema and returns XML.
  • The page polls the job status and, when it succeeds, downloads the XML output and loads it into ATP.
Quarterly refresh of the Oracle mapping with refresh runs
The quarterly refresh page: upload Oracle’s mapping file, run the Fusion ESS job and reload the reference tables (73,807 structure rows, 1,966 keys).

All Fusion calls use the signed-in user’s token (the same idea as in testing Fusion REST APIs with the bearer token of a browser session). The page triggers each step through an AJAX process, so there is no service account and nothing runs unattended against Fusion. The data model of the report has three data sets. If you develop BIP SQL regularly, the free CID Fusion Query extension makes this loop much faster. The interesting one turns the JSON into rows and finds the physical column, with a fallback to the translation table when the base table does not hold the column:

Why an ESS job and not an online BIP call? To reduce the load on Fusion, and following our design patterns, we never run BI Publisher online through the SOAP service. A synchronous report competes with interactive users, runs into timeouts and cannot be retried cleanly. We submit the report as an ESS job instead: it runs in the batch tier, the page polls the job status and the output is fetched only after the job has succeeded. The same pattern is described in OIC: minimize impact for online users by utilization of ESS job for running BIP queries and Get the BIP PDF Output of an ESS Job.

select s.view_object, s.attribute, s.table_name, s.column_name,
       c.data_type, c.data_length, c.data_precision, c.data_scale,
       case c.data_type
         when 'VARCHAR2' then 'VARCHAR2(' || c.char_length || ' CHAR)'
         when 'NUMBER'   then case when c.data_precision is not null
                                   then 'NUMBER(' || c.data_precision || ',' || nvl(c.data_scale,0) || ')'
                                   else 'NUMBER' end
         else c.data_type
       end                                   as data_type_full,
       case when c.column_name is not null then
              case when c.table_name = s.table_name then 'Y' else 'TL' end
            else 'N' end                      as found_in_db
from   json_table(:p_mapping, '$[*]' columns (
         view_object path '$.viewObject',
         attribute   path '$.attribute',
         table_name  path '$.table',
         column_name path '$.column')) s
left join all_tab_columns c
       on c.owner       = 'FUSION'
      and c.table_name  in (s.table_name, s.table_name || '_TL')
      and c.column_name = s.column_name

The third data set finds primary keys. Fusion constraints are not consistent, so the query tries candidates in order: the primary key constraint by name, the _B and _ALL variants, any primary key on the table, and finally a unique index. The output is a simple XML:

<DATA_DS>
  <G_OBJECTS_STRUCTURE>
    <VIEW_OBJECT>CustomerAccount</VIEW_OBJECT>
    <ATTRIBUTE>PartyId</ATTRIBUTE>
    <DATA_TYPE_FULL>NUMBER(18,0)</DATA_TYPE_FULL>
    <FOUND_IN_DB>Y</FOUND_IN_DB>
  </G_OBJECTS_STRUCTURE>
  <G_TABLE_CONSTRAINTS>
    <VIEW_OBJECT>CustomerAccount</VIEW_OBJECT>
    <PK_COLUMNS>CUST_ACCOUNT_ID</PK_COLUMNS>
  </G_TABLE_CONSTRAINTS>
</DATA_DS>

Triggering and monitoring the job uses the ERP integration REST resources:

POST /ess/rest/scheduler/v1/requests          -- submit the ESS job

GET  /fscmRestApi/resources/latest/erpintegrations?finder=ESSJobStatusRF;requestId=<id>
GET  /fscmRestApi/resources/latest/erpintegrations?finder=ESSJobExecutionDetailsRF;requestId=<id>

On the ATP side the XML is loaded in one transaction. The reference tables are replaced as a whole and the loader refuses an empty result, so a broken report can never wipe the metadata:

procedure replace_reference(p_xml clob) is
begin
  if dbms_lob.getlength(p_xml) < 1000 then
    raise_application_error(-20031, 'Empty reference result, keeping current data');
  end if;

  delete from ref_structure;
  delete from ref_key;

  insert into ref_structure (view_object, attribute, data_type_full, found_in_db)
  select x.*
  from   xmltable('/DATA_DS/G_OBJECTS_STRUCTURE' passing xmltype(p_xml)
           columns view_object    varchar2(200) path 'VIEW_OBJECT',
                   attribute      varchar2(200) path 'ATTRIBUTE',
                   data_type_full varchar2(100) path 'DATA_TYPE_FULL',
                   found_in_db    varchar2(2)   path 'FOUND_IN_DB') x;
  -- same pattern for keys
  commit;
end;

For the current quarter this gave 73,807 structure rows and 1,966 key rows in about 2.5 minutes.

7. Typed tables: how a Fusion Data Extraction column gets its type

When a new entity arrives, the loader resolves a type for every column with a strict priority order: the structure from Fusion first, then a type default specific to the entity, then a global type default, and as a last resort VARCHAR2(4000 CHAR). One UNION ALL query with a priority column does it, and the first match per column wins:

select column_name, data_type
from (
  select upper(replace(business_view_attribute, '.')) column_name,
         data_type_full data_type,
         row_number() over (partition by upper(replace(business_view_attribute, '.'))
                            order by prio) rn
  from (
    select 1 prio, business_view_attribute, data_type_full from ref_structure   where view_object = :entity
    union all
    select 2 prio, column_name, data_type from type_default_entity where entity = :entity
    union all
    select 3 prio, column_name, data_type from type_default_global
  ))
where rn = 1

The result in the admin app: a customer accounts extract with 29 columns, all with their type source shown as STRUCTURE, meaning they came straight from the Fusion data dictionary. The ATP table can be queried with real dates, numbers and joins.

Extracts list with typed ATP tables, last load and row counts
All extracts and their typed ATP tables: last load, job type, data-up-to timestamp, pending and problem batches, approximate rows.
Entity detail with columns typed from the Fusion structure
One entity in detail: key column, and every column typed from the Fusion structure (type source STRUCTURE).

If a later extract changes a column type, the structure sync has a conflict phase: it stops that entity and shows the difference instead of silently altering the table.

8. Loading Fusion Data Extraction files: soft delete and reconciliation

The load itself is the part where I trust nothing. Every row is accounted for. A full extract marks all existing rows as deleted, an incremental extract marks the keys present in the batch, and the batch is inserted with log errors so a bad row cannot kill the load. At the end inserted plus rejected must equal the row count the extract declared, otherwise the whole batch rolls back:

-- soft delete
update typed_table set "##deleted" = 'Y'
 where  l_is_full = 1
    or  key_col in (select key_col from ext_table);

insert into typed_table (...)
select ... from ext_table
log errors into typed_table_err ('batch ' || l_batch_id)
reject limit unlimited;

l_inserted := sql%rowcount;
select count(*) into l_rejected from typed_table_err where ora_err_tag$ = 'batch ' || l_batch_id;

if l_inserted + l_rejected <> l_total_rows then
  rollback;
  raise_application_error(-20060,
    'Reconciliation failed: ' || l_inserted || ' + ' || l_rejected || ' <> ' || l_total_rows);
end if;

Consumers query a view per entity that filters the soft-deleted rows, so history stays available for audit while normal queries see only current data.

9. A new Fusion Data Extraction object needs no code

This is the part customers like most. The loader is generic. To bring a new extract in, you add the object to the extract definition in Fusion. The first load must be a Full extract. The loader creates the typed table, the external table pattern and the view by itself, using the reference tables from section 6.

There is one exception: if the primary key of an object cannot be identified from the Fusion constraints, the admin app has a Settings page with manual entity keys. One row, and the entity continues to load incrementally.

10. The admin app: APEXlang

The admin application has about a dozen pages (dashboard, extracts, batches, entities, columns, type defaults, manual keys, Fusion reference, settings and more). It is written entirely in APEXlang, the text format of APEX 26. The source lives in git next to the database scripts. A page looks like this (simplified, real APEXlang syntax): readable, diffable and easy for an AI to generate or review:

page 20 (
    name: Entities
    alias: ENTITIES

    region entities (
        name: Entities
        type: interactiveReport
        source {
            location: localDatabase
            type: sqlQuery
            sqlQuery:
                ```sql
                select extract_name, table_name, last_loaded_at, data_up_to,
                       pending_batches, problem_batches, key_columns, column_count
                from   app_entity_status_v
                ```
        }
        link {
            linkColumn: customTarget
            target: { page: 21, items: { P21_EXTRACT_NAME: \#EXTRACT_NAME#\ } }
        }
    )
)

The live status page polls the backend through a small dynamic action that runs when the page loads. It is plain JavaScript calling an AJAX process:

executeWhenPageLoads
  function tick() {
    apex.server.process("NEXT_STEP", { pageItems: "#P60_RUN_ID" })
      .then(function (d) { apex.item("P60_STATUS").setValue(d.status);
                           if (!d.done) setTimeout(tick, 3000); });
  }
  tick();

Deployment is a script of three parts: validate, import, check.

apex validate -input apex/app-source
apex import   -input apex/app-source
begin
  apex_application_install.set_workspace('MYWORKSPACE');
  apex_application_install.set_schema('MYSCHEMA');
  apex_application_install.set_auto_install_sup_obj(true);
end;
/
select object_name, status from user_objects where status <> 'VALID';

Supporting objects (tables, packages) are kept as re-runnable install scripts and a post-deploy check lists any invalid object. The app uses Fusion single sign-on and a Fusion job role for authorization, and has English and Hebrew. For another APEX on ATP pattern, see Add Log in with Microsoft by using Entra ID OIDC. The official Oracle APEX documentation covers the APEXlang format.

11. Working with Claude: what actually helped

  • Give it the real artifacts. The Fusion extract metadata, the Oracle mapping file and the exported APEXlang of a working page produced far better results than descriptions.
  • Ask for the architecture first, code second. We agreed on the two-path design and the resource principal before a line of PL/SQL was written.
  • Make it prove results. Claude queried the database through SQLcl MCP (the same setup as in Searching Inside 500+ Integration Flows), compared counts, and fixed its own mistakes against real error messages.
  • Keep review human. Reconciliation, the empty-result guard and the conflict phase exist because we asked “what happens when this goes wrong?” for every step.

12. Gotchas and honest limitations of this Fusion Data Extraction setup

  • APEXlang install scripts for supporting objects have a size limit (32,767 bytes), so we split them with a small build script.
  • Interactive Grid column filter operators must be listed explicitly, otherwise filtering fails with ORA-00936.
  • apex import can report success even if an install script failed. The post-deploy object check is not optional.
  • Relative paths in -input are resolved in a way that surprised us. Use absolute paths in scripts.
  • Remote server names differ between dev, test and prod. We would love environment-neutral remote server definitions in APEXlang so promotion and P2T do not need manual fixes.
  • The Fusion token is tied to the signed-in user, so the metadata refresh cannot be a background job. For a quarterly task we consider this acceptable.

13. Takeaways

  • Oracle publishes more metadata than people use. Combine it with the data dictionary through BI Publisher and Fusion Data Extraction (RODS) files become self-describing.
  • The resource principal removes the whole credential-management topic from this pattern.
  • Run BI Publisher through ESS, not online SOAP. It protects the Fusion instance and gives you status, retry and a clean audit trail.
  • Generic beats clever: because everything is driven by reference tables, a new extract is a configuration change.
  • APEXlang plus an AI assistant is a very productive pair for admin apps. Text sources, validation and git make the loop fast.

If you are planning to bring Fusion Data Extraction output into Autonomous Database, or want to see how APEXlang and AI can speed up your Oracle projects, get in touch with CID.

Table of Contents

Leave a Reply

Your email address will not be published. Required fields are marked *