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 693979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:48:35+00:00 2026-05-14T02:48:35+00:00

I’m using Oracle object data types to represent a timespan or period. And I’ve

  • 0

I’m using Oracle object data types to represent a timespan or period. And I’ve got to do a bunch of operations that involve working with collections of periods. Iterating over collections in SQL is significantly faster than in PL/SQL.

CREATE TYPE PERIOD AS OBJECT (
  beginning DATE,
  ending    DATE,
  ... some member functions...);

CREATE TYPE PERIOD_TABLE AS TABLE OF PERIOD;

-- what I would like to do: where t.column_value is still a period type
SELECT (t.column_value).range_intersect(period2)
FROM TABLE(period_table1) t
WHERE pa_contains(period_table1, (t.column_value).prev()) = 0
  AND pa_contains(period_table1, (t.column_value).next()) = 1

The problem is that the TABLE() function explodes the objects into scalar values, and I really need the objects instead. I could use the scalar values to recreate the objects but this would incur the overhead of re-instantiating the objects. And the period is designed to be subclassed so there would be additional difficulty trying to figure out what to initialize it as.

Is there another way to do this in SQL that doesn’t destroy my objects?

  • 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-05-14T02:48:35+00:00Added an answer on May 14, 2026 at 2:48 am

    Sorry this was a really tough question. But I finally found a way to do this using some tools I had created earlier. The trick ended up being to iterate over a nested table of number to get each element.

    So the first piece was a series generator that I had shamelessly borrowed from Postgres. There are other ways to generate numbers but this is pretty efficient.

    CREATE OR REPLACE FUNCTION generate_series(
      p_start         NUMBER,
      p_end           NUMBER
    ) RETURN NUMBER_TABLE PIPELINED IS
    BEGIN
      FOR i IN p_start .. p_end LOOP
        PIPE ROW(i);
      END LOOP;
      RETURN;
    END;
    

    And the second piece is the ability to subscript a collection item in SQL.

    CREATE OR REPLACE FUNCTION get_item(p1 PERIOD_TABLE, idx NUMBER)
    RETURN PERIOD IS
    BEGIN
      RETURN p1(idx);
    END;
    

    And finally putting it all together:

    FUNCTION range_intersect(
      p1 PERIOD_TABLE,
      p2 PERIOD_TABLE
    ) RETURN PERIOD_TABLE IS
      v_return    PERIOD_TABLE;
      v_len1      NUMBER(8);
      v_len2      NUMBER(8);
    BEGIN
      v_len1 := p1.last;
      v_len2 := p2.last;
    
      WITH pa1 AS (
        SELECT get_item(p1, column_value) AS period
        FROM TABLE(generate_series(1, v_len1))
      ),
      pa2 AS (
        SELECT get_item(p2, column_value) AS period
        FROM TABLE(generate_series(1, v_len2))
      )     
      SELECT period(start_time, MIN(end_time)) 
      BULK COLLECT INTO v_return
      FROM (
        SELECT (pa1.period).first() AS start_time
        FROM pa1
        WHERE contains(p1, (pa1.period).prev()) = 0
          AND contains(p2, (pa1.period).first()) = 1
    
        UNION ALL
    
        SELECT (pa2.period).first() AS start_time
        FROM pa2
        WHERE contains(p1, (pa2.period).prev()) = 0
          AND contains(p2, (pa2.period).first()) = 1
      ) s_start
      ... snip...
    

    Not easy, but doable.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
i got an object with contents of html markup in it, for example: string
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a French site that I want to parse, but am running into
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I need a function that will clean a strings' special characters. I do NOT

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.