AIDraft — pending technical review

Run a local LLM (Ollama) inside Oracle APEX

Private, on-prem AI for APEX — call a local Ollama model from PL/SQL so no data leaves the building.

Intermediate1 min readUpdated: 2026-06-09

For sensitive workloads you may not want to send data to a cloud LLM. Ollama runs open models locally; APEX can call it over HTTP from PL/SQL — fully on-prem.

Run Ollama

Install Ollama and pull a small instruct model. It serves an HTTP API on port 11434.

# Download Ollama for Windows from ollama.com, then:
ollama pull llama3.2
ollama serve

Allow the database to make the call

Grant the APEX/parsing schema a network ACL so it can reach the Ollama host.

BEGIN
  DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE(
    host => 'host.docker.internal',
    ace  => xs$ace_type(privilege_list => xs$name_list('http'),
                        principal_name => 'APEX_PUBLIC_USER',
                        principal_type => xs_acl.ptype_db));
END;
/

Call the model from PL/SQL

DECLARE
  l_resp CLOB;
BEGIN
  l_resp := APEX_WEB_SERVICE.make_rest_request(
    p_url         => 'http://host.docker.internal:11434/api/generate',
    p_http_method => 'POST',
    p_body        => '{"model":"llama3.2","prompt":"Summarize order 1001","stream":false}');
  -- parse l_resp JSON ->.response and show it in your page
END;
/

💡 Keep prompts grounded

Pass only the rows the user is allowed to see into the prompt, and validate the model's output before acting on it.

Check your understanding

Check your understanding

0% · 0/2

What's the main reason to run a local LLM?

How does PL/SQL reach Ollama?

Need this delivered?

Request a quote