Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8419099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:31:04+00:00 2026-06-10T02:31:04+00:00

I have created a pipelined function which returns a table. I use this function

  • 0

I have created a pipelined function which returns a table. I use this function like a dynamic view in another function, in a with clause, to mark certain records. I then use the results from this query in an aggregate query, based on various criteria. What I want to do is union all these aggregations together (as they all use the same source data, but show aggregations at different heirarchical levels).

When I produce the data for individual levels, it works fine. However, when I try to combine them, I get an ORA-12840 error: cannot access a remote table after parallel/insert direct load txn.

(I should note that my function and queries are looking at tables on a remote server, via a DB link).

Any ideas what’s going on here?


Here’s an idea of the code:

function getMatches(criteria in varchar2) return myTableType pipelined;

…where this function basically executes some dynamic SQL, which references remote tables, as a reference cursor and spits out the results.

Then the factored queries go something like:

with marked as (
  select id from table(getMatches('OK'))
),
fullStats as (
  select    mainTable.id,
            avg(nvl2(marked.id, 1, 0)) isMarked,
            sum(mainTable.val) total
  from      mainTable
  left join marked
  on        marked.id = mainTable.id
  group by  mainTable.id
)

The reason for the first factor is speed — if I inline it, in the join, the query goes really slowly — but either way, it doesn’t alter the status of whatever’s causing the exception.

Then, say for a complete overview, I would do:

select sum(total) grandTotal
from   fullStats

…or for an overview by isMarked:

select sum(total) grandTotal
from   fullStats
where  isMarked = 1

These work fine individually (my pseudocode maybe wrong or overly simplistic, but you get the idea), but as soon as I union all them together, I get the ORA-12840 error 🙁


EDIT By request, here is an obfuscated version of my function:

function getMatches(
    search in varchar2)
  return idTable pipelined
  as
    idRegex     varchar2(20) := '(05|10|20|32)\d{3}';
    searchSQL   varchar2(32767);

    type rc is ref cursor;
    cCluster rc;
    rCluster idTrinity;

    BAD_CLUSTER exception;
  begin
    if regexp_like(search, '^L\d{3}$') then
      searchSQL := 'select distinct null id1, id2_link id2, id3_link id3 from anotherSchema.linkTable@my.remote.link where id2 = ''' || search || '''';    
    elsif regexp_like(search, '^' || idRegex || '(,' || idRegex || || ')*$') then
      searchSQL := 'select distinct null id1, id2, id3 from anotherSchema.idTable@my.remote.link where id2 in (' || regexp_replace(search, '(\d{5})', '''\1''') || ')';
    else
      raise BAD_CLUSTER;
    end if;

    open cCluster for searchSQL;
    loop
      fetch cCluster into rCluster;
      exit when cCluster%NOTFOUND;

      pipe row(rCluster);
    end loop;

    close cCluster;
    return;

  exception
    when BAD_CLUSTER then
      raise_application_error(-20000, 'Invalid Cluster Search');
      return;
    when others then
      raise_application_error(-20999, 'API' || sqlcode || chr(10) || sqlerrm);
      return;
  end getMatches;

It’s very simple, designed for an API with limited access to the database, in terms of sophistication (hence passing a comma delimited string as a possible valid argument): If you supply a grouping code, it returns linked IDs (it’s a composite, 3-field key); however, if you supply a custom list of codes, it just returns those instead.

I’m on Oracle 10gR2; not sure which version exactly, but I can look it up when I’m back in the office 😛

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:31:05+00:00Added an answer on June 10, 2026 at 2:31 am

    To be honest no idea where the issue came from but the simplest way to solve it – create a temporary table and populate it by values from your pipelined function and use the table inside WITH clause. Surely the temp table should be created but I’m pretty sure you get serious performance shift because dynamic sampling isn’t applied to pipelined functions without tricks.

    p.s. the issue could be fixed by with marked as ( select /*+ INLINE / id from table(getMatches(‘OK’))) but surely it isn’t the stuff you’re looking for so my suggestion is confirmed WITH does something like ‘insert /+ APPEND*/’ inside it’.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a function with a signature like this: def tsadd(key: Any,
I have created a function that shows/hides different messages according to a combination of
I have created a custom pipeline component which transforms a complex excel spreadsheet to
Suppose I have objects that have a parent-child relationship like this: public class Node
If you created your pipe like this: pipeline.addLast(decoder, new StringDecoder()); pipeline.addLast(encoder, new StringEncoder()); Is
I have created a table named test2 as follows in SQL Server 2008 R2
I have created a QWidget with a bunch of QToolButtons in it and I
I have created 3 classes as following Ext.mine.TextParent - Inherting from Textfield Ext.mine.child.TextChildA -
I have created some JQuery that will expand a div 'popup' on hover and
I have created a JSP / servlets application running in Tomcat 7. It runs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.