Forum Discussion

amit_saroha's avatar
amit_saroha
New Contributor III
4 years ago

Generate Unique Sequence

Hi All,

I have a table in the Oracle database which has a unique key column. I have to insert data in this table and I am in need of generating a unique sequence while processing a file for each row. Could you suggest how to do it?

4 Replies

  • bojanvelevski's avatar
    bojanvelevski
    Valued Contributor

    By unique sequence you mean integers? If the field is Autoincrement, pass only null , the DB engine will do the assignment of a primary key.

    • amit_saroha's avatar
      amit_saroha
      New Contributor III

      @bojanvelevski - Yes, integers. The database version is old, it can’t generate itself so it must be passed to it via snap logic by any method.

      • bojanvelevski's avatar
        bojanvelevski
        Valued Contributor

        Well, it’s a bit tricky, but manageable. You can take the highest id (I’m presuming it’s an id field) with a select call to the database, and use that value to calculate the following ids, by including the snap.in.totalCount method.

        To calculate the ID, use the following expression in a mapper:

        $value_from_db + snap.in.totalCount