Db_stat output question (last column value?)

Hi,
Searched everywhere, can not find this mentioned anywhere. What are the meanings of the columns in the db_stat -C output, for example:
Locks grouped by lockers:
Locker Mode Count Status \--------------- Object \------------
1 dd= 0 locks held 2 write locks 0 pid/thread 20910/1121282384
1 READ 1 HELD 840055011:840055011 handle 2
1 READ 1 HELD 840055011:840055011 handle 0
4 dd= 0 locks held 0 write locks 0 pid/thread 20910/1121282384
5 dd= 0 locks held 2 write locks 0 pid/thread 20910/1121282384
5 READ 1 HELD 840055038:840055038 handle 2
5 READ 1 HELD 840055038:840055038 handle 0
I take this to indicate:
Locker 1 has two READ locks on 840055011, which is an open handle
Locker 4 had been declared, but is now empty, awaiting its call to duty
Locker 5 has two READ locks on 840055038, again, an open handle
The pid and thread information are self-describing I believe.
My questions are, what would the difference be between the two different READ locks in, say, locker 1, one line ends w/ 2, the other w/ 0. Is this a problem in my code, could I possibly have opened the same handle twice?
Additionally, I know the database handle is being named 840055011 but is listed as "840055011:840055011", is this expected, or again, might I have an issue. I'm fairly sure this is simply naming and probably arbitrary.
If there is a source for the db_stat output that I have missed, by all means, please let me know, I've tried my best to RTFM, but couldn't find many M's.
FYI: transactional environment using the Java binding (not JE)
Thank you

Hi,
brianmckenna wrote:
Searched everywhere, can not find this mentioned anywhere. What are the meanings of the columns in the db_stat -C output...I think this should answer your questions:
Deadlock debugging - http://www.oracle.com/technology/documentation/berkeley-db/db/programmer_reference/lock_deaddbg.html
Thanks,
Bogdan Coman

