is [8i] possible to add a line number that increases after a column?

I have the following the sample table and data:
CREATE TABLE ords
(     ord_nbr          NUMBER     NOT NULL
,     step_nbr     NUMBER
,     area_code     VARCHAR2(2)
     CONSTRAINT caln_pk PRIMARY KEY (ord_nbr)
);

INSERT INTO     ords
VALUES (1,1,'A1');
INSERT INTO     ords
VALUES (1,2,'B1');
INSERT INTO     ords
VALUES (1,3,'B1');
INSERT INTO     ords
VALUES (1,4,'B2');
INSERT INTO     ords
VALUES (1,5,'A1');
INSERT INTO     ords
VALUES (1,6,'C1');
INSERT INTO     ords
VALUES (1,7,'X1');
INSERT INTO     ords
VALUES (1,8,'C2');
INSERT INTO     ords
VALUES (1,9,'C2');
INSERT INTO     ords
VALUES (1,10,'Z9');
The results that I want to look like:
ORD_NBR     STEP_NBR     AREA_CODE     SEQ_NBR
-----------------------------------------------
1     1          A1          1
1     2          B1          2
1     3          B1          2
1     4          B2          3
1     5          A1          4
1     6          C1          5
1     7          X1          6
1     8          C2          7
1     9          C2          7
1     10          Z9          8
I want only the SEQ_NBR to increase if the area changes... I wonder if there is that I need to transform that into a hierarchical sort query, so that there is a relationship between step 1 and step 2, step 2 and step 3, etc.

I played a bit with ROW_NUMBER, RANK, DENSE_RANK, but I can't understand how to add this column SEQ_NBR...

Any suggestions?

Hello

That's what you asked for:

SELECT     ord_nbr, step_nbr, area_code
,     SUM (new_grp) OVER ( PARTITION BY  ord_nbr
                              ORDER BY          step_nbr
                  ) AS seq_nbr
FROM     (
         SELECT  ord_nbr, step_nbr, area_code
         ,         CASE
                WHEN  area_code = LAG (area_code) OVER ( PARTITION BY  ord_nbr
                                                           ORDER BY       step_nbr
                                        )
                THEN  0
                ELSE  1
                  END          AS new_grp
         FROM    ords
     )
ORDER BY  ord_nbr
,            step_nbr
;

I'm guessing what role ord_nbr plays in this problem.

user11033437 wrote:
I have the following the sample table and data:

CREATE TABLE ords
(     ord_nbr          NUMBER     NOT NULL
,     step_nbr     NUMBER
,     area_code     VARCHAR2(2)
     CONSTRAINT caln_pk PRIMARY KEY (ord_nbr)
);

Part of your constraint PRIMARY KEY be lost? It seems that ord_nbr is not separate, so it cannot be a primary key by itself.

... I wonder if there is that I need to transform that into a hierarchical sort query, so that there is a relationship between step 1 and step 2, step 2 and step 3, etc.

I played a bit with ROW_NUMBER, RANK, DENSE_RANK, but I can't understand how to add this column SEQ_NBR...

You have some very good instincts!
I think you could do this as a CONNECT BY query, but I don't think it would be any easier or more effective. It is good to keep CONNECT BY in mind and recognize that CONNECT BY is a possible solution for this kind of problem.
Of course, this looks like a problem DENSE_RANK. That's what I have trid first, but I couldn't find a solution more simple than the one above.

Thanks for posting the CREATE TABLE and INSERT. It is very useful.
If you are using Oracle 8.1, it is very important. You must mention your version in the message body and not just hope that someone notice "8i" in the line object or tags.

Published by: Frank Kulash, February 18, 2010 14:22

Tags: Database

