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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:20:23+00:00 2026-06-09T05:20:23+00:00

I have next data: with t as (select 1 as id, ‘1324345’ as amount,

  • 0

I have next data:

with t as
 (select 1 as id, '1324345' as amount, 7821 as code
    from dual
  union all
  select 2 as id, 'current' as amount, 2210 as code
    from dual
  union all
  select 3 as id, 'link' as amount, 2210 as code
    from dual
  union all
  select 4 as id, '56236400' as amount, 6740 as code
    from dual
  union all
  select 5 as id, '45562330' as amount, 5578 as code
    from dual
  union all
  select 6 as id, '34875930' as amount, 5828 as code
    from dual
  union all
  select 7 as id, 'current' as amount, 8520 as code
    from dual
  union all
  select 8 as id, 'link' as amount, 8520 as code
    from dual
  union all
  select 9 as id, '6731347060' as amount, 4740 as code
    from dual
  union all
  select 10 as id, '346008600' as amount, 6575 as code
    from dual)
select * from t

and I want to get the following:

with t as
 (select 1 as id, '1324345' as amount, 7821 as code, 1 as group_id
    from dual
  union all
  select 2 as id, 'current' as amount, 2210 as code, 2 as group_id
    from dual
  union all
  select 3 as id, 'link' as amount, 2210 as code, 2 as group_id
    from dual
  union all
  select 4 as id, '56236400' as amount, 6740 as code, 3 as group_id
    from dual
  union all
  select 5 as id, '45562330' as amount, 5578 as code, 3 as group_id
    from dual
  union all
  select 6 as id, '34875930' as amount, 5828 as code, 3 as group_id
    from dual
  union all
  select 7 as id, 'current' as amount, 8520 as code, 4 as group_id
    from dual
  union all
  select 8 as id, 'link' as amount, 8520 as code, 4 as group_id
    from dual
  union all
  select 9 as id, '6731347060' as amount, 4740 as code, 5 as group_id
    from dual
  union all
  select 10 as id, '346008600' as amount, 6575 as code, 5 as group_id
    from dual)
select * from t

The condition is the value of “amount” field. It may be number or text.

UPD: Expected result:

id  |  amount     |    code   |   group_id
---------------------------------------------
 1  | 1324345     |    7821   |      1 
--------------------------------------------- 
 2  | current     |    2210   |      2 
---------------------------------------------
 3  | link        |    2210   |      2  
---------------------------------------------
 4  | 56236400    |    6740   |      3  
---------------------------------------------
 5  | 45562330    |    5578   |      3  
---------------------------------------------
 6  | 34875930    |    5828   |      3 
---------------------------------------------
 7  | current     |    8520   |      4  
---------------------------------------------
 8  | link        |    8520   |      4  
---------------------------------------------
 9  | 6731347060  |    4740   |      5  
---------------------------------------------
 10 | 346008600   |    6575   |      5  
---------------------------------------------

EDIT: best solution:

with tmain as
 (select t.*,
         decode(isnumeric(Amount),
                lag(isnumeric(Amount)) over(order by id),
                null,
                1) lg
    from t
   order by id)
select id, amount, code, count(lg) over(order by id) group_id from tmain

Where isnumeric function is (based on @valexhome answer):

CREATE OR REPLACE FUNCTION ISNUMERIC (Str IN CHAR) RETURN NUMBER AS
    TMP int;
BEGIN
    if Str is null then
       return(null);
    end if;
    TMP:=TO_NUMBER(Str);
    RETURN (1);
EXCEPTION
    WHEN OTHERS THEN
       RETURN (0);
END;
  • 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-09T05:20:24+00:00Added an answer on June 9, 2026 at 5:20 am

    Here is function ISNUMERIC to define before a query run:

    CREATE OR REPLACE FUNCTION ISNUMERIC (Str IN CHAR) RETURN NUMBER AS
        TMP int;
    BEGIN
        if Str is null then
           return(null);
        end if;
        --if input null return NULL
        TMP:=TO_NUMBER(Str);
        RETURN (1);
    EXCEPTION
        WHEN OTHERS THEN
           RETURN (0);
    END;
    

    And here is the query:

    select id, amount, code, 
    (
    select count(id) 
    from t Tab 
    where tab.id<=t.id
      and 
      isnumeric(Amount)<>nvl(isnumeric((select Amount from t d1 where d1.id=(select max(d.id) from t d where (d.id<Tab.id)))),isnumeric(Amount)-1)
    ) Group_id
    
    from t order by id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 5 HTML select boxes that are all populated with the same data,
I have the following data SELECT T.FEED_TIME from GLRS.FEED_TYPE T 05:00:00 AM 06:00:00 AM
I have encountered a problem when trying to select data from a table in
I have a next code: $parent_priority = $data['priority']; $where = $this->getAdapter()->quoteInto('priority >= ?', $parent_priority);
i have question about YAJLiOS parser... I have next json data : {{ body
I have next form and some ashx <form action=FileUpload.ashx method=POST enctype=multipart/form-data id=frmUpload> <input id=fileupload
What does this mean: Next add reference to: MySql.Data actually I have downloaded mysql
I have a view that I would like to populate data when the next
I have the following problem: list.c struct nmlist_element_s { void *data; struct nmlist_element_s *next;
I have next code, <form id=form1 runat=server> <asp:Label runat=server ID=Label1 EnableViewState=false /> <asp:CheckBox runat=server

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.