Similar Messages

  • Read one column and output its second column value in same row

    Hi
    I have 2 columns, of which I only wish to read the first column. There is an input value, which comes from an outside source, but we can call a constant for this particular question. This constant value must be compared to these first column values, untill it equals the same value. The code must then read the second columns value in the same row and output this value. The exel spreadsheet is below as an example, though the sheet has far more values and larger numbers.
    If there is no value in the first column which is equal to the input constant, it must output a 0. If anyone could help with this it would be fantastic. I'm still busy working on it and might get it eventually, but I would like to get there faster a great deal.
    Thanks
    Jingles
    Attachments:
    Exel.JPG ‏35 KB

    Jingles,
    if you get the data in a 2d array, you should be able to write soemthing like this pseudocode:
    while i<max length
        if checkvalue=array[1,i]
          output array[2,i]
    i++
    if output is empty output zero
    Regards,
    Kyle Mozdzyn
    Applications Engineering
    National Instruments
    Regards,
    Kyle M.
    Applications Engineering
    National Instruments

  • Last column value

    Looking for simplest way to return last value in a column that is regularly added to.  No blanks between numbers in the column.  Would like to return the value to a given cell.  Can do this in excel but having difficulty in numbers.  Thanks.

    Hi trexo,
    Jerry's original solution, reproduced here, may be placed in any cell on the same table as the list of values in column B.
    =OFFSET(B1, COUNT(B), 0)
    It assumes that the first value in the list is in cell B2 (one row below the label in Row 1), and that (as you specified) there are no gaps in the data from that cell to the last one containing a value.
    COUNT(B) counts the numerical values entered in column B; the result is used as the row-offset in the OFFSET function. Zero ( 0 ), the column-offset value in the formula, means 'the same column as the base, B1'.
    Your Excel formula:
    =index(D:D, Match(9.9999999999999E+307,D:D))
    MATCH returns the position of the specified value in a list of values in a range.
    The range here is column D, and the value to match (expressed as a base 10 number) is
    99999999999999 followed by 294 zeroes, a rather large number, likely to be far greater than the largest number in column D.
    MATCH in numbers can be set to find the largest close match, the smallest close match, or an exact match, with 'largest close match' the default choice. My assumption is that this is also true in Excel. If so, the expression in your Excel formula is looking for the "largest number in column D that is smaller than or equal to the search value."
    IF the last number in the column is also the largest number in the column (and that number is smaller than 9.9999999999999E+307), then the formula will return the correct value. If the last value in column D is NOT also the largest value in column D, OR is larger than the search value, then the formula will not return the 'last value' in column D.
    A Numbers similar to this would be:
    =OFFSET(D1,MATCH(9.9999999999999E+307,$D)-1,0)
    Here's an example, showing the results. The formula above is in B2; the same formula with the cell references changed to E1 and $E is in B3:
    Note that both return the largest value in their column, not necessarily the 'last' value in that column.
    Regards,
    Barry

  • Modeling Question: Last Item value and First Value

    Dear all,
    I have the data coming in the following format:
    Data Source:
    HEAD1     1     21.01.2005
         2     21.01.2005
         3     21.01.2005
         4     21.01.2005
         5     23.01.2005
         6     21.01.2005
         7     21.01.2005
         8     21.01.2005
         9     21.01.2005
         10     25.01.2005 * ( I need this last Value)
    HEAD2     1     26.01.2005 * ( I need 1st Value)
         2     28.01.2005
         3     28.01.2005
         4     28.01.2005
         5     28.01.2005 * (I need this last value)
    HEAD2     1     29.01.2005 * (I need this 1st Value in the report)
         2     30.01.2005
         3     30.01.2005 * ( I need this last value in the report)
    And I want in reporting as:
    Reporting:
    0) 00.00.0000  21.01.2005
    1) 25.01.2005  26.01.2005
    2) 28.01.2005  29.01.2005
    3) 30.01.2005  00.00.0000
    What can be my options?
    I am not interested to use ABAP logic..
    Is any last and first value aggregations can be helpfull??
    Thanks for your time..
    Regards,
    Hari

    Hi Aborgeld,
    you can remove headers after writing the csv by using Get-Content $file | Select -skip 1 | Set-Content $file.
    If null values are a problem for your SQL, this may work for you in your Select-Object call:
    # Service Pack Filter-hash
    $spf = @{
    n = "osServicePack"
    e = {
    if ($_.osServicePack) { $_.osServicePack }
    else { " " }
    # Using it later in Select
    Select-Object Name, lastLogonTimestamp, OSName, ParentContainerDN, osversion, $spf
    Cheers,
    Fred
    There's no place like 127.0.0.1

  • Urgent: Formular question: get first/last month value with qty value

    We've got a query result as the following:
    Jan_2007 -- Feb_2007 -- Mar_2007 -- Apr_2007
    0 --- 54 --- 0 --- 3
    23 ---0 --- 12 --- 7
    In the above query result,
    1st row shows the sales quantity in Jan_2007 is 0, in Feb_2007 is 54, in Mar_2007 is 0, and in Apr_2007 is 3.
    2nd row shows the sales quantity in Jan_2007 is 23, in Feb_2007 is 0, in Mar_2007 is 12, and in Apr_2007 is 7.
    We would like to add a new column to get the first/last month value with quantity, e.g., in 1st row, the 1st month value with quantity value (>0) is Feb_2007, and the last month value with quantity value (>0) is Apr_2007. Therefore the 1st month value with qty is Feb_2007 and the last month value with qty is Apr_2007. In 2nd row, the first month value with qty is Jan_2007 and the last month value with qty is Apr_2007. But how to use formular to get the 1st/last month values with qty?
    We will give you reward points!

    Hello Kevin,  
    You can create forumula using [Boolean Operator|http://help.sap.com/saphelp_nw04/helpdata/en/23/17f13a2f160f28e10000000a114084/content.htm]
    IF<Logic Expression> THEN <Expression1> ELSE <Expression2> can also be made using a formula in the form
    You can also use the [AND, OR Logical operators |http://help.sap.com/saphelp_nw04/helpdata/en/23/17f13a2f160f28e10000000a114084/content.htm]to check all the keyfigure columns.
    Thanks
    Chandran

  • Cumulated values, but last column sometimes empty

    Hi,
    We have a report which cumlated an amount key figure per fiscal period. The query shows the following results:
    001.2009   002.2009   003.2009  004.2009
    10                 20               30         40          --> every month we get +10
    But know we have a data record, were we have no value for april and the report shows the following results:
    001.2009   002.2009   003.2009  004.2009
    10                 20               30        
    The last column is empty. Can somebody explain me this result? Is this normal? If I show the total cumulated result, the result is correct.
    Thank you very much.
    Jessica

    Hi,
    I suppose there is no data posted for Month of April and calmonth reads data from master data not the posted data, if it is right then the query is running fine.
    Regards,
    Kams

  • Question about the vi : Average Last Five Values

    Hello,
    I found the vi to make the average of the last five values here : https://decibel.ni.com/content/docs/DOC-4013
    But i think that it is not really the average of the last five values...
    The problem in my opinion is that the shift register on the left should contain only 4 and not 5 elements.
    Can someone check it ?
    Thanks to answer

    That looks like the correct fix to me.  The previous version was definitely wrong.
    I wanted to add a comment to that article in the community zone, but couldn't find a way to do it event though I was logged in.
    There is a comment that the results are in valid for the first 4 iterations.  The way to fix that is to divide by the number of iteration that have occurred using the In range and coerce function to limit it to 5.
    Attachments:
    Example_VI_BD.png ‏15 KB

  • Error importing text file into SQL Server when last column is null

    Hello all. Happy holidays!
    I'm trying to import a text file into a SQL Server table, and I get the error below when it gets to a row (row 264) that has null in the last column. I'm guessing the null jumbles up the delimiters somehow. The nulls are not errors, and I need to import
    them into the table with the rest of the rows. Any idea how I can do that?
    Thanks!
    [Flat File Source [1]] Error: Data conversion failed. The data conversion for column "XYZ" returned status value 2 and status text "The value could not be converted because of a potential loss of data.".
    [Flat File Source [1]] Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR.  The "output column "XYZ" (178)" failed because error code 0xC0209084 occurred, and the error row disposition on "output column "XYZ"
    (178)" specifies failure on error. An error occurred on the specified object of the specified component.  There may be error messages posted before this with more information about the failure.
    [Flat File Source [1]] Error: An error occurred while processing file "ABC.txt" on data row 264.
    [SSIS.Pipeline] Error: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED.  The PrimeOutput method on component "Flat File Source" (1) returned error code 0xC0202092.  The component returned a failure code when the pipeline engine called PrimeOutput().
    The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing.  There may be error messages posted before this with more information about the failure.
    WeeLass

    Hi WeeLass,
    The error that” Data conversion failed. The data conversion for column "XYZ" returned status value 2 and status text "The value could not be converted because of a potential loss of data.".” is generally error message, and the error indicates
    that there is data type mismatch issue between the input columns and the output columns.
    Based on your description, the issue is that you trying to convert a column contains empty value from string to integer data type for the output column "XYZ" in Flat File Source [1]. Please note that we cannot type an empty value as integer data
    type column value, so the error occurs.
    To fix this issue, just as you did, we should convert the data type for the output column "XYZ" in Flat File Source [1] back to DT_WSTR or DT_STR, then use a derived column task to replace the current column (UBPKE542). But the expression should
    be like below:
    LEN(TRIM(UBPKE542)) > 0 ? (DT_I8)UBPKE542 : NULL(DT_I8)
    In this way, the data type of the column in SQL table would be int, and the empty value would be replaced with NULL.
    If there are any other questions, please feel free to ask.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Combine 2 specific column values into one column

    Is there an easy solution to combine column values that is in a group?
    In my report I have 1 column group named Activity_Area which has 5 different values Activity 1, Activity2...Activity5.
    Let's say I want to merge Activity 4 and Activity 5 and call it ActivityX and gives me the output as below
    Activity 1 | Activity 2 | Activity 3 | ActivityX

    Hi Jhonny86,
    According to your description, you create a field in database and it contains five values. Then you want to only display four values in report column group, and the last two values should be replaced by “ActivityX”, right?
    In your scenario, you can create an table like below:
    create table Act(id int,activity varchar(99))
    insert into Act select 1,'Activity 1'
    insert into Act select 2,'Activity 2'
    insert into Act select 3,'Activity 3'
    insert into Act select 4,'Activity 4'
    insert into Act select 5,'Activity 5'
    Then query the table with code like below in query designer, then add the field [Act] into the column group.
    If you have any question, please feel free to ask.
    Best regards,
    Qiuyun Yu
    Qiuyun Yu
    TechNet Community Support

  • How to get the last "reported" value in a cross tab

    Dear all,
    based on a BeX Query Universe I have built a report with a cross tab in webI.
    Maybe you can help me with the following issue. There I have a problem: I want to get in the Total-column always the last reported value, e.g. for Number Total Customers "66", not for Mar or Apr, because they are null.
    Calendar Month                      |Jan| |Feb| |Mar| |Apr| |Total|
    Number Total Customers         |54|    |66|  | |      | |       66
    Number Active Customers      |57|    |71|  | |      | |       71
    I hope that you understand my problem and could help as soon as possible.
    Thanks a lot in advance for your support.
    Best regards.
    Edited by: HOLWUE on Feb 8, 2010 1:40 PM

    Hi,
    If this question is related to Webi then post in the below forum.
    http://scn.sap.com/community/businessobjects-web-intelligence/content?filterID=content~objecttype~objecttype[thread]
    Regards,
    Sujit.

  • Parsing Column Value. SQL / Stored Proc/ Function ?

    Hi,
    I just started writing SQL. Need your valuable input for the following query,
    Need to query a table and parse a column to produce a desired output.
    like suppose my column value is
    #ADFA
    /SDFGAS
    {ABC}: 123
    {BCA}: 456
    {DEF}: 789
    and i need to get an out put as follows
    {ABC} {BCA} {DEF}
    123 456 789
    so the patterns are defined.
    I some how tried and reached through SQL, but there should be better way than this. So posted this question.
    I tried using SQL itself (using substr, instr & decode functions in the select statement)... with out using stored proc/ function as i have not created one earlier.. I am just learning the syntax and trying it.
    The psuedo code i have planned is
    function substring(column_value, search_string)
    var start_index NUMBER;
    var end_index NUMBER;
    var result VARCHAR2;
    result = 'N/A';
    start_index = instr(column_value, search_string) + 4
    if start_index >= 4
    end_index = instr(substr(column_value, 0, start_index), CHR(13)-1)
    if start_index >= 4 && end_index >=0
    result = substr(column_value, start_index, end_index);
    return result;
    I just wrote it like writing in a programming language. Need to implement this through Stored Proc/ Function. Please let me know your comment on this

    Oops, I think regular expressions are not available in my current oracle version :-(
    I am having Oracle 9i.
    Got it.. Yes it is available from 10G onwards.. :-(
    Message was edited by:
    Thiru.Thiru

  • Unable to read last column in FCC

    Hi Experts,
    I have a simple fcc to bapi scenario....
    I have two questions
    Firstly ..what is the limit on the number of fields , I mean number of columns in the input file????
    Secondly.. Im facing a strange issue where the last column is not being read if it empty , and being read (as i see it in comm channel monitoring) only when it has a value...
    Pls share ur thoughts

    Hi Teja,
    > Firstly ..what is the limit on the number of fields , I mean number of columns in the input file????
    There is no limit, you can use any number of fields based on your requirements.
    > Secondly.. Im facing a strange issue where the last column is not being read if it empty , and being read (as i see it in comm >channel monitoring) only when it has a value...
    If you want to read that fields always(if value is there or not) then in the mapping use map with default node function.
    More info check this link
    http://help.sap.com/saphelp_srm40/helpdata/ru/2c/181077dd7d6b4ea6a8029b20bf7e55/content.htm
    Regards
    Ramesh

  • How to not repeat the column values if repeated on next line and so on..?

    Hi all,
    The XmlP template that is designed gives me the output as follows :
    COL1 COL2 COL3 COL4 COL5 COL6 COL7
    abc 1 1000.00 10.00 95.00 695.00 cad
    abc 2 1000.00 100.00 95.00 695.00 cad
    abc 3 1000.00 100.00 95.00 695.00 cad
    But my requirement is as follows :
    COL1 COL2 COL3 COL4 COL5 COL6 COL7
    abc 1 1000.00 10.00 95.00 795.00 cad
    - 2 - 100.00 - - -
    - 3 - 100.00 - - -
    Note : "-" indicates blank column values (gaps are being filled)
    How do I not repeat the column values if repeated?
    Please let me know if you have answer for it?
    Thanks in Advance
    Munna

    Iam trying to design the xml publisher template using xmlp template builder.
    My requirement is :
    For a receipt number, I have receipt amount, applied amount, unapplied amount and on account amount. And for each receipt, there can be multiple applied amount ( as the receipt can be applied multiple times), but the unapplied amount, on account amount and receipt amount is single.
    By using the logic as said above from http://blogs.oracle.com/xmlpublisher/2007/04/13
    Iam getting the output something like this:
    Receipt Number| Receipt Amount | App Amount |UnappAmount|OnaccountAmount|
    111-b|249.28|249.28|0.00|0.00|
    1110|1,000.00|10.00|95.00|795.00|
    1110| -|10.00|-|-|
    1112|1500.00|1,271.02|-|-|
    1112|-|228.98|-|-|
    My requirement is to go get something like this:
    Receipt Number| Receipt Amount | App Amount |UnappAmount|OnaccountAmount|
    111-b|249.28|249.28|0.00|0.00|
    1110|1,000.00|10.00|95.00|795.00|
    1110| -|10.00|-|-|
    1112|1500.00|1,271.02|0.00|0.00| ---> here lies the difference
    1112|-|228.98|-|-|
    How do i check the duplicate of the column values only for a receipt number??
    Because as for receipt no. 111-b the unapplied amount and on account amount is 0.00, the the unapplied amount and on account amount for receipt number 1112 is getting hided( because its a duplicate) . In reality, it should be 0.00 and any other line for that receipt number (1112) should be hided. except for the applied amount.
    Note We can see that last 2 columns in the last record( for receipt number 1112) is getting hided that is as expected but for 4th record the unapplied amount and on account amount should be 0.00 respecively.
    '-' indicates hided value
    Please help.
    Thanks in Advance

  • Missing database last column

    Dear All ,
    I am facing one problam . In this code in while loop i am getting all columns. but while i am trying to get out of the loop last column is missing. please can anybody rectify this problam.
    public class DatabseFetching {
    /ublic static void main(String[] args) throws SQLException, Exception {
    DatabaseConnection con = new DatabaseConnection();
    Connection connection = con.getConnection();
    String SQL = "select * from t_mig_filenet_attach_error";
    Statement stmt = connection.createStatement();
    ResultSet resultObj = stmt.executeQuery(SQL);
    String DatabaseAttachId=null;
    while (resultObj.next()) {
    DatabaseAttachId=resultObj.getString("attach_id");
    System.out.println("Database attach id is:"+DatabaseAttachId);
    System.out.println("test is:"+DatabaseAttachId*);// i want total columns here.... while i am trying to get last column missing here.*
    }

    Hi,
    When i am running the above program then i am getting the following output.
    ***************************OUT PUT*****************************
    *# Connected to Database: sun.jdbc.odbc.JdbcOdbcConnection@a62fc3*
    Database attach id is:attacha
    Database attach id is:attacha
    Database attach id is:attacha
    Database attach id is:attacha
    Database attach id is:12345
    Database attach id is:12345
    test is:12345
    Now i want that all the value of attach_id will be come in test is:
    like following way.
    test is:attacha
    test is:attacha etc. like the same way in Databse attach id is:

  • Initialize sub sequence column values on insert?

    I asked this on stack overflow, but it was recommended that I also ask here.
    http://stackoverflow.com/questions/12982875/initialize-sub-sequence-column-values-on-insert-oracle
    I would like my table to sequence its "order by" column based on it's TEMPLATE_ID. I would like this to happen on insert (via an insert trigger, probably). For example, if I run the following inserts, I should get the following table values.
    INSERT INTO TEMPLATE_ATTRIBUTES (ID, TEMPLATE_ID) VALUES (1, 1)
    INSERT INTO TEMPLATE_ATTRIBUTES (ID, TEMPLATE_ID) VALUES (2, 1)
    INSERT INTO TEMPLATE_ATTRIBUTES (ID, TEMPLATE_ID) VALUES (3, 1)
    INSERT INTO TEMPLATE_ATTRIBUTES (ID, TEMPLATE_ID) VALUES (4, 2)
    INSERT INTO TEMPLATE_ATTRIBUTES (ID, TEMPLATE_ID) VALUES (5, 2)
    INSERT INTO TEMPLATE_ATTRIBUTES (ID, TEMPLATE_ID) VALUES (6, 2)
    INSERT INTO TEMPLATE_ATTRIBUTES (ID, TEMPLATE_ID) VALUES (7, 2)
    INSERT INTO TEMPLATE_ATTRIBUTES (ID, TEMPLATE_ID) VALUES (8, 3)
    ID TEMPLATE_ID ORDER_BY
    1           1        1
    2           1        2
    3           1        3
    4           2        1
    5           2        2
    6           2        3
    7           2        4
    8           3        1I first tried to create this trigger, but it gives me an error when I insert.
    create or replace
    trigger TEMPLATE_ATTRIBUTES_AF_INS_TRIG
       after insert on TEMPLATE_ATTRIBUTES
       for each row
    begin
        if :NEW.ORDER_BY is null then
           update TEMPLATE_ATTRIBUTES
           set ORDER_BY = (select coalesce(MAX(ta.ORDER_BY), 0) + 1 from TEMPLATE_ATTRIBUTES ta where ta.TEMPLATE_ID = :NEW.TEMPLATE_ID)
           where ID = :NEW.ID;
        end if;
    end;The error it gives me is: "table TEMPLATE_ATTRIBUTES is mutating, trigger/function may not see it"
    So I need a different way to build this trigger. And I also need it to "thread safe" so that if these two inserts occur on different sessions at the same time, then the resulting records will still get different "ORDER_BY" values:
    INSERT INTO TEMPLATE_ATTRIBUTES (ID, TEMPLATE_ID) VALUES (1, 1)
    INSERT INTO TEMPLATE_ATTRIBUTES (ID, TEMPLATE_ID) VALUES (2, 1)
    Edit:
    I tried the common work around for the "table is mutating, trigger/function may not see it" and the work around "worked" but it was not "thread safe." I tried to add locking but it gave me another error on insert
    create or replace package state_pkg
    as
      type ridArray is table of rowid index by binary_integer;
      newRows ridArray;
      empty   ridArray;
    end;
    create or replace trigger TEMPLATE_ATTRIBUTES_ORDER_BY_TB4
    before insert on TEMPLATE_ATTRIBUTES
    begin
      state_pkg.newRows := state_pkg.empty;
    end;
    create or replace trigger TEMPLATE_ATTRIBUTES_ORDER_BY_TAF1
    after insert on TEMPLATE_ATTRIBUTES for each row
    begin
      if :NEW.ORDER_BY is null then
        state_pkg.newRows( state_pkg.newRows.count+1 ) := :new.rowid;
      end if;
    end;
    create or replace trigger TEMPLATE_ATTRIBUTES_ORDER_BY_TAF2
    after insert on TEMPLATE_ATTRIBUTES
    declare
      v_request     number;
      v_lockhandle varchar2(200);
    begin
      dbms_lock.allocate_unique('TEMPLATE_ATTRIBUTES_ORDER_BY_lock', v_lockhandle);
      while v_request <> 0 loop
        v_request:= dbms_lock.request(v_lockhandle, dbms_lock.x_mode);
      end loop;
      begin
        for i in 1 .. state_pkg.newRows.count loop
          update TEMPLATE_ATTRIBUTES
          set ORDER_BY = (select coalesce(MAX(q.ORDER_BY), 0) + 1 from TEMPLATE_ATTRIBUTES q where q.TEMPLATE_ID = (select q2.TEMPLATE_ID from TEMPLATE_ATTRIBUTES q2 where q2.rowid = state_pkg.newRows(i)))
          where rowid = state_pkg.newRows(i);
        end loop;
        v_request:= dbms_lock.release(v_lockhandle);
      EXCEPTION WHEN OTHERS THEN
        v_request:= dbms_lock.release(v_lockhandle);
        raise;
      end;
    end;This gives me:
    ORA-04092: cannot COMMIT in a trigger ORA-06512: at "SYS.DBMS_LOCK", line 250 ORA-06512: at "TEMPLATE_ATTRIBUTES_ORDER_BY_TAF2", line 5 ORA-04088: error during execution of trigger 'TEMPLATE_ATTRIBUTES_ORDER_BY_TAF2' ORA-06512
    Edit 2: The ORDER_BY column must be an updateable column. ID actually uses a sequence and before insert trigger to set its values. I thought I was simplifying my question when I included it in the insert examples, but that was incorrect. ORDER_BY's initial value is not really related to ID, but rather to what order the records are inserted. But ID is sequenced so you can use that if it helps.

    Check here below:
    create table TEMPLATE_ATTRIBUTES
    ( ID           INTEGER
    , TEMPLATE_ID  INTEGER
    , ORDER_BY     INTEGER
    CREATE OR REPLACE TRIGGER templ_attr_bf_ins_trg
       BEFORE INSERT
       ON template_attributes
       FOR EACH ROW
    BEGIN
       IF :new.order_by IS NULL
       THEN
          SELECT NVL (MAX (ta.order_by), 0) + 1
            INTO :new.order_by
            FROM template_attributes ta
           WHERE ta.template_id = :new.template_id;
       END IF;
    END;
    INSERT INTO TEMPLATE_ATTRIBUTES (ID, TEMPLATE_ID) VALUES (1, 1);
    INSERT INTO TEMPLATE_ATTRIBUTES (ID, TEMPLATE_ID) VALUES (2, 1);
    INSERT INTO TEMPLATE_ATTRIBUTES (ID, TEMPLATE_ID) VALUES (3, 1);
    INSERT INTO TEMPLATE_ATTRIBUTES (ID, TEMPLATE_ID) VALUES (4, 2);
    INSERT INTO TEMPLATE_ATTRIBUTES (ID, TEMPLATE_ID) VALUES (5, 2);
    INSERT INTO TEMPLATE_ATTRIBUTES (ID, TEMPLATE_ID) VALUES (6, 2);
    INSERT INTO TEMPLATE_ATTRIBUTES (ID, TEMPLATE_ID) VALUES (7, 2);
    INSERT INTO TEMPLATE_ATTRIBUTES (ID, TEMPLATE_ID) VALUES (8, 3);
    SELECT * FROM TEMPLATE_ATTRIBUTES;
    Output:
            ID TEMPLATE_ID   ORDER_BY
             1           1          1
             2           1          2
             3           1          3
             4           2          1
             5           2          2
             6           2          3
             7           2          4
             8           3          1
    {code}
    Let me also comment that I don't like this solution. It might conflict with multiuser access.
    If you just need the column to order the table you can use a sequence and then order you table by template_id, order_by (generated by a sequence).
    In this way you will not have a problem with multiuser access. Do you care that order_by column is not starting from 1 for each template_id and it has "holes" in the sequence for that template_id?
    Regards.
    Al
    Edited by: Alberto Faenza on Oct 22, 2012 5:11 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Maybe you are looking for