Generate a surregate key only when insert a new row - (SCD1)

Hi all,
I´m starting with OWB (10gR2) and I'm creating a simple template dimension with SDC type 1 with one source, one target and a sequence do generate the surrogate key.
The main properties configurations are:
- Target property: Loading type = INSERT/UPDATE.
- Only match the natural key between source and target.
- Only use the sequence.nextval when inserting a new row.
- Mapping: Set based.
The generated code was something like this:
{color:#000080}+MERGE INTO DIM_DEFAULT+{color}
{color:#000080}+USING SCR_TABLE+{color}
{color:#000080}+ON(SCR_TABLE.NATURALKEY=DIM_DEFAULT.NATURALKEY)+{color}
{color:#000080}+WHEN MATCHED THEN+{color}
{color:#000080}+UPDATE SET NAME=SCR_TABLE.NAME+{color}
{color:#000080}+WHEN NOT MATCHED THEN+{color}
{color:#000080}+INSERT(SK_DEFAULT,NATURALKEY,NAME)+ {color}
{color:#000080}+VALUES(SQ_DIM_DEFAULT.NEXTVAL,SCR_TABLE.NATURALKEY,SCR_TABLE.NAME)+{color}
Ok, it works fine! But the merge statement generates a new SK for each merged row even if the action is update! What I want is a new SK only when the process inserts a new row. Hard-coding, I possible solve this problem creating a function to return the nextval from a sequence and put it on the insert clause like this:
{color:#000080}+MERGE INTO DIM_DEFAULT+{color}
{color:#000080}+USING SCR_TABLE+{color}
{color:#000080}+ON(SCR_TABLE.NATURALKEY=DIM_DEFAULT.NATURALKEY)+{color}
{color:#000080}+WHEN MATCHED THEN+{color}
{color:#000080}+UPDATE SET NAME=SCR_TABLE.NAME+{color}
{color:#000080}+WHEN NOT MATCHED THEN+{color}
{color:#000080}+INSERT(SK_DEFAULT,NATURALKEY,NAME)+ {color}
{color:#000080}+VALUES(FN_SQC_NEXTVAL('SQ_DIM_DEFAULT'),SCR_TABLE.NATURALKEY,SCR_TABLE.NAME)+{color}
Hard-coded it works fine as I need and that´s the point that I want to know:
It´s possible perform this solution using OWB?
I tried to use Constants but this solution doesn´t work then I tried an expression calling my sequence.nextval function but the result was:
{color:#000080}+MERGE INTO DIM_DEFAULT+{color}
{color:#000080}+USING (SELECT FN_SQC_NEXTVAL('SQ_DIM_DEFAULT') AS SK_DEFAULT_0,NATURALKEY,NAME FROM SCR_TABLE) AS SCR_TABLE+{color}
{color:#000080}+ON(SCR_TABLE.NATURALKEY=DIM_DEFAULT.NATURALKEY)+{color}
{color:#000080}+WHEN MATCHED THEN+{color}
{color:#000080}+UPDATE SET NAME=SCR_TABLE.NAME+{color}
{color:#000080}+WHEN NOT MATCHED THEN+{color}
{color:#000080}+INSERT(SK_DEFAULT,NATURALKEY,NAME)+ {color}
{color:#000080}+VALUES(SK_DEFAULT_0,SCR_TABLE.NATURALKEY,SCR_TABLE.NAME)+{color}
It´s the same of merge the row using the SEQUENCE.NEXTVAL direct.
Does anyone have a workaround to solve this situation?

Hi,
Perhaps this comes a bit late but...
Have you tried to change attribute properties in the mapping? For simple example you have a source table in sa-stage which have to fields: code (varchar2(2), natural key) and description (varchar2(50)). You want to map those fields to target table where you have 3 fields: id (NUMBER(10), surrogate id, nextval from sequence when new row inserted), code (as from the source, natural key, the field to determine if the coming row is new or one to be merged) and description as in source table. Fields and datatypes are just for an example.
When you have source and target tables in your mapping (and fields mapped), drag the sequence operator to the mapping and map the nextval to target table's surrogate id field.
- Change target table operator properties:
* loading type = UPDATE/INSERT
* Match by constraint = no constraint
- Change target table attribute properties for:
* surrogate id field: Load column when updating row = no; match column when updating row = no; load column when inserting row = yes
* natural key field(s): Load column when updating row = no; match column when updating row = yes; load column when inserting row = yes
* all the regular fields: Load column when updating row = yes; match column when updating row = no; load column when inserting row = yes
- change the deleting rules as you want them to be
- Validate your mapping. If the green light is shown, the settings in field properties are suitable for merge.
Hope this is what you wanted to get. I think this kind of solution works fine. Trigger in the table that holds and where one inserts millions of rows sounds scary...
Regards,
jk
Added text: sorry about false alarm. I think that was what you did. The solution above steals the nextvals from sequence. Perhaps no-native-english-reader should be more careful when reading questions ;-)
Edited by: jkoski on 5.11.2008 1:30

Similar Messages

  • Textarea - space when inserting a new row !!!

    when I insert a new row with the editcurrent record, I get a space in each textarea.
    I don't understand why you write this like:...
    if(obj == null)
    sText = createMultilineTextField(sAttribute , " ");
    else
    The Db now contain a space caracter.
    Jean-Nokl WALLEZ
    [email protected]

    Hi, your code is right. So, replaces your blank space by the character 255 (ALT+255) and the blank space will be shown in your table.
    if(obj == null)
    sText = createMultilineTextField(sAttribute , " ");
    else
    Pakitwo.

  • How I disable my textbox at view time and Enable only when insert or edit t

    hi master
    Sir i have master detail form and i am not use toolbar i am usint my button add/edit/view/next/last and other
    sir my requirement is all textbox disable at view time enable ony edit or inserting time
    how I disable my textbox at view time and Enable only when insert or edit time.
    i use this
    if :system.form_status='change' then
    if :system.form_status='insert' then
    if :system.form_status='execute query' then
    but not right work
    please give my idea where i use what statment
    send me sample
    Aamir

    Aamir,
    Set the text item's Enabled property to False at design time. Then, using SET_ITEM_PROPERTY (see Forms Help), set to Enabled in the relevent part of the code on the WHEN-BUTTON-PRESSED triggers on your Insert and Update buttons. Similarly, disable on your Save button once the cnahges are saved etc.

  • Inserting a new row in a child table referencing an already existing parent

    I have two tables PARENT & CHILD (one to many), both of which are populated at different times.
    In our toplink mappings, parent contains a collection of child Domain Objects, & and child Domain object contains a one - one to parent.
    How can I insert a new row in a child table with reference to an already existing row in parent?
    When I fetch the parent Domain object and try to set it in the child Domain Object and use the unitOfWork.registerObject() it goes into a circular loop of selecting from 2 other tables.
    Please suggest.

    Odd, have you disabled caching and indirection? (NoIdentityMap, dontUseIndirection, or alwaysRefresh/disableCacheHits). If so, then this could be the issue.
    Otherwise please include the sample code you use to perform this, and verify that you do not have any unusual code in your set/get methods or in descriptor events. Also turn TopLink logging on and include a sample. Also ensure that you do not modify your objects until after registering them in the unit of work, and only modify the unit of work clones.

  • How to Insert the New Row in the  Workbook (b/w the Records)

    Hi All,
    In my workbook, I have 10 records.
    So my requirement is after 5 Records I want to Insert a New Row( ex: Total(1st Column) : SUM (2nd Column)of first five records )
    And remaining records should display the same after inserted row.
    For that what i did, Inserted a new row and put the sum for the first five records and save the workbook.
    Problem is when I refresh the workbook, The inserted row is disappearing.
    Please let me know can we do the aboue requirment or not?
    Regards
    Josu

    Hello joji,
    Please check this thread for changing working book template...
    check the last post by Bhanu..
    Re: Web Template creation .

  • BAPI to insert a new row in the MCHA table

    Hi all,
    I am in search of a BAPI to insert a new row in the MCHA table... with the fields of the materail, plant and batch values.
    Any inputs on this..is highly appreciable...
    thanks in advance...
    regards..
    prathima.

    explore BAPI_BATCH_CREATE

  • BAPI to insert a new row in the AUSP table

    Hi all,
    I am in search of a BAPI to insert a new row in the AUSP table... with the fields of the object and
    characteristic values.
    Any inputs on this..is highly appreciable...
    thanks in advance...
    regards..
    prathima.

    hi,
    from best of my knowledge  here is list of bapi through you can insert ausp table.
    check it.
    CLSE_SELECT_AUSP
    CLVF_INSERT_AUSP
    BAPI_CLASS_CREATE
    C14K_AUSP_CHANGE_VALUE
    CLSE_SELECT_AUSP
    CLVF_UPDATE_AUSP
    C14K_AUSP_ADD_UPD
    BAPI_CLASS_CREATE
    regards,
    vipul

  • How to insert a new row in the middle of an set of rows

    Hi
    How to insert a new  row in the middle of an set of rows ? and How to Reset the line id after the new row added ?
    Regards,
    Sudhir B.

    Hai,
    just try this,
    Instead of using omatrix.Addrow(1,-1) use like
    omatrix.AddRow( RowCount , Position)
    RowCount
    The number of rows to add (default is 1)
    Position
    The position of the new rows (0-based; default is -1, meaning append row to the end)
    After adding rows in matrix For, sno.
    for i=1 to omatrix.visualrowcount
    otext=omatrix.getcellspecific("columnid",i)  '--where columnid is the unique id of the sno column
    otext.value=i
    next i
    Hope this helps you.
    Thanks & Regards,
    Parvatha Solai.N

  • Query regarding inserting a new row at first row data table

    hi all,
    I have a doubt regarding the insertion of new row in data table.I am now using the following code
    if (skillDataProvider.canAppendRow()){
    RowKey rowkey = skillDataProvider.appendRow();
    skillDataProvider.setCursorRow(rowkey);
    String skillID=getSkilID();
    skillDataProvider.setValue("Skill.SkillID", rowkey, skillID);
    int rowID=Integer.parseInt(rowkey.getRowId());
    tableRowGroup1.setFirst(rowID);
    Its working fine.But this code gives me provision to add the data at the last of the table.I need it to be at the first row.I tried
    RowKey rowkey=skillDataProvider.insertRow(skillDataProvider.getRowKey(String.valueOf(0)));
    but it shows some null pointer exception.Can anyone help me?
    Thanks in advance
    Sree

    I think AChervov has the right idea here.
    CachedRowSetDataProvider.canInsertRow(beforeRow) returns false, so you cannot insertRow().
    Therefore, you'll need to control the sort order yourself. I'd add a sort field to the database. Then use TableRowGroup.setSortCrtieria() to control the table display order. Or commit the append to the database immediately and reselect (refresh) the provider (assuming the provider has the desired "order by").

  • How to insert the new row after current row in RowIterator - Steve Muench

    Hi,
    Our client wants the new row to be added after current row on the front end instead of before current row.
    we were using "new JUActionBinding(this,iterBinding,JUActionBinding.ACTION_CREATE_INSERT_ROW);" this code inserts the new row after current row.
    I tried a lot to insert the new row after current row. Used new JUActionBinding(this,iterBinding,JUActionBinding.ACTION_LAST to move the cursor to last row in rowiterator and the used .ACTION_CREATE_INSERT_ROW but this thing inserts the new row as the second last row.
    Could somebody plesae help ?
    Message was edited by:
    user556161

    I am using JDeveloper 9.0.4.2.0 (Build 1459)

  • Update statement inserts a new row instead of updating

    My code should just update a single specific row in the table. I used a simple procedure to update a record in the current application as well and it runs without any problem except this case. Every time the query runs, it actually inserts a new row instead
    of just updating an existing:
    So here is my c# code:
    try
    command.Parameters.Clear();
    command.Parameters.AddRange(vars);
    command.CommandText = "Update" + tableName;
    conn.Open();
    command.ExecuteNonQuery();
    conn.Close();
    this.GetData(tableName);
    catch
    throw;
    And here is my SQL code (please ingore 'Alter Procedure' statement, I just wanted to get the core script of the procedure):
    ALTER procedure [dbo].[UpdateExpenditureItems]
    (@ID int,
    @Name nvarchar(50),
    @IsGroup bit,
    @Parent nvarchar(50),
    @Description nvarchar(50)
    AS
    Begin
    --a new inserted row seems to be a result of running IF statement rather than ELSE
    if @Parent is not null
    begin
    declare @ParentID int
    set @ParentID = (select ID from ExpenditureItems where Name=@Parent);
    UPDATE ExpenditureItems SET Name =@Name, Parent =@ParentID, [Description] =@Description, IsGroup = @IsGroup WHERE ID=@ID;
    end
    else
    begin
    UPDATE ExpenditureItems SET Name =@Name, [Description] =@Description WHERE ID=@ID
    end
    end
    I ran the query itself from sql management studio and it works fine. The problem seems to be in c# code, but there's nothing unusual. Same code for operations with the databse works fine in other parts of the software... I appreciate your help!
    Thanks in advance!

    Please can you post your full C# code for this function? Also the code you sent is not calling an SP? so why do we need to validate against the SP?
    Fouad Roumieh
    So here is my code:
    //Update is called on OK button click
    private void okBut_Click(object sender, EventArgs e)
    //edit code runs here
    SqlParameter[] pars = new SqlParameter[5];
    pars[0] = new SqlParameter("@ID", int.Parse(idTB.Text));
    pars[0].SqlDbType = SqlDbType.Int;
    pars[1] = new SqlParameter("@Name", itemTB.Text);
    pars[1].SqlDbType = SqlDbType.NVarChar;
    pars[2] = new SqlParameter("@IsGroup", true);
    pars[2].SqlDbType = SqlDbType.Bit;
    pars[3] = new SqlParameter("@Parent", DBNull.Value);
    pars[3].SqlDbType = SqlDbType.Int;
    pars[4] = new SqlParameter("@Description", descTB.Text);
    pars[4].SqlDbType = SqlDbType.NVarChar;
    try
    DAL dal = new DAL();
    dal.UpdateData("ExpenditureItems", pars); //Update is called here
    catch (Exception ex)
    StaticValues.WriteEventLogXML(ex, this.Text);
    switch (StaticValues.user.Language)
    case "English":
    MessageBox.Show("Database error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    break;
    default:
    break;
    finally
    this.DialogResult = System.Windows.Forms.DialogResult.OK;
    StaticValues.currentNode = itemTB.Text;
    public void UpdateData(string tableNameString, SqlParameter[] vars)
    string tableName = tableNameString.Replace(" ", string.Empty);
    try
    command.Parameters.Clear();
    command.Parameters.AddRange(vars);
    command.CommandText = "Update" + tableName;
    conn.Open();
    command.ExecuteNonQuery();
    conn.Close();
    this.GetData(tableName);
    catch
    throw;
    And here is GetData procedure:
    public void GetData(string tableNameString)
    string tableName = tableNameString.Replace(" ", string.Empty);
    command.CommandText = "Get" + tableName;
    command.Parameters.Clear();
    if (!StaticValues.dataSet.Tables.Contains(tableName))
    StaticValues.dataSet.Tables.Add(tableName);
    else
    StaticValues.dataSet.Tables[tableName].Clear();
    try
    adapter.SelectCommand = command;
    conn.ConnectionString = DAL.ConnectionString;
    command.Connection = conn;
    conn.Open();
    adapter.Fill(StaticValues.dataSet.Tables[tableName]);
    conn.Close();
    catch
    throw;
    And this is my complete code for sql procedure:
    USE [ISWM project]
    GO
    /****** Object: StoredProcedure [dbo].[UpdateExpenditureItems] Script Date: 13.04.2015 9:09:36 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER procedure [dbo].[UpdateExpenditureItems]
    (@ID int,
    @Name nvarchar(50),
    @Parent nvarchar(50),
    @Description nvarchar(50),
    @IsGroup bit
    AS
    Begin
    if @Parent IS NOT null
    begin
    declare @ParentID int
    set @ParentID = (select ID from ExpenditureItems where Name=@Parent);
    UPDATE ExpenditureItems SET Name =@Name, Parent =@ParentID, [Description] =@Description, IsGroup = @IsGroup WHERE ID=@ID;
    end
    else
    begin
    UPDATE ExpenditureItems SET Name =@Name, [Description] =@Description WHERE ID=@ID
    end
    end
    The codes posted above work great in other similar parts of the application where select, insert, delete and update is required.
    Concerning my current problem - I ran the procedure itself in SQL Server Management Studio, and it works well. I would say that there's something wrong with my c# code, but it can't be wrong because it's quite simple and works in other place in my application...
    I really don't get what's missing...

  • I'm trying to insert a new row, but not a whole row  on  a spreadsheet, but all i can seem to do is insert a full complete row? iPad Air Wi-Fi

    I'm trying to insert a new row, but not a whole row  on  a  pages app spreadsheet, but all i can seem to do is insert a full complete row?

    What exactly are you trying to do? As I stated in your other thread, there is no such thing as a partial row.

  • Help!! How do you keep objects in the same order in a 20 page doc when inserting a new object?

    I am creating a catalog of pictures only, as objects.
    They are organized alphabetically, 4 images per page as a 2x2 grid, for 20 pages.
    I want to insert a NEW object (image) in the middle of these 20 pages, and want all the objects after it to shift over one spot to make room.
    How do I get the objects after the inserted ones to shift, as text would if you inserted more text in the middle of a paragraph?
    I can't figure out how do do that (without just putting the images in a text box and in-line, but then I lose all the spacing controls)...
    Thank you!
    Lawrence

    ID ships with a free Image Catalog script in the sample scripts. You don't need to buy one.
    And that isn't going to do what you want, exactly. You'd have to re-run the script each time you add an image to make a new file, and you don't get to set the sort order yourself.

  • Error when inserting a new record (Ctrl+Down)

    Hello,
    [http://img402.imageshack.us/my.php?image=12846351.jpg]
    Here the problem is : when i press Ctrl+Down (Insert new record), i enter data into all those fields, but i got an error
    Cannot Insert Record ("ROGER"."NUME") cannot be null (roger is my username which i logged on). And i completed all fields
    Also, when inserting data into fields, when i click on another field, it points me back automatically to the last completed field, then when i click again on the next field, i can enter data in that field. why the cursor cannot be on the next field when i first click there?
    i changed the property of the items Required = No (but however, in the database cannot be null).
    Please help if you can.
    Thanks

    For your other issue, with null fields on your forms.
    have you ever tried to log those fields value into a log table?
    A better and simple idea is:
    Create a temp table, with four columns: seq, section, message, type
    Where section is the column to condition any search you want to make
    message is the column to write anything you want
    type is the column which holds the tpe of the record, like info, debug, warn, etc.
    then create a database procedure
    this procedure must recieve the section, message, type and insert them into the log table and do commit.
    in yiour pre-insert trigger [forms level] or in your when-button-pressed or even better on your on-commit trigger [forms level]
    write the following code:
    begin
    database_procdure('MY_FORM_NAME', 'THE VALUES ARE: 1='||:1||' 2='||:2||' 3='||:3, 'INFO');
    end;
    After that you can do a select in your sql*plus with the following statement:
    select *
    from temp_table
    where selction like 'MY_FORM_NAME';
    then you can track if any of the values you think is null or has a value, in fact, has a value.
    best regards,
    Abdel Miranda
    AEMS Global Group
    Panama

  • Unable to refresh page when insert the first row in viewobject

    I am using JDeveloper 10g to develop a JSP page, DataAction, AppModule and ViewObject. But when I am trying to use the following code to insert the first row, the page is not getting refresh. The quite weird thing is when I insert the second row, it returns me the first row as well as the second row. And it works well when I am trying to insert the third row, forth row....
    //code in AppModule
    ViewObject vo= this.getSampleView();
    vo.insertRow(newRow);
    vo.setNewRowState(Row.STATUS_INITIALIZED);
    vo.setAttribute("STR1", str1);
    vo.setAttribute("NUMBER1",new NUMBER(1));
    vo.setAttribute("STR2", str2);
    getTransaction().postChanges();
    getTransaction().commit();
    //Note: SampleView is a simply view created from a EnityObject mapping to a single table.
    Anybody could help me? Thanks very much!

    //The following code is the method in AppModule, which is invoked when clicks on the Add Remarks button on web page.
    public void addRemarks(String strCustCode,String strRemarks,String strUserID)
    ViewObject voRemarks1 = this.getCrmCustomerRemarksView();
    ViewObject voRemarks2 = this.getCrmCustomerRemarksView();
    NUMBER newSeq = new NUMBER();
    try
    voRemarks1.setWhereClause(" CRM_CUST_CODE ='" + strCustCode + "'");
    voRemarks1.setOrderByClause(" CRM_SEQ_NO DESC");
    voRemarks1.executeQuery();
    if (voRemarks1.getEstimatedRowCount()<1)
    newSeq = new NUMBER(1);
    else
    Row row = voRemarks1.first();
    NUMBER seq = (NUMBER)row.getAttribute("CrmSeqNo");
    newSeq = seq.add(new NUMBER(1));
    SimpleDateFormat tmpLocalFormat = new SimpleDateFormat();
    Date tmpDate = new Date();
    tmpDate = Calendar.getInstance().getTime();
    tmpLocalFormat.applyPattern("yyyy-MM-dd");
    System.out.println("NGNCM003 add Remarks with " + strCustCode + "," strRemarks "," + strUserID);
    Row newRow = voRemarks2.createRow();
    voRemarks2.insertRow(newRow);
    newRow.setNewRowState(Row.STATUS_INITIALIZED);
    newRow.setAttribute("CrmCustCode", strCustCode);
    newRow.setAttribute("CrmSeqNo",newSeq);
    newRow.setAttribute("CrmCreatedBy", strUserID);
    newRow.setAttribute("CrmRemarks", strRemarks);
    newRow.setAttribute("CrmLastModifiedBy", strUserID);
    newRow.setAttribute("CrmCreationTimestamp",tmpLocalFormat.format(tmpDate));
    newRow.setAttribute("CrmLastModificationTime",tmpLocalFormat.format(tmpDate));
    getTransaction().postChanges();
    getTransaction().commit();
    catch (Exception ex)
    throw new RuntimeException("Invalid Sequence No.");
    }

Maybe you are looking for

  • How can I get Adobe .pdx file to work online?

    Hi, I am researching the possibility of putting our extensive contract library on a web server so that all concerned will be able to access it.  It already has a web front end, with all the documents linked within the library, and all documents have

  • Sharing external hard drives

    Hi folks, I have recently started to use Time Machine and I own two Macs, a MBPro and an iMac. The external disks (two) are FireWire and formatted to HFS+, and stay connected all the time to the iMac. Both Macs are running Leopard updated to 10.5.6.

  • Problem with N90 updated software

    I have a Nokia N90. A few days ago I've made a update to the phone's soft from the 3.0535.4.3 version to the 5.0607.7.3 version and I must say that I'm very dissapointed. My main complain is that now, when I am recording a video the image on the disp

  • How to view log of the exception occured in an application

    Hi All, While running the webdynpro application in the portal currently we are displaying some generic error messages in the catch block to make it user friendly. If some exception occurs, how is it possible for the user to view the error log in the

  • Safari opens up all my saved pages...

    When I start safari on my macbook air, safari opens up all of my pages that I have saved on top. Why does this keep happening? Anyone else who has the same problem as I do? This problem is not something that all the suddenly popped up after updating