How to best generate a unique alphanumeric key

Hi:
  I have a requirement to generate a unique alphanumeric key 20 characters long.
  I know that I can use sys.dbms_random.string('X', 20) but I also have a requirement to not include certain characters that could be missread, i.e. no 0 (zero), O(uppercase oh) and a few others.
  My questions are:
     1) Is there a way to tell dbms_random to not include certain characters in the key generation
     2) If the answer to 1 is No, what would be the best way to replace the unwanted characters.  I am thinking just do a translate right afterwards with a randomly generated set of characters that do not include the characters I am interested in and seeded
         upon package initialization.  Any other ideas.
    3) Is there a better way of meeting this requirement within PL/SQL?
Thanks,
Thomas

The most safe would be to use something like below if efficient enough
select listagg(x.ltr,'') within group (order by y.step desc) key
  from (select level lvl,
               substr(:alphabet,level,1) ltr
          from dual
        connect by level <= length(:alphabet)
       ) x,
       (with
        to_base(step,num,base,quot,remain) as
        (select 1 step,num,base,trunc(num / base) quot,mod(num,base) remain
           from (select :sequence_value num,length(:alphabet) base
                   from dual
                  where :sequence_value between power(length(:alphabet),:key_length - 1)
                                            and power(length(:alphabet),:key_length) - 1
         union all
         select step + 1,quot,base,trunc(quot / base),mod(quot,base)
           from to_base
          where num > 0
        select step,remain
          from to_base
         where num > 0
       ) y
where x.lvl = y.remain + 1
Regards
Etbin

Similar Messages

  • How can I generate multiple unique random numbers?

    Hello,
    I am trying to generate multiple random numbers between a given set of numbers (1-52) and not have the same number generated twice within that set. I can compare the last and next numbers with the compare function but how would I go about comparing all of the generated numbers without using a huge list of shift registers...
    Any help/ideas are welcome and appreciated.
    Jason
    Solved!
    Go to Solution.

    Here is an implementation of Jason's solution.
    steve
    Help the forum when you get help. Click the "Solution?" icon on the reply that answers your
    question. Give "Kudos" to replies that help.
    Attachments:
    random.vi ‏10 KB

  • Generate Unique Hash Key in PL/SQL

    I have a document that i want to send to certain customers. What I've decided to do is send the customer a link to the document that will be stored locally on our server. Obviously for security reasons i don't want to simply send the sequential doc ID allowing customers to change the query string to get other information.
    What would be the best way in pl/sql to generate a unique hash key to include in the url? The key would have to be both unique and not easily edited by customers to view other documents.
    Any help would be much appreciated.
    Faoilean.

    faoilean wrote:
    I've been experimenting with SHA-1 and it works very well in producing a 40 character hash. My one concern is that for example hashing '1025' produces the following hash 'B74E9CAD775D997FC742B45E1BA7BD5295D63D13'.
    Would someone not just simply be able to use SHA-1 to create a hash for '1026' (since i'm using a sequential number for my input) and consequently retrieve somebody elses information and leave my system vulnerable?
    Might i be better off to encrytp the input?I thought the point was that the "user" would only be provided with the hash value as a reference to the document and they would not have a clue how to alter that hash value to another value in order to retrieve a different document. Surely they don't know that the hash value they have relates to '1025' so a) how would they know that they can obtain the hash for '1026' to get the next document and b) how would they go about creating their own hash values unless you somehow give them access to Oracle's DBMS_CRYPTO package?
    If you really want to be sure then you could also also incorporate the date/time of the document into the string that you hash, so they would have to a) have access to the dbms_crpto package, b) know the filename and the date/time of the document and c) know what order to combine those things (and the format mask you've used on the date/time etc.) to provide the correct hash to obtain the document.
    If you use encryption then you leave yourself open to decryption.
    If you use hash then this is generally a 1 way mechanism, hence details are better hidden.
    I think you'll find when it comes to things like password storage, most will use a 1 way hash (or similar) algorithm rather than an encrypted password so that the stored passwords can never be reverse engineered. Also, such password algorithms usually combine the username or some other feature to prevent two users with the same password getting the same hash value.

  • How to generate Serial(Unique) Number for finished goods?

    Guru's,
    How do i generate Serial(Unique) Numbers for finished goods.Suppose,if we get an order for a finished good A of 10 qty.We want to generate unique number to identify each and every A item separately for quality purpose.Any help is much appreciated.
    thanks Guru's

    Depending on serial control of item, you will need to generate serial numbers at the time of WIP Completion transaction using Serial Entry window (i.e. if serial control is At Receipt) or at the time of job creation (i.e. if you are using serial control as predefined)
    In latter case, you will have to use MES or MSCA screens to perform serialized WIP completion.
    Thanks,
    Hrishi

  • How to generate a Unique key based on a some String value

    Hello every one,
    I am sorry , If I post this question in wrong group... I have a requirement to generate a unique key ( what every it may be alpha, numeric or alpha numeric) based on some String..
    For ex : String str = "AbCX" - Gives a unique key based on "AbCX" value..
    Is there any way we can get the unique value using Java ?
    Thanks

    May be not what you are looking for, but here's may idea:
    use a sequence (db sequence) and add it the the string value. This way the value is unique, because the sequence is unique. So you could omit the string theoretically, but your requirement is met.
    It's very easy to get a unique sequence number from the db using java, depending of the technology you use (which you did not say :-( )
    Timo

  • How do you insert new records into multiple tables using the same unique primary key?

    I’ve created a PHP site and MySQL server using a free app called XAMPP.  I have successfully created a form in Dreamweaver that will write data to a (name) table in the SQL database.  Here’s my question: How do you write to two (or more) tables in the same database and pass the same primary key to both tables?  In the SQL database, I defined the first field as ID and set it as the primary key with auto update.  So, when you insert a new record, it creates a unique primary key for that record.  In my form, I’m capturing info that needs to be stored to two tables at the same time; a Name table and Address table. Since the Name and Address tables use the ID field as the primary key, I believe I will need to pass the ID value from the Name table to the insert of the Address table to insure they both have the same primary key, right?

    No. You probably need the primary key from one table to be a foreign key in the other tables. In any case, I believe you can use two methods to obtain the auto generated key. First with SQL:
    http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html
    And the other using a PHP function:
    http://us3.php.net/mysql_insert_id

  • How to "auto" generate "Primary Key" in custom table?

    Hi Folks,
    Requirement:
    I need a function module or program that can create automatically a primary key.
    Scenario:
    I have a program that creates an entries and save it to a custom table at the same time, but a primary key should always be generated respective to the entries saved.
    Example:
    Material(MATNR) 4001001, Plant(WERKS) XX01, ID[Primary Key-auto generated]
    (I'm thinking of a similar concept/logic on how a unique IDOC number is being generated or how SAP standard creates a unique entry)
    I try to look for any SAP FM that can generate a PK, but there's no luck.
    Thanks.
    Regards,
    Jun

    Hi Keshu and All,
    The links are helpful, however:
    #1. I don't have authorization to create a new object in transaction SNRO, but the way I see the objects in SNRO is just for defining the length(number of characters) for the ranges that will be use if I'm not mistaken.
    #2. FM NUMBER_GET_NEXT - yes it can populate incremental unique entries but it's only occurring at runtime ?? So when the program get terminated it's not being saved nowhere.
    So after if I use FM NUMBER_GET_NEXT, I always have to look for all the last primary key in my custom table, then target it as my starting point for creating a new PK.  I think this will give a performance issue, any comments?
    For better visualization, I have scenario:
    1.  (ZQ_CREATE_PK) Create unique incremental PK for material, batch, so on..
    2.  Append line/entries to ZQ_TABLE
    3.  Repeat #1 and #2
    4.  User exits the program
    5.  Back to 1 --> At this point, I need to get the "LATEST" PK then start this as a starting point again to generate PK and append it to ZQ_TABLE
    I'm assuming that SAP has other SAP FMs related in creating this scenario.   Similar to IDOC # creation..
    Thanks.

  • How can I generate SSL Keys from a Oracle 9iAS server version 1.0.2.2.0

    How can I generate SSL Keys for use on Oracle 9iAS server
    version 1.0.2.2.0. I have tried using the open_ssl method but
    was unsuccessful.

    <?xml version="1.0" encoding="UTF-8" ?>
    <nodes>
    <node>
    <category_id>3</category_id>
    <parent_id>2</parent_id>
    <name>Mobile</name>
    <is_active>1</is_active>
    <position>1</position>
    <level>2</level>
    <children>
    <node name="Nokia" category_id="6" parent_id="3" is_active="1" position="1" level="3">
    <node name="Nokia N79" category_id="7" parent_id="3" is_active="1" position="2" level="3" />
    <node name="Nokia N95" category_id="7" parent_id="3" is_active="1" position="2" level="3" />
    <node name="Nokia N97" category_id="7" parent_id="3" is_active="1" position="2" level="3" />
    </node>
    <node name="Samsung" category_id="7" parent_id="3" is_active="1" position="2" level="3">
    </node>
    </children>
    </node>
    <node>
    <category_id>4</category_id>
    <parent_id>2</parent_id>
    <name>Laptop</name>
    <is_active>1</is_active>
    <position>2</position>
    <level>2</level>
    <children></children>
    </node>
    <node>
    <category_id>5</category_id>
    <parent_id>2</parent_id>
    <name>Monitor</name>
    <is_active>1</is_active>
    <position>3</position>
    <level>2</level>
    <children></children>
    </node>
    <node>
    <category_id>8</category_id>
    <parent_id>2</parent_id>
    <name>Camera</name>
    <is_active>1</is_active>
    <position>4</position>
    <level>2</level>
    <children></children>
    </node>
    </nodes>
    Is this correct format to create dynamic menu?

  • How to generate a unique WSDL for two webservices ?

    Hi ,
    Does anyone know if there is a way to generate a unique WSDL file for two webservices ?
    Actually, the problem is more general. I have two EJB that are exposed through web services. They both contain a simple data structure that is passed back and forth.
    The Client is a C# GUI and it is having problems with that data structure. Even if it is the same data structure with the same namespace, it seems it as two different objects and so creates two different stubs ...
    I am trying to work around that from the server side, bc it does not seem that we can do it from the C# application.
    First, I am trying to generate just one WSDL that would include both webservices but I can't seem to find an easy way of doing that.
    Second, I have heard that the complex types could be referenced externaly and I think that it would do the trick as well. I don't know how to do that either.
    I am using ServiceGen Ant tags to generate my web services from an EJB.
    Did anyone encounter that issue ?
    Can any one help ?
    Thanks a lot
    Farez

    hi,
    go to t-code SNRO and create a number range from 0 to 99999999.
    call the below fm in the report by passing the created number range name to fm to generate the new number every time..
    see
    NUMBER_GET_NEXT Get next free number in a range
    CALL FUNCTION 'NUMBER_GET_NEXT'
    EXPORTING
    NR_RANGE_NR = '01'
    OBJECT = 'YPOLLID'        "number range name created in SNRO.
    IMPORTING
    NUMBER = LS_NUMBER.       "new number with one increment..
    or
    you can try..
    you can use following code.
    select max( num ) from z_table into v_max_num.
    v_max_num = v_max_num+1.
    Regards,
    prabhudas

  • How to generate a unique 8 byte number for a String in DES

    Hi All,
    Is there any way to generate a unique 8 byte number representation of String?
    I know it can be done with DES encryption (while MD5 gives 16 bytes number). My requirement is:
    Every time a String is passed - my static method should return the same unique number - all the time.
    i.e A String "AAAAAA" will return same unique number all the time. How can I achieve this (8 byte number) by DES Encryption or any other encryption?
    Thanking all in advance.

    Thanks for your reply. Won't there be any loss of data if I consider only first 8 bytes? Will Integrity be maintained.?
    In some cases my Strings can be unusually long - having length of 400 to 500.
    I want 8 bytes as I want to map the number with MySQL bigint field.

  • How do I generate a TripleDES key from the user's password?

    Is there any standard way to generate a Key (for TripleDES for example) using a user provided password? I want to store encripted data and I see TripleDes key has to be 24 bytes long, so how do I generate it consistently and safely from the user provided password?
    I know how to actually build a key with the keyfactory, I'm talking about the aproach to generate good keys from a user entered string. It can't be random keys since I have to store those encripted files and restore them later.

    Is there any standard way to generate a Key (for
    TripleDES for example) using a user provided
    password? I want to store encripted data and I see
    TripleDes key has to be 24 bytes long, so how do I
    generate it consistently and safely from the user
    provided password?
    I know how to actually build a key with the
    keyfactory, I'm talking about the aproach to generate
    good keys from a user entered string. It can't be
    random keys since I have to store those encripted
    files and restore them later.Hi , i�m having the same problem, i was wondering if yoy found any solution so far.
    I�ve tried this
    SecretKey symmetricKey = SecretKeyFactory.getInstance("DESede").generateSecret(new PBEKeySpec("mypassword".toCharArray()));But it returns java.security.spec.InvalidKeySpecException: Inappropriate key specification
    I have also tried to this:
    SecretKey symmetricKey = SecretKeyFactory.getInstance("PBEWithMD5AndTripleDES").generateSecret(new PBEKeySpec(password.toCharArray()));But it results on different byte arrays whenever i try to do the encrypting, i mean it allways returns different encryptatios. I suposed it could be becaus it�s using some kind of random, and i need to have always a specific result.

  • My nice white and shiny  key pad is now not so white! how is best to clean it?

    My nice white and shiny  key pad is now not so white! how is best to clean it?

    http://support.apple.com/kb/HT3226 Click on Peripherals, and note especially be careful not to let liquids get inside openings.

  • Advice/Recommendation please? How to best handle big models with various schemas?

    Hi
    Using DM 3.3.0.747.
    We have several bespoke applications, each using its own data model in separate schemas.  They do share various entities/tables which are made available in a shared schema.  There are references to these shared tables, etc. (e.g. foreign keys)
    We want to embark on a process to reverse engineer and then maintain these applications' schemas in Data Modeller.
    I would really like your views on how to best approach this.  The main concern is that the bigger the design (or more models/sub-views) the slower actions like saving and loading it becomes.  Once you also have it version controlled more time is added onto saving and synchronising with the sub-version repository and between team members.
    The thinking is to primarily have each application (and hence its own schema) in separate designs (projects), but include tables from the shared/core schema as needed.  Would this be a good/recommended approach?
    How does one address potential changes made (differences introduced) that may conflict between these separate designs?
    e.g. in physical model the schema becomes a user that has permissions, etc.  and that same user may be in multiple designs.  Each design is version controlled, but in the end only exists once in the database.  If each design is synch'ed with the database, DDL generated and executed, this can cause one design to add permissions, etc. that the second DDL from the second design removes or replaces with its own?
    I hope my question/scenario is clear enough.  If not, please revert to me for more clarification.
    Thank you & Regards

    Hi Hans,
    I think it's better to use DM 4.0 and have everything in one design.
    1) You can import all schemas you need into one design (one relational model). Save that design - important to do it before using "remote objects" approach
    2) Use "Create new models based on schema names" wizard available in context menu for relational model in browser. Wizard will create new relational model for each schema in originating model and create there tables and views that
    belong to that schema. All objects in originating model become read-only "remote objects".
    If table (in new model) has a foreign key that refer table in another schema (now that table is moved to another new model) then "remote object" presentation is created for referred table.
    At the end you'll have one large model with read-only remote objects and set of relational models that keep the track of foreign keys between tables in different schemas in database.
    You can keep the originating model (the large one) in order to have global picture or delete it.
    Properties from physical model are also transferred to new models in DM 4.0.
    3) Check "Show 'Select relational models' dialog" in "Preferences>Data Modeler" - upon "open design"  that will bring up dialog allowing to select which model   to be loaded. The choice is persisted and
    applied next time you open design (no need to see that dialog again if no change in what to be loaded).
    4) For each model you can create "DDL generation" configuration (one or more) and exclude remote object from generation in DDL. Permissions should be maintained in model where table is editable and where DDL for that table will be generated.
    The thinking is to primarily have each application (and hence its own schema) in separate designs (projects), but include tables from the shared/core schema as needed.
    I won't recommend it. I know it's possible to have remote object in another design but you'll face following problems:
    1) You cannot use design level domains and definitions in data types model
    2) Remote object from another design are sensible to location of that remote design. You need to maintain the same directory structure everywhere designs (all related) are checked out and they need all to be checked out before dependent design to be open
    3) You need to add remote objects manually while wizard described above will do it for you in the scope of one design
    The main concern is that the bigger the design (or more models/sub-views) the slower actions like saving and loading it becomes.
    The number of models shouldn't be a problem with support of "Select relational models" dialog. Subviews will impact loading if only they are large and are visible when "save" is used.
    Total number of objects in model doesn't impact "save' operation - only modified objects are saved.
    Yes, there is overhead for versioned designs - one more reason to move to DM 4.0 - SVN client 1.7 is used there.
    Philip

  • Generating a unique ID to pass to Payment Provider?

    Hi.
    I have a site that has "orders" from customers which have a
    unique ID (PK).
    I'm using ASP / SQL.
    I was passing this ID to my payment service provider but have
    discovered
    that, if a customer for some reason cancels the order (highly
    likely), then
    that ID cannot be passed to the payment provider again.
    Therefore, when the
    customer logs back in to our site, they'll still see the
    order as "requiring
    payment" but when they try to re-submit the order, the
    payment provider
    won't allow it! Groan!
    Anyway, that is the way their system works, and I understand
    why I suppose
    (unique identifier 'an all that).
    So, my solution is to simply pass a unique value (which
    doesn't have to
    relate to my unique order ID) to the payment provider.
    My question is....how can I create/generate a unique value on
    my checkout
    page and ensure that the same value is never generated twice?
    Is there a
    feature in DW?
    Oh yes, and I need it to be a numerical value! :o)
    Thanks.
    Nath.
    Brain < Pea

    Here is a guaranteed unique algorithm for any string (sequence of characters.)
       String createMyId(String stringToEncode)
          String uniqueId = stringOfChars;
          return uniqueId;
       }The code above guarantees the following properties (expressed as psuedo logic code, not java code.)
    For any given sequence of chars A and B.
    If A = B is true if and only if createMyId(A) = createMyId(B)
    And of course
    If A != B is true if and only if createMyId(A) != createMyId(B)
    Of course the problem with the above algorithm is that it produces a variable sized value. But if you use a char array of of size Integer.MAX_VALUE then you can guarantee that it will work for any String in java. There is still a downside to this in that it requires a lot of data.
    Of course someone who is particularily observant might note that this suggests that one might as well just store the string. That however is just an optimization in the above algorithm and as nothing to do with the validity of the algorithm itself.

  • How can I permanently disable the "fn" key?

    Hi.  My subject says it all.  How can I permanently disable the "fn" key?
    At first I thought I had a virus or something because when I typed only weird symbols came out.  Then I reset the computer.  Then I couldn't even log in.  I tried Time Machine etc.
    Then I realized that the "fn" key wasn't working right.  It seems to be working backwards.  It acts like it's being pushed when it's not, and when I do push it it acts like it's not being used.
    So it's kind of a simple problem but it's really annoying.
    Is there a way I can just disable it permanently?  Even physical force if necessary.  I tried to break it but it wouldn't break.  I don't really use the key anyway so it doesn't really matter.  I don't want to pay a bunch of money to replace a key I don't even use.
    Thanks.  I hope someone knows.

    That's the best answer.  Yeah usually if you press "fn" or "option" you can get it to work for awhile.
    Yeah I have considered some kind of external keyboard also.  It will make a laptop less laptopish.  But it could do the job for awhile.
    It's sad because I don't even care about the "fn" or "option" keys.
    But anyway it's not catastrophic at least.
    And yeah maybe we can get a new computer later or something.  I like mine though.  It's customized and is how I like it right now.
    Anyway thanks for the reply.

Maybe you are looking for