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

  • Home
  • SEARCH
  • 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 9273861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:12:48+00:00 2026-06-18T16:12:48+00:00

I have a table that looks like this: CREATE OR REPLACE TYPE subaccount_nt IS

  • 0

I have a table that looks like this:

 CREATE
     OR
REPLACE
   TYPE subaccount_nt 
     IS TABLE OF VARCHAR2(30);

 CREATE
   TABLE my_table
       ( contract_id   NUMBER(38,0)
       , subaccount    SUBACCOUNT_NT );

Here’s some sample data:

   100          [1000, 1, 2]
   200          [2000, NULL, 999]
   300          [3000]

How can I write a query to return the the third row from the nested table if the 3rd row exists? Here’s the output I’m trying to get:

   100          1
   200          NULL
   300          NULL

Haeving never worked with nested tables before, I’m finding it quite hard to forumate my query. Thanks.

  • 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-18T16:12:49+00:00Added an answer on June 18, 2026 at 4:12 pm

    You can use analytics with a lateral join (unnesting of collection):

    SQL> SELECT contract_id, CASE WHEN rn = 2 THEN val END val
      2    FROM (SELECT t.contract_id, column_value val,
      3                 row_number() over(PARTITION BY t.contract_id ORDER BY 1) rn,
      4                 COUNT(*) over (PARTITION BY t.contract_id) cnt
      5            FROM my_table t,
      6                 TABLE(t.subaccount))
      7   WHERE rn = 2 OR cnt = 1;
    
       CONTRACT_ID VAL
    -------------- ---
               100 1
               200 
               300 
    

    This will not list rows that have an empty subaccount.

    By the way the order is not guaranteed since the nested tables are stored as unordered sets of rows.

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

Sidebar

Related Questions

I have a table that looks like this: CREATE TABLE foobar ( id SERIAL
Hi there I have an SQL table that looks like this: CREATE TABLE IF
I have a schema that essentially looks like this: CREATE TABLE `data` ( `id`
I have a table that looks like this: CREATE TABLE [dbo].[StudentTime] ([StudentTimeID] [int] NOT
I have a table that looks something like this: CREATE TABLE student_results(id integer, name
I have a database table that looks like this: CREATE TABLE IF NOT EXISTS
I have a table that looks like this: CREATE TABLE [Test].[dbo].[MyTest] ( [Id] INT
I have a table cell of type nvarchar(max) that typically looks like this: A03
I have a partitioned table in MySQL that looks like this: CREATE TABLE `table1`
I have a table that looks like this: id value AGA 0.211 AGA 0.433

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.