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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:24:18+00:00 2026-06-02T06:24:18+00:00

So a dilemna, I have an Oracle table called T_GROUP. The records in the

  • 0

So a dilemna, I have an Oracle table called T_GROUP. The records in the table have a unique id (ID) and they are part of a Study, identified by STUDY_ID, so multiple groups can be in the same Study.

CREATE TABLE T_GROUP
(
    "ID" NUMBER(10,0),
    "GROUP_NAME" VARCHAR2(255 CHAR),
    "STUDY_ID" NUMBER(10,0)
)

The existing table has hundreds of records and I now add a new column called GROUP_INDEX:

ALTER TABLE T_GROUP ADD (
 GROUP_INDEX NUMBER(10,0) DEFAULT(0)
);

After adding the column I need to run a script to update the GROUP_INDEX field as such: it should start at 1 and increment by 1 for each group within a study, starting with the lowest ID.

So now I have data as follows:

ID  GROUP_NAME      STUDY_ID    GROUP_INDEX
-------------------------------------------
1   Group 1         3           0
2   Group 2         3           0
3   My Group        5           0
4   Big Group       5           0
5   Group X         5           0
6   Group Z         6           0
7   Best Group      6           0

After the update the group_index field should be as follows:

ID  GROUP_NAME      STUDY_ID    GROUP_INDEX
-------------------------------------------
1   Group 1         3           1
2   Group 2         3           2
3   My Group        5           1
4   Big Group       5           2
5   Group X         5           3
6   Group Z         6           1
7   Best Group      6           2

The update will be run from sqlplus via a batch file. I’ve played around with group by and sub queries but I’m not having much luck, and having never used sqlplus I’m not sure if I can use variables, cursors etc. All tips greatly appreciated!

  • 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-02T06:24:20+00:00Added an answer on June 2, 2026 at 6:24 am

    You should be able to use the analytic function row_number for this

    UPDATE t_group t1
       SET group_index = (SELECT rnk
                            FROM (SELECT id,
                                         row_number() over (partition by study_id
                                                                order by id) rnk
                                    FROM t_group) t2
                           WHERE t2.id = t1.id)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started learning MVVM and having a dilemna. If I have a
I have a dilemna that needs I've been thinking a while but still haven't
I have a dilemma, maybe you can help me. I have a table which
Dilemma: I have a table with several hundred rows in it. I would like
Here's the dilemma: I have a table with rows. I need to count based
I have a dilemma on my hands. After much trial and error, I still
We have a dilemma; developing desktop application using Matisse or Jigloo.. Matisse has this
I have a dilemma that I've encountered before. What's the best in terms of
i have little dilemma, i often use data-bound controls such as Gridview in conjunction
I have a dilema, I want to present to the user a semi-transparent view.

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.