Similar Questions

  • Is it possible to add a line attribute?

    Hello

    I need a add a new attribute to a table row, but I can't find a way to do it. I already added some attributes to the document and page elements by adding a new persistent interface to kDocBoss and kSplineItemBoss respectively and it management in the provider. For text attributes, I added a new boss and he succeeded in the provider thanks to:

    / * Text attribute script providers must use the TextAttrScriptUtility

    class to access and modify text attributes.  This provider shows

    How to use this utility.  Suppliers third text attribute script should

    Follow this same pattern.

    */

    scoped_ptr < TextAttrScriptUtility > tasu.

    I can't use TextAttrScriptUtility for lines and seems it isn't a boss for a line that I can use to add a new interface, like I did for document elements and page. In addition the IScript object * I get in the method AccessProperty is a kScriptCellRefBoss without database (: GetUIDRef gives me an empty object).
    Is it possible to add an attribute of row with the SDK?

    I use SDK 9.0/10/11/11.2

    Thanks in advance

    Massimo

    I have foiund the solution on my own using ITableCommands and ItableAttrAccessor, I put a sample of the script provider if someone will have the same question:

    ErrorCode PBTaggerIDMLRowScriptProvider::AccessProperty_PBCycleAttr(IScriptRequestData* data, IScript* script)

    {

    Result ErrorCode = kSuccess;

    {}

    InterfacePtr cellRef (script, UseDefaultIID());

    GridArea grid;

    cellRef-> GetRange (grid);

    RowRange range = grid. GetRows();

    InterfacePtr tableModel (cellRef-> QueryModel());

    If (data-> {IsPropertyGet())}

    Download

    ScriptData outData;

    InterfacePtr tableAcc (tableModel, UseDefaultIID());

    DataWrapper listA = tableAcc-> QueryRowOverrides (start);

    const AttributeBossList * list = listA.get ();

    InterfacePtr attr (static_cast< const="" ipbtaggerrowattrcycle*="">(list of-> QueryByClassID (kPBTaggerRowAttrCycleBoss, IPBTaggerRowAttrCycle::kDefaultIID)));)))

    If (! attr)

    break;

    WideString cycle = attr-> Get();

    outData.SetWideString (cycle);

    data-> AppendReturnData (script, p_PBTaggerCycleRowData, outData);

    }

    else {}

    PUT

    ScriptData scriptData;

    If (data-> {HasRequestData (p_PBTaggerCycleRowData))}

    result = data-> ExtractRequestData (p_PBTaggerCycleRowData, scriptData);

    WideString cycle;

    result = scriptData.GetWideString (cycle);

    Assert(result == kSuccess);

    If (result! = kSuccess)

    break;

    InterfacePtr attr (: CreateObject2< ipbtaggerrowattrcycle="">(kPBTaggerRowAttrCycleBoss));

    Assert (attr);

    attr-> Set (cycle);

    InterfacePtr tableMod (tableModel, UseDefaultIID());

    List of AttributeBossList;

    list. ApplyAttribute (attr, kPBTaggerRowAttrCycleBoss);

    const AttributeBossList * list_const = &list;

    tableMod-> ApplyRowOverrides (range, list_const);

    }

    }

    } While (kFalse);

    return the result;

    }

  • How to automatically add the line number in the query

    Hello

    Can anyone please glimpses me the path to achieve this?

    I want to write a query that will search the record based on the line number in the result set.
    Let's say I have 500 rows in the employee table, but I want to put a condition on request where will see record only between 100 to 200 line number in the result set.



    Thank you
    Madam.

    It is wrong to say that look for the lines between ROWNUM 100 to 200 unless you define a column of lines must be ordered.

    Oracle does not guarantee that the lines will be be returned in the same order if you run the query several times without defining the ORDER BY clause.

    So first decide on what columns you want to order the files and then use the rownum to assign the line number and then get the records you want.

    something like that

    SQL>SELECT *
      2    FROM ( SELECT e.*
      3                 ,ROW_NUMBER() OVER (ORDER BY sal)  row_num
      4             FROM emp  e
      5         )
      6   WHERE row_num BETWEEN 5 AND 10;
    
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO    ROW_NUM
    ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- ----------
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30          5
          7934 MILLER     CLERK           7782 23-JAN-82       1300                    10          6
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30          7
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30          8
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10          9
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30         10
    
    6 rows selected.
    
    SQL>
    

    Concerning
    Arun

  • Possible to add the line to OBIEE answers

    Hello
    I have a dimension D1, F1,

    D1 F1
    A 10
    B 20
    c 30
    When I'm generating a report in fact I get three rows and, I have to get 4th place as d = b + c output as follows,

    D1 F1
    A 10
    B 20
    c 30
    -----------------
    d 50

    is it possible to OBIEE answers?

    Thanks in advance?

    Published by: Maya on January 9, 2012 21:24

    Yes... Pivot of use see point calculated to calculate B + C

  • When you try to add the option "number of words" for the column headings in the window my documents, the number of words doesn't quite show

    For school, I need to take a screenshot of the header of column of count of Word showing under my documents.
    When I added the option to account for Word for column headers and clicked it twice so that the word count
    show for files listed, nothing shows up.

    Any help with this would be greatly appreciated!

    Hello

    Welcome to the Microsoft Community and thanks for posting the question.

    According to the description, you are having problems with the number of words not displaying do not.

    What is the format of the Document?

    Number of words is a feature that is available only for Documents Word from Microsoft.

    http://Office.Microsoft.com/en-in/Word-Help/count-the-number-of-words-in-a-document-HA010368775.aspx

    Meet us if you encounter problems with the number of words or any other issue of Windows, and we would be happy to help you.

    Good day!

    Hope this information helps.

  • Is it Possible to add a text form that will be sent WITH a payment?

    I want to add to a Web site, a text shape. People will write the details in this document,

    and after they click submit, they will be redirected to

    a paypal payment page.

    I don't think I understand your question, because it seems that you did it yourself. Simply create a form, then send it after submit option to the PayPal url you need to change. but you should know that the two are not related and with form of muse, you cannot link the two. If both should be linked I would use rather a third party such as service

    https://sellfy.com/

  • I have a version of adobe reader pro download - it keeps telling me the demo has expired and I have to add a serial number that I don't have...

    any help much appreciated.

    Adobe READER is a free program... you actually have the ACROBAT program?

    Cloud Plans https://creative.adobe.com/plans

    Your subscription to cloud shows correctly on your account page?

    If you have more than one email, you will be sure that you use the right Adobe ID?

    https://www.adobe.com/account.html for subscriptions on your page from Adobe

    If Yes

    Some general information for a subscription of cloud

    Cloud programs don't use serial... numbers you, connect you to your cloud account paying to download & install & activate... you may need to sign out of the cloud and restart your computer and log into the cloud for things to work

    Sign out of your account of cloud... Restart your computer... Connect to your paid account of cloud

    -Connect using http://helpx.adobe.com/x-productkb/policy-pricing/account-password-sign-faq.html

    -http://helpx.adobe.com/creative-cloud/kb/sign-in-out-creative-cloud-desktop-app.html

    -http://helpx.adobe.com/x-productkb/policy-pricing/activation-network-issues.html

    -http://helpx.adobe.com/creative-suite/kb/trial--1-launch.html

    -ID help https://helpx.adobe.com/contact.html?step=ZNA_id-signing_stillNeedHelp

    -http://helpx.adobe.com/creative-cloud/kb/license-this-software.html

    If no

    This is an open forum, Adobe support... you need Adobe personnel to help

    Adobe contact information - http://helpx.adobe.com/contact.html

    -Select your product and what you need help with

    -Click on the blue box "still need help? Contact us. "

  • is it possible to add a footer page number to a PDF in reader

    I use Adobe Reader XI on a MacBook Pro.  I created documents in Word and Excel and then them scanned in pdf format, bringing together in a single pdf file in order to present the data in order.  Is it possible to add a page number footer?

    Hi cathmint,

    You will need Acrobat free trial download Adobe Acrobat application | Acrobat Pro DC to add the header & foot Add headers, footers and in format PDF, Adobe Acrobat Bates numbering.

    Kind regards
    Nicos

  • Display the line number in TextEdit

    I'm trying to twist around the preferences and browsing the web, if there is a way to display the line numbers in the TextEdit application. I could not find, how is it possible to display the line number?

    OS: Mac OS X El Capitan

    No, but the free TextWrangler has add/remove line numbers in the text menu, you could copy of TE & paste in TW.

  • Add bus lines?

    Hello

    I was wondering if it is possible to add buses lines (with verification by Apple of course) as public transport network which has 22 lines around my town, but the Maps app informs he...

    Sincerely

    Hello

    It is a community of user-oriented support.

    If you want to send a feature request to Apple, you can do it here:

    https://www.Apple.com/feedback/iPhone.html

  • Error handling: to display the line number tht erored out with error message

    Hello

    I'm trying to update several lines at once and for some lines are error-ed out due to the failure of the validation. It's giving the correct error message does not display do not line number what error-ed out.
    I tried with OARowValException, such as specified in the guide of the OA-developer to add the line number in the error message:

    After using this it is show the number of line 1, which either the line it wrong:

    Error in line 1 - the Start Date cannot be later than the Ending Date.
    Error in line 1 - the Start Date cannot be later than the Ending Date.

    In fact I've updated the line-2, 3 but it gives as 1st row.

    Here's the code to add the line numbers for the error message, I added.
    ========================
    try {}
    throw new OARowValException (viewObject.getName)
    voRowObject.getKey ().
    "PA".
    Error_Message);
    }
    catch (System.Exception e)
    {
    exList.add (e);
    }

    If (exList.size () > 0) {}
    OARowValException.raiseBundledOAException (exList);
    }
    ==========================

    Code the developer guide OA that I follow:

    throw (OARowValException) new
    getViewObject () .getFullName (), / / View full name use object
    getKey(), / / primary key line
    "DAMIEN", / / message name abbreviated enforcement
    "ATTR_EXCEPTION"); name of the message
    end


    Any suggestion/solution will be a great help.

    -Shasha.

    Edited by: 826073 January 6, 2011 06:58

    Thanks a ton of out. Your update has helped me solve the problem. The original Version I was using had no attributes defined as "Key attribute". Once I put one of the key attribute primary as "attribute Key' on my VO Editor, all worked great :). Thanks again.

  • Line number SQLLoader

    Hello

    I have a requirement to load a huge number of data files using SQL Loader. My requirement is to load the records sequentially with the line number that can be achieved using Oracle sequence object.

    But I want to start the sequence with 1 whenever I start with the new file. Little research offers 2 options to achieve this:

    • Drop & re-creation of sequence
    • Change the sequence and set it to 1

    Since this is the current process, not sure if two options above affect DB.

    Experts, is there a better way to do this?

    Thank you and best regards,

    Matrat

    RECNUM

    http://docs.Oracle.com/CD/B28359_01/server.111/b28319/ldr_field_list.htm#i1008287

  • See the line number error container

    Hello

    I am new to Oracle SQL Developer, I use the version 3.0.0.4 on Windows XP 32 Bit, connected to an Oracle 11 g server.

    I have a statement of "CREATE or REPLACE VIEW FORCE" that shows me an error ("error at line 0 in command: CREATE or REPLACE...") ") when I run it directly in SQL Developer. Unfortunately the error message does not indicate in what line the error occurs (I have activated the display of line numbers).

    Can Developer SQL show me the line number that contains the error?

    Thank you!

    Developer SQL can display the line number, but for some instructions a number of line is not available. CREATE VIEW is one of them.

    Try taking the select statement of create view and it works separately. That should give better diagnoses.

  • How to set the default value of the attribute with a sequence number? Is it possible to add a string to seq.no. like abc0001?

    Mr President.

    How to set the default value of the attribute with a sequence number? Is it possible to add a string to seq.no. like abc0001?

    Concerning

    For the date, you can use groovy expression adf.currentDate to set the current date. reference http://adfgouravtkiet.blogspot.in/2012/11/how-to-set-default-values-for-entity.html

    You already have ways to use the sequence.

    How do you add a new value in the form. You're creating a new line of your page (user interface) and by engaging with validation operation? Unless you commit you will not be able to see anything in the table.

    Thank you

  • V9 Acrobat JavaScript Alert Box - possible to add space or line break after each element of the array?

    I have a Document level Javascript used to identify empty mandatory fields and fires on shares of paper, print and save. The script identifies the required fields empty, counties and outputs of an alert box indicating the number of required fields empty and lists the name of the ToolTip fields. The script identifies the required fields with an asterisk at the end of each balloon.

    Is my question possible to add a space or a line break after the decimal point for each item?

    Here is a picture of the exit where the items listed are all grouped together.

    Alert box array items need space or line break.jpg

    Here is the code:

    function validateFields()

    {

    a counter for the number of empty fields

    var = 0 flg

    count all the fields of the form

    var n = this.numFields

    create a table to contain the names of the required fields

    If they are determined to be empty

    fArr var = new Array();

    Browse all fields and look for ones that are required

    all fields that have a ' *' in their ToolTip are required

    for (var i = 0; i < n; i ++) {}

    var fn = this.getNthFieldName (i);

    var f = this.getField (fn);

    ToolTip is the property of 'userName' of the fields\;

    TT = f.userName var

    test the ' *';

    If (TT. IndexOf('*')

    ! =-1 & & f.value == f.defaultValue) {}

    increment the counter of empty fields;

    FLG ++;

    Add the fields username (ToolTip) to the list of the names of fields empty.

    fArr [fArr.length] = tt;

    }

    }

    now display a message if there are blank fields

    if(FLG>0) {}

    App.Alert ("there are '+ flg + areas that require a value\n\n' + fArr, 3")

    }

    else {}

    This.Print ();

    }

    }

    The required property is very easy to use. It's just a Boolean (true/false) value, then you can use it like this in your code. Instead of this line:

    If (tt.indexOf('*')! =-1 & f.value == f.defaultValue) {}

    Use this:

    If (f.required == true & f.value == f.defaultValue) {}

Maybe you are looking for

  • Firefox always displays all the possible options in the context menu

    When I select some text on a web site and right-click, I get a popup menu with about 50 options. Some earlier, archived posts have addressed one of the causes of this - extensions - but disable my extensions and restarting did not work for me. I alwa

  • Where can I find a tutorial for Web Developer?

    I see nothing in the 'index' for the tool, and I have no experience in using a tool/application/etc like that.

  • Satellite Pro P300 restarts a few minutes after the stop

    Hello I'm unable to download the update of the BIOS for a Toshiba Satellite Pro P300 PSPCDE (WIN 3.00), the reason being that I wonder a user name and password to download the file! The laptop has this annoying problem to revive a few minutes after t

  • Stop time

    I have a small question about the closing time. Can someone tell me how long it should take for the i1 power off then turns off? When I go to turn it off it takes so long that I'm impatient and remove the battery. I was told that this is not good for

  • New Time Capsule ranging from Windows to Mac with file sharing.

    OK, so we bought a new time capsule recently and my family migrates slowly over Apple products. My question comes from having moved all our old saved files from various sources during the share of time capsule. Currently, the file system is FAT32 bec