Seperate Sequence for Separate Column in a Table

I have following table
id,        Inv_no,         Item,          Item_Sequence
1, 132 , Processor,     
2 , 132 , RAM,     
3 , 132, DVD ROM,     
4 , 133 , Processor     ,
5, 133 , RAM,     
6 , 133 , DVD ROM     ,
7 , 953 , Processor,     
8 , 953 , Harddisk,     
9 , 953 , RAM,     
10 , 953 , DVD ROM     ,
I want to generate autosequence for "*Item_Sequence"* column, let say for processor i want pr-001, p1-002, pr-003 , and for RAM, it can be ram-001, ram-002 ......................
if i input any item it should start creating auto number for that,
If any one can help me here, Thanks in Advance
Kind Regards
Abbas
Edited by: Abbas on Apr 3, 2011 10:42 AM
Edited by: Abbas on Apr 3, 2011 10:43 AM
Edited by: Abbas on Apr 3, 2011 3:13 PM

Abbas wrote:
I want to generate autosequence for "*Item_Sequence"* columnFirst of all, sequence does not guarantee "no holes". If, for example, session inserting in your table rolls back or if sequence has CACHE and you restart database, seaquence will have holes. Said that, just for fun (I'd do extensive testing before using it in production):
SQL> create table inventory(
  2                         id     number,
  3                         Inv_no number,
  4                         Item   varchar2(50),
  5                         Item_Sequence number
  6                        )
  7  /
Table created.
SQL> create or replace
  2    function get_nextval(
  3                         p_seq_owner varchar2,
  4                         p_seq_name varchar2
  5                        )
  6      return number
  7      is
  8          pragma autonomous_transaction;
  9          v_cnt number;
10      begin
11          select  count(*)
12            into  v_cnt
13            from  dba_sequences
14            where sequence_owner = upper(p_seq_owner)
15              and sequence_name  = upper(p_seq_name);
16          if v_cnt = 0
17            then
18              execute immediate 'create sequence ' || p_seq_owner || '.' || p_seq_name;
19          end if;
20          execute immediate 'select ' || p_seq_owner || '.' || p_seq_name || '. nextval from dual' into v_cnt;
21          return v_cnt;
22  end;
23  /
Function created.
SQL> create or replace
  2    trigger inventory_bir
  3      before insert
  4      on inventory
  5      for each row
  6      begin
  7          :new.Item_Sequence := get_nextval('scott',replace(:new.Item,' ','_'));
  8  end;
  9  /
Trigger created.
SQL> insert into inventory(id,inv_no,item) values(1, 132 , 'Processor');
1 row created.
SQL> insert into inventory(id,inv_no,item) values(2 , 132 , 'RAM');
1 row created.
SQL> insert into inventory(id,inv_no,item) values(3 , 132, 'DVD ROM');
1 row created.
SQL> insert into inventory(id,inv_no,item) values(4 , 133 , 'Processor');
1 row created.
SQL> insert into inventory(id,inv_no,item) values(5, 133 , 'RAM');
1 row created.
SQL> insert into inventory(id,inv_no,item) values(6 , 133 , 'DVD ROM');
1 row created.
SQL> insert into inventory(id,inv_no,item) values(7 , 953 , 'Processor');
1 row created.
SQL> insert into inventory(id,inv_no,item) values(8 , 953 , 'Harddisk');
1 row created.
SQL> insert into inventory(id,inv_no,item) values(9 , 953 , 'RAM');
1 row created.
SQL> insert into inventory(id,inv_no,item) values(10 , 953 , 'DVD ROM');
1 row created.
SQL> select  *
  2    from  inventory
  3    order by item,
  4             id
  5  /
        ID     INV_NO ITEM                                               ITEM_SEQUENCE
         3        132 DVD ROM                                                        1
         6        133 DVD ROM                                                        2
        10        953 DVD ROM                                                        3
         8        953 Harddisk                                                       1
         1        132 Processor                                                      1
         4        133 Processor                                                      2
         7        953 Processor                                                      3
         2        132 RAM                                                            1
         5        133 RAM                                                            2
         9        953 RAM                                                            3
10 rows selected.
SQL> Obviously, performance will be questionable for high(er) volumes. Also, you will need to add error handler for sequence creation to ignore sequence already exists situations which can happen in multi-session environment.
SY.

Similar Messages

  • How to generate a  number sequence for a column of a Z*table?

    Hi ,
    How to generate a  number sequence for a column of a Z*table?
    plz guide me.
    thanks
    Albert

    1) Use SNRO for defining a number range.
    2) Use FM NUMBER_GET_NEXT for getting the next number with object, sub object etc..
    See one example below.
          CALL FUNCTION 'NUMBER_GET_NEXT'
            EXPORTING
              nr_range_nr                   = c_01
              object                        = c_z_prd_code
    *           QUANTITY                      = '1'
             subobject                     = p_vkorg
    *           TOYEAR                        = '0000'
    *           IGNORE_BUFFER                 = ' '
           IMPORTING
             number                        = in_prd_code
    *           QUANTITY                      =
    *           RETURNCODE                    =
            EXCEPTIONS
                  interval_not_found            = 1
                  number_range_not_intern       = 2
                  object_not_found              = 3
                  quantity_is_0                 = 4
                  quantity_is_not_1             = 5
                  interval_overflow             = 6
                  buffer_overflow               = 7
                  OTHERS                        = 8
    3) You may write these code in main program of the table maintinence
    rgds,
    TM.

  • Get frequent data for each column of a table

    What is the best way to get the most frequent data in each column of a table.
    we have around 25 tables and each table has around 20 columns , so rather than writing group by for each column of table , is there any easy way to find this?
    example we have table
    Column A       Column B         Column C
    Apple             Monday             Red
    orange            Tuesday            Green
    Apple              Monday            Red
    Lemon            Wednesday       Green
    Apple               Thursday         Red
    in this table, column A's frequnt data is Apple , column B's frequent data is Monday , Column C's frequnt data is Red
    Apple 3          Monday 2                  Red 3
    Orange 2        Tuesday 1                 Green 2
    Lemon 1          Wednesday 1         
                          Thursday 1
    Group by kind of query will give this result, but with 20 tables each having 20 - 30 columns if we need similar kind of result ..  is there any way to get this data.

    Hi,
    GROUP BY (using aggregate functions) is the best way to do what you described.
    PIVOT and UNPIVOT are probably what you'd want in this case.  The phrase "GROUP BY" may not actually appear in your code, but you'll essentially be doing a GROUP BY.
    Analytic functions (rather than aggregate functions) can do the job, too, but they'll be less efficient.  Analytic functions get you results about the groups, without losing each row's identify, but in this case, losing each row's identity is eactly what you want to do.  You only want 'Apple' to appear 1 time, not 3 times.
    The fact that you need to do the same query on 20 different tables suggests that there's something wrong with your table design.  Wouldn't it be better to have 1 big table, with a new column that has 20 unique values instead?
    I hope this answers your question.
    If not, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved, so that the people who want to help you can re-create the problem and test their ideas.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    Simplify the problem as much as possible.  For example, instead of posting a problem with 20 tables, each having 25 columns, post a similar problem involving, say, 2 tables, each with 3 columns.
    Always say which version of Oracle you're using (for example, 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • How does Toggle Visible for a Column in a Table work ?

    Hi All,
    I have a question for you.
    Using version 11.1.1.7:
    I was playing with a use case where I need to show and hide columns in an af:table component.
    I want to do this clientside using javascript.
    Guess what: It works, however, it only works for hiding columns ?!
    Initially I have client component = true and visible is true.
    See javascript below.
    When I call hideColumn, the component is found and hidden after calling.
    When I call showColumns (after it is hidden) the component cannot be found anymore.
      function showColumn(evt){
          var col = AdfPage.PAGE.findComponentByAbsoluteId("pt1:pc1:t1:c9")  ;
          col.setVisible(true);    
       function hideColumn(evt){
          var col = AdfPage.PAGE.findComponentByAbsoluteId("pt1:pc1:t1:c9")  ;
          col.setVisible(false);    
        }I checked and when the columns visible property is initially false, the column is not found by AdfPage.PAGE.findComponentByAbsoluteId("pt1:pc1:t1:c9"), which means it is not available ?!
    It looks like the visible property for an af:column works slightly different then for other components such as buttons.
    Also makes me wonder how the panelCollection component shows and hides columns. Doesn't that component do exactly the same ?
    Thanks.

    Luc,
    couldn't find a hint in the sources (maybe didn't spend enough time). However, one reason for this behavior would be if the hidden column had no client component created (in which case it only exists as hidden HTML). The work around I think would be to use a serverListener on the table and to pass the columns to show/hide as the payload for server side show/hide
    Frank

  • Filtering feature for a column in a table view

    Hi,
    I have a table view in which the column should have a feature of filtering.
    How do we enable that.
    Thanks and Regards,
    Radhika

    Hi Radhika,
    I don't understand exactly why you're looking for a specific procedure to enable the filtering feature. Column filtering should be available for all tables in CRM2007 by default without further action. There are only few cases where filtering doesn't work.
    You can open the dropdown for sorting and filtering in the WebClient UI by just clicking the column header.
    Are you referring to a SAP delivered view or a custom built one. in the latter case make sure you use the "thtmlb:cellerator" tag instead of the "thtmlb:tableView" one to be on the safe side.
    Best regards
    Peter

  • Constraint based on existing values for a column in the table

    I have a table as follows
    create table MS_FAV_ACCT
    NICKNAME VARCHAR2(50) not null,
    ACCOUNT VARCHAR2(6) not null,
    SUB_ACCOUNT VARCHAR2(3) not null,
    DETAIL VARCHAR2(4) not null,
    ICID VARCHAR2(3) not null,
    SEGMENT VARCHAR2(2) not null,
    PRIMARY_ACCT VARCHAR2(1) not null
    I want to have a constraint such that there can be only one row with PRIMARY_ACCT ='Y' there could be multiple rows with value 'N'.
    I have put a CHECK constraint on this column to check for values Y or N but I want to be able to check this condition too that only one row can have PRIMARY_ACCT as Y .
    I saw a thread on this forum regarding using UNIQUE INDEX with case when but didnt understand how I could use it in my case.
    Could anyone please help?

    You only want to have 1 row in the table with an identifier of 'Y'?
    That is what i understood, in which case you can use something like this.
    ME_XE?create table MS_FAV_ACCT
      2  (
      3     NICKNAME VARCHAR2(50) not null,
      4     ACCOUNT VARCHAR2(6) not null,
      5     SUB_ACCOUNT VARCHAR2(3) not null,
      6     DETAIL VARCHAR2(4) not null,
      7     ICID VARCHAR2(3) not null,
      8     SEGMENT VARCHAR2(2) not null,
      9     PRIMARY_ACCT VARCHAR2(1) not null
    10  );
    Table created.
    Elapsed: 00:00:00.03
    ME_XE?CREATE UNIQUE INDEX MS_FAV_ACCT_U01 ON MS_FAV_ACCT (CASE WHEN  PRIMARY_ACCT = 'Y' THEN 1 ELSE NULL END);
    Index created.
    Elapsed: 00:00:00.01
    ME_XE?
    ME_XE?INSERT INTO MS_FAV_ACCT VALUES('ONE','TWO', 'U','I','X','A','N');
    1 row created.
    Elapsed: 00:00:00.00
    ME_XE?INSERT INTO MS_FAV_ACCT VALUES('ONE','TWO', 'U','I','X','A','Y');
    1 row created.
    Elapsed: 00:00:00.00
    ME_XE?INSERT INTO MS_FAV_ACCT VALUES('ONE','TWO', 'U','I','X','A','N');
    1 row created.
    Elapsed: 00:00:00.01
    ME_XE?INSERT INTO MS_FAV_ACCT VALUES('ONE','TWO', 'U','I','X','A','Y');
    INSERT INTO MS_FAV_ACCT VALUES('ONE','TWO', 'U','I','X','A','Y')
    ERROR at line 1:
    ORA-00001: unique constraint (TFORSYTH.MS_FAV_ACCT_U01) violated

  • Global display options for equal columns of different tables

    Hi,
    is it possible to create some kind of templates for tables which are nearly the same! I mean different table names, different content and some columns are equal.
    e.g. I've got a a lot of Error tables, in every table there is a column named Reload Flag, which should be displayed as a List of value, can i set this by default. Or for example I've got a column named Error message and i display it as a standard report column, but i always have to edit the column formatting, because the column is very broad. I have to change the CSS Style ( {width:30em;} )!
    THX Mat

    Hi,
    Yes, It must be working using rowid since its not mention anywhere, I could not post it. But I too think so.
    check the below block
    SQL> Declare
      2  v_mydept1 emp.deptno%TYPE;
      3  v_mydept2 dept.loc%TYPE;
      4  CURSOR C1 IS SELECT e.deptno,d.loc
      5  FROM emp e,dept d
      6  WHERE e.deptno = d.deptno
      7  and empno=7900
      8  FOR UPDATE of e.sal;
      9  Begin
    10  OPEN C1;
    11  LOOP
    12  FETCH C1 INTO v_mydept1,v_mydept2;
    13  Dbms_output.put_line(v_mydept2);
    14  Dbms_output.put_line(v_mydept1);
    15  EXIT WHEN C1%NOTFOUND;
    16  UPDATE dept SET loc = 'NY' WHERE CURRENT OF C1;
    17  select loc into v_mydept2 from dept where deptno=v_mydept1;
    18  Dbms_output.put_line('Record updated '||v_mydept2);
    19  End loop;
    20  COMMIT;
    21  End;
    22  /
    Declare
    ERROR at line 1:
    ORA-01410: invalid ROWID
    ORA-06512: at line 16The logic doesnot make sense, but if you can notice the error speaks about rowid.
    For update locks the specific rows listed in the cursor and Where Current Of Clause must be taking in account the rows as per thier ROWID.
    Twinkle
    Edited by: Twinkle on Apr 8, 2010 4:28 PM

  • How to make allow null for a column in all table.

    Hi,
    I have a column "col1" in all tables (user made table) , i want to make it allow null
    please tel me how can it be done using single script.
    i mean in short way.
    yours sincerely.

    yes. absolutely you can.
    Look, what i got -
    Ranit>>  select 'alter table ' || table_name || ' modify("TIMESTAMP" null) ; ' from user_tab_columns where column_name='TIMESTAMP' and nullable ='N';
    'ALTERTABLE'||TABLE_NAME||'MODIFY("TIMESTAMP"NULL);'                           
    alter table FIXED_OBJ$ modify("TIMESTAMP" null) ;                              
    alter table SUMPARTLOG$ modify("TIMESTAMP" null) ;                             
    alter table SUMDELTA$ modify("TIMESTAMP" null) ;                               
    alter table ALL_SUMDELTA modify("TIMESTAMP" null) ;                            
    alter table DBA_EXP_FILES modify("TIMESTAMP" null) ;                           
    alter table WRI$_DBU_CPU_USAGE modify("TIMESTAMP" null) ;                      
    alter table DBA_CPU_USAGE_STATISTICS modify("TIMESTAMP" null) ;                
    7 rows selected.But, it is not over.
    Either - You have to do an 'EXECUTE IMMEDIATE' over these 'alter' scripts.
    OR - Take these scripts, put it into a <script_name>.sql file and then execute this file.
    Hope you understand.
    Edited by: ranit B on Dec 22, 2012 3:17 PM
    -- code added

  • How to Embedded a Graph for one column in pivot table in OBIEE 11.1.1.7.0

    Hello,
    Please let me know how to achieve the below requirement
    I have to display the report with time , section, total students, passed ,failed and display column which as to be a red and green notation..Is it possible to build a report as below?
    Time
    section
    Total students
    Passed
    Failed
    Display column
    2009
    SA_A
    100
    90
    10
    Thanks for the Help!! Highly Appreciated!!
    Thanks
    SR

    Hi Sr,
    There is Trails view in Result . which is newly introduced by Oracle.
    With the help of this you can achive this solution.
    Thanks & Regards
    Rahul

  • Displaying of charts as a separate column in table view view in obiee 11g

    Hi all,
    we have a requiremnet where i need to display charts in a separate column in a table view in OBIEE 11g. can any body help in achieving this requirement?
    Thanks in advance.
    Regards

    HI All,
    Can any body let me know how to achieve this requirement!
    charts also should be dsplayed in a column in table. I had gone through below Sparkline graph link but didn't move forward with Jquery. can any body help me in understanding this?
    http://srisnotes.com/tag/obiee-11g/.

  • Setting different Tabel Cell SemanticColor for Multiple Columns of each row

    Hi,
    I have requirement of setting different colors to different columns for each row based on some condition in table data.
    The data to table is coming from model, hence table is mapped to model node and attributes.
    I have created Seperate Node CellColorNode with attribue CellClr1 and CellClr2 of type TextView Semantic Color.
    Set the calculated, read only attribute to True. Mapped table columns text view to the CellColorNode->CellClr1 and CellColorNode-->CellClr2 correspondingly.
    Now, my query is how do i set the colors to CellClr1 and CellClr2 attributes. As I need to set the color for multiple columns of each table row.
    Is it in method getColorCellCellClr generated? Any  Example Code?

    Its resolved by following below link
    http://scn.sap.com/thread/158286

  • Is there a way to have tooltips for every column in a TableView?

    Hi there!
    I found in documentation that any node and control can show a tooltip ( http://docs.oracle.com/javafx/2/api/javafx/scene/control/Tooltip.html ) but I can't get tooltips to work for TableColumn (a column from TableView).
    Do you have any idea how could I have tooltips for each column of the table view?

    TableColumn's are neither controls nor nodes, so you can neither set nor install tooltips on them.
    You can use cellfactories to set tooltips on cells generated from the factories.
    You can use css style lookups (node.lookup function) to get access to table nodes (such as the headers) after the tableview has been displayed on a stage and then manipulate the displayed nodes to add tooltips. It's not a great approach, but it is the only approach I know at the moment that would work.

  • Grant select privilege to specific columns on a table to user in Oracle 9i

    Can anyone tell me how to grant select privilege to a user for specific columns in a table?
    I have tried the following statement
    GRANT SELECT (EMP_ID) ON EMP TO USER1
    But it's not working and I am getting this error "Missing ON Keyword".
    Please anyone tell me how to grant select privilege for specific columns.
    Edited by: 899045 on Nov 24, 2011 7:03 AM

    899045 wrote:
    Can anyone tell me how to grant select privilege to a user for specific columns in a table?
    I have tried the following statement
    GRANT SELECT (EMP_ID) ON EMP TO USER1
    But it's not working and I am getting this error "Missing ON Keyword".
    Please anyone tell me how to grant select privilege for specific columns.
    Edited by: 899045 on Nov 24, 2011 7:03 AMFrom the 9.2 SQL Reference manual, found at tahiti.oracle.com (http://docs.oracle.com/cd/B10501_01/server.920/a96540/statements_912a.htm#2062456)
    *"You can specify columns only when granting the INSERT, REFERENCES, or UPDATE privilege. "*

  • Using default values for a column

    Hi,
    I am using PL/SQL Developer, where for some columns in a table I've defined 0 as default value.
    After running some queries on the table (insert,update) I realized that all the columns that are supposed to have 0 value (default), actually have NULL value.
    Please advice about possible reason.
    Thanks

    Hi,
    You might have explicitly inserted a NULL value in those columns. Have a look at the below test case:
    SQL> create table test(a number, b number default 0, c number default 1);
    Table created.
    SQL> insert into test (a) values (10);
    1 row created.
    SQL> select * from test;
             A          B          C
            10          0          1
    SQL> insert into test (a, b) values (10, null);
    1 row created.
    SQL> select * from test;
             A          B          C
            10          0          1
            10                     1
    SQL> insert into test (a, b, c) values (10, null, null);
    1 row created.
    SQL> select * from test;
             A          B          C
            10          0          1
            10                     1
            10
    SQL> insert into test (a) values (20);
    1 row created.
    SQL> select * from test;
             A          B          C
            10          0          1
            10                     1
            10
            20          0          1Regards

  • Search for a column in schema

    Hi ,
    Is there a way to search for a column exist in tables of particular schema ?
    thanks in advance

    user10641405 wrote:
    Hi ,
    Is there a way to search for a column exist in tables of particular schema ?
    You need to clarify "exists". Do you mean exists regardless if you have acces to it or "exists" means you have access to it? For the former use:
    SELECT  OWNER.TABLE_NAME
      FROM  DBA_TAB_COLUMNS
      WHERE OWNER = '<schema name>'
        AND COLUMN_NAME = '<column_name>'
    /For latter use ALL_TAB_COLUMNS instead as it was suggested by others.
    SY.

Maybe you are looking for

  • Meid no longer working with ting after recent update

    Hey guys i have a 4s with an meid of 99000, was working fine then the recent update seems to have changed the meid or something because it was different then the one originally supplied to ting my provider, and it no longer works on any network it se

  • Why does Firefox v 7.0 no longer pass downloads to Speed Download?

    All my Browsers worked with Speed Download v. 5.2.28 doing the downloading for them (installed are Safari 5.0.5, Chrome 14, and Camino 2.0.9), but since updating to v 7.0 Firefox no longer seems to allow the downloads to be handled by SpeedDownload.

  • Recover Songs  Deleted accidentally

    I accidentally deleted a Whole Genre and many songs, rather then delete one duplicate song, whihc is what i wanted. Most songs not fro ITUNEs store but from disks, whihc i no longer have. As a result, i've deleted many fav. songs. I cannot find in It

  • Request shows in Red status after extraction of Data from Planning area

    Hi Experts, I am extracting data from DP planning area to APO BW Info Cube. It was working fine but from last few days after extraction we are getting Red status of that request. However whatever data packages we are extracting we are getting same in

  • Add columns to attachment overview

    Hi gurus, On SRM portal I've added an attachment to the shopping cart and I see the columns: Description  Category  Version  Processor  Typ  File Size (Kb)  Inter.  Changed By  Changed on  I want to add a few columns, how do I do this? I've searched