How to maintain a counter column?

Hi All,
I am a novice with Oracle. Currently I have a problem which requires me to maintain a counter in an oracle column.
Following is my schema:
assetTable
1. ID
2. Name
3. Count
recordTable
1. ID
2. AssetID
For each insert in the recordTable, I want to update the 'Count' column in assetTable by 1 for the appropriate 'AssetID' which is the foreign key to the assetTable. There would be multiple clients trying to do insert into the recordTable, however the counter must be incremented for each insert reliably. Initially I thought I would be able to achieve this by writing a simple trigger. But I think that a trigger which does a simple read and update would not work as their are multiple clients writing simultaneously.
Please suggest a solution.
Thanks in advance.

create or replace view v_asset as
select a.id, a.name, count(r.id)
from assetTable a, recordTable r
where r.assetID = a.id
{code}<br /><br /><br /><br />Google database+normalization for why any other approach is <a href="http://catb.org/jargon/html/B/Bad-and-Wrong.html" title="Bad And Wrong">Bad And Wrong</a>
Edited by: Dave Hemming on Oct 31, 2008 11:46 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • How to set Tile count column or count row?

    How to set Tile count column or count row? If not can do, How
    to adjust count row or count column?
    Thx for all idea.

    The Tile container's number of columns and rows is calculated
    based on each child's width and height (or based on tileWidth and
    tileHeight which you can set). If you need more control over the
    layout, use Grid.

  • How to define a dynamic column to count the quarter of each year?

    Lets see the result that now displayed:
    YEARS MONTHS SUMMONTH SUMYEAR SUMQUARTER
    2009 Jan      127994 1766166     449652
    2009 Feb      168106 1766166     449652
    2009 Mar      153552 1766166     449652
    2009 Apr      160329 1766166     438913
    2009 May      137605 1766166     438913
    2009 Jun      140979 1766166     438913
    2009 Jul      148606 1766166     435283
    2009 Aug      150390 1766166     435283
    2009 Sep      136287 1766166     435283
    2009 Oct      149529 1766166     442318
    2009 Nov      153268 1766166     442318
    2009 Dec      139521 1766166     442318
    2010 Jan      124670 1721212     407181
    2010 Feb      139278 1721212     407181
    2010 Mar      143233 1721212     407181
    2010 Apr      149518 1721212     444112
    2010 May      152292 1721212     444112
    2010 Jun      142302 1721212     444112
    2010 Jul      149125 1721212     412855
    2010 Aug      130328 1721212     412855
    2010 Sep      133402 1721212     412855
    2010 Oct      157754 1721212     457064
    2010 Nov      137078 1721212     457064
    2010 Dec      162232 1721212     457064
    The problem is about how to dynamic a new column called "Q_count" to count each displayed row belong to which quarter of year??
    In addition, it will repeat again from next year.
    For example:
    *2009 Jan-Mar will display "q1", Apr-Jun will display "q2".....and for 2010 Jan-Mar, it will display "q1" again and so on.*
    Here is my sql that I am using:
    select years,months,summonth,sumyear,sumquarter
    from(
    select years,months,summonth,sumyear,
            sum(sumhour) over(partition by years || to_char(ym, 'Q') order by years || to_char(ym, 'Q')) sumquarter,ym
    from(
    select years, months, days, hours, mins, sumHour, SUM (sumHour) OVER (PARTITION BY years,months,days) sumDay, SUM (sumHour) OVER (PARTITION BY years,months) sumMonth, SUM (sumHour) OVER (PARTITION BY years) sumyear,
    to_date(years || months, 'YYYYMon', 'NLS_DATE_LANGUAGE=American') ym
    from (SELECT x.years, x.months, x.days, x.hours, x.mins, sum(x.value) as sumHour
    FROM xmltest,
    XMLTABLE ('$d/cdata/name' passing xmldoc as "d"
       COLUMNS
      years integer path 'year',
      months varchar(3) path 'month',
      days varchar(2) path 'day',
      hours varchar(2) path 'hour',
      mins varchar(2) path 'minute',
      value float path 'value'
      ) as X
      group by x.years, x.months, x.days, x.hours, x.mins
      order by x.years, x.months, x.days
      group by years,months,summonth,sumyear,sumquarter,ym
      order by ymThanks everyone helps me!!!

    If my understanding is correct..
    select years,months,summonth,sumyear,sumquarter,qtr
    from(
            select years,months,summonth,sumyear,to_char(ym, 'Q') qtr,
                    sum(sumhour) over(partition by years || to_char(ym, 'Q') order by years || to_char(ym, 'Q')) sumquarter,ym
            from(
                    select   years, months, days, hours, mins, sumHour,
                             SUM (sumHour) OVER (PARTITION BY years,months,days) sumDay,
                             SUM (sumHour) OVER (PARTITION BY years,months) sumMonth,
                             SUM (sumHour) OVER (PARTITION BY years) sumyear,
                             to_date(years || months, 'YYYYMon', 'NLS_DATE_LANGUAGE=American') ym
                    from  (
                            SELECT x.years, x.months, x.days, x.hours, x.mins, sum(x.value) as sumHour
                            FROM xmltest,
                                 XMLTABLE ('$d/cdata/name' passing xmldoc as "d"
                                            COLUMNS
                                              years integer path 'year',
                                              months varchar(3) path 'month',
                                              days varchar(2) path 'day',
                                              hours varchar(2) path 'hour',
                                              mins varchar(2) path 'minute',
                                              value float path 'value'
                                           ) as X
                            group by x.years, x.months, x.days, x.hours, x.mins
                            order by x.years, x.months, x.days
    order by ymEdited by: jeneesh on Mar 26, 2012 5:49 PM
    Removed unnecessary GROUP BY

  • How to maintain counter in a for loop

    Hi, 
      How do we track counter in a loop?Isn't it the way I implemented.? Please suggest.
    Regards.
    Solved!
    Go to Solution.
    Attachments:
    for loop counter.jpg ‏219 KB

    Both loops have errors, if you try to do for(i=60;i<120;i++) you're only running 60 loops, not 120.
    You should also disable the autoindexing on incoming arrays as you want some split array indexes (actually you can optimize it by extracting the constant a[30] before the 1st loop and the opposite on the 2nd. Now you're extracting 2 numbers from a 1D array instead of 1 from a 2D array ...
    The number on the select/sum function should be integers, no need to calculate doubles.
    The small array to sum it up is only max 170 numbers, it's ok although a sum in a shift register would be better.
    /Y
    LabVIEW 8.2 - 2014
    "Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
    G# - Free award winning reference based OOP for LV

  • How to add records or how to maintain list in stored Procedure

    Hi,
    I am facing an issue in the addition of record in the type
    create or replace
    TYPE               "PROD_SEARCH_COUNT_TBL"                                          AS TABLE OF PROD_SEARCH_COUNT_OBJ;
    create or replace
    TYPE               "PROD_SEARCH_COUNT_OBJ"                                          AS OBJECT
    ( /* TODO enter attribute and method declarations here */
        V_Name Varchar2(500 Byte),
        v_Value Varchar2(500 Byte),
        v_count Number
    I want to add records to the type I tried following way
    prod_wcf_rec PROD_SEARCH_COUNT_TBL;
      SELECT PROD_SEARCH_COUNT_OBJ('Name1','Value1',1) BULK COLLECT INTO prod_wcf_rec FROM DUAL;
        SELECT PROD_SEARCH_COUNT_OBJ('Name2','Value2',2) BULK COLLECT INTO prod_wcf_rec FROM DUAL;
        SELECT PROD_SEARCH_COUNT_OBJ('Name3','Value3',3) BULK COLLECT INTO prod_wcf_rec FROM DUAL;
        SELECT PROD_SEARCH_COUNT_OBJ('Name4','Value4',4) BULK COLLECT INTO PROD_WCF_REC FROM DUAL;
    DBMS_OUTPUT.PUT_LINE ('-----------------------------Looping----------------------------');
    FOR i in 1 .. prod_wcf_rec.COUNT
    LOOP         
    DBMS_OUTPUT.PUT_LINE (prod_wcf_rec(i).V_Name||' - '||prod_wcf_rec(i).v_Value||' - '||prod_wcf_rec(i).v_count);     
       END LOOP;
       DBMS_OUTPUT.PUT_LINE ('-----------------------------Looping----------------------------');
    In printing I am getting last records only .So is there any way to add records to PROD_SEARCH_COUNT_TBL
    How to add records or how to maintain list in stored Procedure

    Every time you BULK COLLECT into a collection type the value is overwirtten. So you need to try something like this.
    SQL> create or replace type prod_search_count_obj as object(v_name varchar2(500 byte), v_value varchar2(500 byte), v_count number)
      2  /
    Type created.
    SQL> create or replace type prod_search_count_tbl as table of prod_search_count_obj
      2  /
    Type created.
    SQL> declare
      2    prod_wcf_rec prod_search_count_tbl;
      3  begin
      4    select obj_val
      5      bulk collect into prod_wcf_rec
      6      from (
      7            select prod_search_count_obj('name1','value1',1) obj_val from dual
      8            union all
      9            select prod_search_count_obj('name2','value2',2) from dual
    10            union all
    11            select prod_search_count_obj('name3','value3',3) from dual
    12            union all
    13            select prod_search_count_obj('name4','value4',4) from dual
    14           );
    15
    16    dbms_output.put_line ('-----------------------------looping----------------------------');
    17    for i in 1 .. prod_wcf_rec.count
    18    loop
    19      dbms_output.put_line (prod_wcf_rec(i).v_name||' - '||prod_wcf_rec(i).v_value||' - '||prod_wcf_rec(i).v_count);
    20    end loop;
    21    dbms_output.put_line ('-----------------------------looping----------------------------');
    22  end;
    23  /
    -----------------------------looping----------------------------
    name1 - value1 - 1
    name2 - value2 - 2
    name3 - value3 - 3
    name4 - value4 - 4
    -----------------------------looping----------------------------
    PL/SQL procedure successfully completed.
    SQL>

  • Report with multiple COUNT columns with counts from same table

    I am new to discoverer so I am a bit lost.
    I am working to create a report to show usage data from the eBusiness Knowledge Base. I have the query written in SQL using subqueries that is in the format:
    Solution Number | Soultion Title | Solution Views | Positive Feedback | Negative Feedback
    12345 ___________ Title ________ 345 ____________ 98 _______________ 34
    The 'Views', 'Positive' and 'Negative' entries are stored in the same table so i am doing a count where setid=setid and usedtype=VS, then counting where usedtype=PF and usedtype=NF
    In discoverer I can get the solution number, title and ONE of the totals but I can't seem to figure out how to get a COUNT for three different things from the same table in columns on the same row.
    When I go to edit sheet -> select items once I select the COUNT option for the UsedType column in the table CS_KB_SET_USED_HISTS I can't select it again. I also have found now way to add a column based on an entered query.
    If anyone could help it would be much appreciated.
    Thanks
    Edited by: Toolman21 on Dec 2, 2010 2:17 PM
    added ______ to correct spacing.

    Hi,
    You can separate the column by using a case or decode.
    for example create 2 calculations:
    case
    when usedtype='PF'
    then <you original column> --- the one contain them both
    else 0
    end
    case
    when usedtype='NF'
    then <you original column> --- the one contain them both
    else 0
    end
    after that you can create the count aggregation over those.
    Tamir

  • How to get attendies count for a calendar list in sharepoint 2013?

    Hi everybody,
    I am using calendar list in SharePoint 2013 for my project.
    Could please tell me how to get the count of attendees using SP Designer or OOTB calculated field.
    Because I want to display the fields like
    TOTAL SEATS =20
    Attendees= Need count
    Avail seats= total - Attendees count.
    In that way I want to show information about availability seats for training session.
    Regards,
    Dhayanand

    Hi Dhaya
    Please refer the links.Hope it helps :-)
    http://social.msdn.microsoft.com/Forums/en-US/b8677dc5-3eb1-4bdc-92f2-f57201bfabb1/field-that-counts-attendees?forum=sharepointcustomizationprevious
    http://sharepoint.stackexchange.com/questions/54253/use-count-related-column-value-as-int-in-a-sp-designer-workflow

  • How to Maintain the Pricing Condition Records in CRM

    Hi
    I am new to the CRM
    How to maintain the pricing condition records in crm for the particular condition type?
    as we do in SD(VK11)
    Thanks

    Hi Binu,
    First of all, you could maintain pricing conditions in the following places:
    1. In General Condition Maintenance (GCM)
    2. At the product maintenance level
    3. At the 'Price agreement' tab of Contracts
    4. As manual conditions during order processing at item level
    Now, if you want to maintain conditions using GCM, you first have to maintain a condition maintenance group in the customizing where in you can assign condition table and condition type for different counter values. I am assuming that you have done this activity successfully.
    When you run the transaction '/SAPCND/GCM', for application 'CRM', your condition maintenance group name and context 'GCM', you will be initially taken to a screen where in you'll have an item area which would be blank and then condition fields would be displayed in a tree on the left.
    Here, select the field 'Condition type' and click on icon 'Select records'. You would get a dialog prompting you to enter condition type. Here you can specifiy the condition type for which you want to maintain/view condition records.
    If no condition records are available, item area would be left blank. Here, you can choose a condition type using the standard F4 help. Depending on condition types that are assigned to condition maintenance group, different condition types would be displayed in the F4-help using which you can maintain condition records.
    Hope this helps.
    Regards,
    Pavithra
    **PS: Please reward points if this helps.

  • How to get the count of each minutes

    Oracle 10 DB
    Hi All
    I using this query to get the count of records fetched by the concurrent program per min,
    select count (distinct b.attribute2)
    from oe_order_headers_all a,oe_order_lines_all b
    where a.header_id=b.header_id
    and b.flow_status_code ='AWAIT_QUINTIQ_BOOK'
    and to_Char(b.last_update_date,'DD-MON-YYYY HH24:MI:SS') between '19-JAN-2011 02:00:01' AND
    '19-JAN-2011 02:00:02'
    This is used to get the count of records fetched at one mins
    How to find the count of last 10 mins ie 1 mins count 2.00 to 2.10
    Thanks & Regards
    Srikkanth.M

    Try this:
    SELECT TRUNC(b.last_update_date, 'mi') time_mins, COUNT(DISTINCT b.attribute2)
    FROM   oe_order_headers_all a,
           oe_order_lines_all b
    WHERE  a.header_id = b.header_id
    AND    b.flow_status_code = 'AWAIT_QUINTIQ_BOOK'
    AND    b.last_update_date >= to_date('19/01/2011 02:00:00', 'dd/mm/yyyy hh24:mi:ss')
    AND    b.last_update_date < to_date('19/01/2011 02:10:00', 'dd/mm/yyyy hh24:mi:ss')
    GROUP BY TRUNC(b.last_update_date, 'mi');I'm not sure why you're bothering with the join to the oe_order_headers_all table, since you're not referencing that in the where clause or the selected columns list. I think you could probably do away with it.
    I've changed your code to take the last_update_date and truncate it to the minute level, and added that as a column, so you can see which count goes with which minute. Obviously, this has to be in the group by.
    I've also changed your date comparisons so that you're actually comparing dates to dates, rather than strings to strings - why would you deliberately take information away from the optimizer? Oracle does not treat strings the same as dates, and forcing it to use strings rather than dates could lead you to have a vastly differing execution path, which will most likely be less performant.
    Not to mention, coding like that leads you to assume that you can compare dates in strings without any problems, and that is just not the case. '19-FEB-2011' is counted as being earlier than '19-JAN-2008', as strings sort alphabetically.

  • How to change a 3 column template to a 2 column template?

    I'm currently working on this website.
    For this website, I designed a page and saved it as a template with the editable regions being the leftcolumn, middlecolumn and rightcolumn divs.  I then created each page using that template.
    If I wanted to change just the home page from a 3 column layout to a 2 column layout, what is the best way to do this?   I know how to make a 2 column site, I just need help with how to "unlock" the template so I can modify the code.
    Would I need to open my template file, save it as template2col (or something similar) and make the changes there, then create a new home page using that template and saving over the index file?
    The only other way I can think of making changes like this would be to copy the code, paste into wordpad, remove the template coding and then paste back into Dreamweaver.  I'm sure this is not the proper method so I thought I would ask those who know much more about working with templates than I do.
    Thanks in advance for your advice

    I suggested 1 template per layout because it's a practical approach that is simple enough for anyone to utilize. You don't need to be an expert with CSS. Also, this method can withstand any CSS layout you care to use -- even the DW starter pages.
    While Murray's approach is sound it will require some careful pre-planning.  Not all layouts are built the same way.  Choosing the right framework and having the CSS skills to work with it are essential.
    Use whichever methods fit your coding skills and those of the person(s) who will be maintaining this site.
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    http://alt-web.com/
    http://twitter.com/altweb

  • How do I set the column content to automatic break lines

    Hello Guys,
    I have a problem with the column width and the column content of a standard report. Within the report are hugh entries which aren't interrupted by an space character. I set my column width to a special value by usingen "css style: display block; width: 300px;". Now the problem is that some of the column entries have a longer width than the column width is setted. So they overlock the entries of the column next to them.
    My question is: How do I set the column content to automatic break lines after a certain count of characters?
    After researching a couple of websites and discussion thread I found maybe a reference to the solution. I hope it help you to give me an answer.
    COLUMN LAST_NAME FORMAT A4
    regards
    wderr

    Wderr,
    PDFs are another animal entirely. Try adjusting the width of the column under the Print Attributes tab of the report.
    If that doesn't work you'll probably need to create custom XSL-FO layouts which, depending on the tools you have at your disposal, could take some time.
    Regards,
    Dan
    Blog: http://DanielMcGhan.us/
    Work: http://SkillBuilders.com/

  • How to store multiple counts based on creation date

    Hi,
    I want to retrieve the count of number of risk  for each date and render it on line graph. I am retrieving data from sharepoint list where the number of risk counts increase with its creation and decreases after it is closure which maintained in another
    column. Like if a risk is created on 02/02/2015 and closes on 03/03/2015 and an another risk is created on 17/02/2015  and closes on 14/03/2015. Then the count of the risk from 02/02/2015 to 16/02/2015 is 1 and from 17/02/2015 to 03/03/2015 is 2  and
    then again till 14/03/2015 is 1. I want to retrieve the count based on the dates rendered dynamically on X-axis that is from current date back to past 24 days. I tried to create two datasets with one storing the risks after being queried based on creation
    date and closure date and retrieving the count from Graph Y values but it is returning me count 0.
    Please help.
    Thanks in advance. 

    Hi,
    I want to retrieve the count of number of risk  for each date and render it on line graph. I am retrieving data from sharepoint list where the number of risk counts increase with its creation and decreases after it is closure which maintained in another
    column. Like if a risk is created on 02/02/2015 and closes on 03/03/2015 and an another risk is created on 17/02/2015  and closes on 14/03/2015. Then the count of the risk from 02/02/2015 to 16/02/2015 is 1 and from 17/02/2015 to 03/03/2015 is 2  and
    then again till 14/03/2015 is 1. I want to retrieve the count based on the dates rendered dynamically on X-axis that is from current date back to past 24 days. I tried to create two datasets with one storing the risks after being queried based on creation
    date and closure date and retrieving the count from Graph Y values but it is returning me count 0.
    Please help.
    Thanks in advance. 

  • How to provide space between columns in alv_grid_display?

    hi,
    gurus,
    I want to provide space between columns in alv display how can i achieve that.
    ex.
    sno   name   street    
    thank u ,
    shabeer ahmed.

    Hi..,
      There you wl get column seperators with seperate blocks and cells in the grid anyway.
    Maintain gap between columns is nothing but grid breaking, its may be possible with oops concept.
    Let me know whats your requirement?
    Thanks,
    Naveen.I

  • How to create Implicit Fact column ?and how to use it ?

    Hi all,
    How to create Implicit Fact column ?
    and how to use it ?
    Thanks in advance

    When you create a request with only dimension columns, the Oracle BI engine has to choose a fact table to join the dimensions to each other. If you have multiple fact tables in your BMM layer, the Oracle BI engine will use the most economical fact table, depending on the number of dimensions of the fact table.
    In some cases you do not want to use this fact table, but you want to force the Oracle BI engine to use the fact table you want.
    In that case you should create a fact (or select an existing fact) of the fact table you want to use for the dimension only query. In the presentation catalog of the subject area you should select this fact as the implicit fact. This fact will always be used in the query, but it won't be visible in your report. An example of an implicit fact is the count of the primary key (id) of the fact table.

  • How to get Page Count of pdf in Document library in EventHandler

    Hi,
    How to get Page Count of pdf in Document library once uploaded has been done and i would like to update the page count value in document library column of the corresponding file.
    I should achieve it in Event handler.
    Which even should i use, either ItemAdded or "ItemUpdated "?
    Thanks & Regards
    Poomani Sankaran.

    Hello,
    If you are looking for file download or view count then event handler will not work. You need to enable the analytic report to your site. Once you enable it then you can see the report within a browser or you can also create custom webpart to show count
    of specific file.
    http://blogs.msdn.com/b/ecm/archive/2010/05/03/web-analytics-in-sharepoint-2010-insights-into-reports-and-metrics.aspx
    http://sharepoint.stackexchange.com/questions/34611/count-of-files-under-a-folder-in-a-document-library
    Hope it could help
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

Maybe you are looking for

  • PPR does not work - I need a workaround

    I have 2 boolean checkboxes nested in tabs; PPR does not seem to work, so I am using a method that does the rerendering for me if I pass in the component. However, in the case of checkboxes which are nested in a panel box, the rerendering fails with

  • Spool to PDF. Approach is Spool- app server then app server to local pdf

    Hello Experts, My requirement is: I want to create PDF file from spool number. As my program works in background and FM WS_DOWNLOAD/GUI_DOWNLOAD wonu2019t work in batch mode, I am trying to find its alternative. I am tiring to upload the internal tab

  • Reg:Error in MONI

    Hi Guys,           I had a error in MONI for File to IDOc  scenarion like"White spaces are required between publicId and systemId." Can you please give the solution. thanks

  • Whats better for mcb 15' - 6X8 or 6X11 intuos wacom tablet?

    hey guys i have a mac book pro laptop 15 inch im lookin to get an intuos wacom tablet...i want to know which one is best for the proportion of the screen...the 6X8 or 6X11??? thanks!

  • Where has the bookmark property for specifying the icon gone?

    In FF3 if I selected a bookmark and its properties, I was provided a field where I could specify the location on my PC for the desired icon for that bookmark. This was particularly true for specifying the icons for the Bookmarks Toolbar. I have the T