Generate random alphanumeric string as pk

Hallo,
I want to generate a random and unique alphanumeric string (4-digit).
Uniqueness is very important, because it will be used as primary key.
Is this supported by oracle 10?

You can try the sys_guid function:
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
PL/SQL Release 10.2.0.3.0 - Production
CORE    10.2.0.3.0      Production
TNS for Linux IA64: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
SQL> select sys_guid() from dual;
SYS_GUID()
439F46B40AAAFB59E04014ACAE650DC1
SQL> create table guid_tbl(str varchar2(300), constraint guid_tbl_pk primary key
(str));
Table created.
SQL> begin
  2  for i in 1..1000 loop
  3     insert into guid_tbl(str) values(sys_guid());
  4  end loop;
  5  end;
  6  /
PL/SQL procedure successfully completed.
SQL> select count(*) from guid_tbl;
  COUNT(*)
      1000
SQL>Amiel

Similar Messages

  • Random alphanumeric string

    Hi,
    I need one function which generates a Random alphanumeric string which I want to use as a primary key value. So it must be unique too.
    Something similar to sys_guid in oracle, However I need length of the string fixed to be 6. sys_guid is not helpful as it generates 32 characters long string.
    Can somebody help please?
    Thanks in advance!
    RK

    You can find many examples by doing a search on this forum:
    Alphanumeric sequence number generator

  • HOW TO GENERATE RANDOM MEANINGFUL STRINGS ?

    Friends,
    How do I generate random meningfull strings ? I know how to generate strings randomly but I want to generate meaningfull names. The length is not important. Please help me in this matter as I have to implement this soon.
    Thanks in advance
    Ankit.

    Thanks for reply,
    I want to generate any string randomly and also want to make sure that it is meaningfull name. I can use Random(0n class to generate random number then convert according to ascii table to char and concat these generated chars to have string but then it is not meaningfull string, it could be anything. I want the string to be meaningfull too.(any word or name in english language). I don't want to pick up already generated word or names from list randomly(i think this is what you are thinking)

  • Generating alphanumeric string

    Hi,
    I'm new to java programming and
    I was wondering if anyone could help.
    I need to generate an alphanumeric string
    consisting of one uppercase letter and 4 digits.
    Ant help gratefully received

    import java.util.Random;
    public class Test {
      private static final char[] uppercaseLetters = { 'A', 'B', 'C', 'D', 'E', 'F',
        'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'R', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
      public Test() {
        final StringBuffer sb = new StringBuffer();
        sb.append(uppercaseLetters[(int)(Math.random() * uppercaseLetters.length)]);
        for (int i = 0; i < 4; i++) sb.append((int)(Math.random() * 10));
        System.out.println(sb);
      public static void main(String[] args) {
        new Test();
    }

  • Random alphanumeric anyone?

    Hi guys. I was wondering how i can generate random alphnumeric strings like for example: f81d4fae-7dec-11d0-a765-00a0c91e6bf6. Is there a random function ready in java and if es how can it be used with alphanumeric characters. Any opinions would be appriciated.

    There are 62 alphanumeric characters
    0 to 9 = ascii 48 to 57:
    65 to 90 = ascii A to Z:
    97 to 122 = ascii a to z:
    1. Generate (however many) random numbers from 0 to 61
    2. If the number generated ... thrfr <in psuedocode>
    if(num < 10) myStr +=(char)num + 48;
    else if(num > 35)myStr +=(char)num + 62;
    else myStr +=(char)num + 55;
    3. Sorted!

  • Cp4 AS3 - using Javascript to generate a text string

    I'm a complete Javascript beginner, so please forgive me if this is a stupid question!
    I need to generate a pseudo random text string. I'm using the unpatched version of Cp4, AS3, Internet Explorer 7
    I've had a look at Captivate.Dev.com and the w3schools site to try to understand how to pass variables & basic javascript, and this is what I've come up with:
    var objCP = document.Captivate;
    function GenerateCode(){
    var rngen = new Array(8);
    var tgits = new Array(8);
    var cdrtn="";
    var lpdx=0;
    var mulier=1;
    for (lpdx=0;lpdx<=5;lpdx++){
    rngen[lpdx]=(Math.floor(Math.random()*9)+1);
    mlier=mulier*(rngen[lpdx]);
    tgits[lpdx]=rngen[lpdx]+"";
    cdrtn=cdrtn+tgits[lpdx];
    rngen[6]=(mlier%17)%10;
    rngen[7]=(mlier%13)%10;
    for (lpdx=6;lpdx<=7;lpdx++)
    tgits[lpdx]=rngen[lpdx]+"";
    cdrtn=cdrtn+tgits[lpdx];
    objCP.cpEISetValue('MyJavascriptVariable', cdrtn);
    GenerateCode();
    I've created a user variable called MyJavascriptVariable , put the code above in the On Slide Enter, Execute Javascript window on the first slide, and on the second a simple caption box showing the variable contents.
    However, when I press F12 I get an orange playbar at the top of the window, and in the middle the preloader and the captionbox (without the return value) flickering. i.e. classic sign of wrong AS version.
    If I change to AS2 the movie progresses ok, but the value the caption reports back for MyJavascriptVariable is blank.
    I know my core code works correctly - if I use the w3school's tryit editor with the code after the function declaration up to the closing curly before the objcCP line, with an addeded document.write to show the variable it works fine.
    It's clearly something to do with the way I'm declaring/passing the function or the way Cp runs the javascript. But what?
    Any help greatfully appreciated!
    Thanks

    Hi Jon,
    You are right... it works great on the W3Schools site.  Although in Cp, you ran into quite an issue using the modulus operater (%).  Looks like Cp needs the encoded version of this operator which is (%25).  Also, if you're using Cp4, then when you go to set the caption, you want to use objCP.cpSetValue();  Cp5 uses cpEISetValue.  I also try to use single quotes when working with strings.
    Here's the updated code:
    var objCP = document.Captivate;
    function GenerateCode() {
    var rngen = new Array(8);
    var tgits = new Array(8);
    var cdrtn='';
    var lpdx = 0;
    var mulier=1;
        for (lpdx=0; lpdx<=5; lpdx++){
            rngen[lpdx]=(Math.floor(Math.random()*9)+1);
            mlier=mulier*(rngen[lpdx]);
            tgits[lpdx]=rngen[lpdx]+'';
            cdrtn=cdrtn+tgits[lpdx];
    rngen[6]=(mlier %25 17) %25 10;
    rngen[7]=(mlier %25 13) %25 10;
       for (lpdx=6; lpdx<=7; lpdx++){
            tgits[lpdx]=rngen[lpdx]+'';
            cdrtn=cdrtn+tgits[lpdx];
    objCP.cpSetValue('MyJavascriptVariable', cdrtn);
    GenerateCode();
    This looks like some really crazy math.
    Let me know if this helps.
    Jim Leichliter

  • Sorting randomly genareted string in alphapetic order

    import java.util.*;
    public class test {
        public static char[] chars;
        public static Random random;
        static {
            chars = new char[26];//taking caracters from asci table
            for (int i = 0; i < 26; i ++) {
                chars[i] = (char) (97 + i);           
            random = new Random ();
        public static void main (String[] args) { //printing random characters
                for (int i = 1; i <= 10; i++ ) {                                                                          
                System.out.println(randomString(20)); 
        private static String randomString (int length) { //generating random
            char[] array = new char[length];
            for (int i = 0; i < length; i ++) {
                array[i] = chars[random.nextInt (chars.length)];
        return new String (array);
        i have this code.i found that in the forums and modified it a bit.but i have still problems to sort randomly genareted strings in alphabetic order.i have a method to do it.but i couldn't implement it correctly.the way that i try to sort them is
    void sort(String[] a) {
      for (int i=0; i<a.length-1; i++) {
         for (int j=i+1; j<a.length; j++) {
            if (a.compareTo(a[j]) > 0) {
    String temp=a[j];
    a[j]=a[i];
    a[i]=temp;
    thats a method i try to use but i couldn't put it in a correct place in the code and couldn't call him.always it gives error.pls help this unexprienced java user...

    Hard to understand your problems, because you're too vague. At one point you mention you don't know where to put your method, at another you say you don't know how to call your method. If that is the case (which seems unlikely but oh well) here's an example.
    public class Testing9 {
         public Testing9() { // constructor
              String basicString = "BasicExample";
              String sortedString = mySortMethod(basicString); // call mySortMethod passing the string
              System.out.println("sortedString = " + sortedString);
         public static void main(String[] args) { // main method starts app
              Testing9 app = new Testing9(); // calls constructor
         public String mySortMethod(String s) { // put the method here cause I feel like it
              String sortedString = "";
              // do your own work here to sort, etc....
              return sortedString;
    }

  • How to create a javabean that generate random password?

    May i know how to create a javabean that can generate random password?
    that include character and string
    and length of 10.

    i created a class file for my java bean
    package autogenerate;
    import java.util.*;
    public class GeneratePwId
    private int MemId;
    private String Passwd;
    public GeneratePwId(){}
    public String getPasswd()
    return this.Passwd;
    public void setPasswd()
    char[] letters = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
    'J', 'K', 'L', 'M', 'N', 'P', 'R', 'T',
    'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c',
    'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
    'm', 'n', 'p', 'q', 'r', 's', 't', 'u',
    'v', 'w', 'x', 'y', 'z', '0', '1', '2',
    '3', '4', '5', '6', '7', '8', '9' } ;
    String pwd = "" ;
    while( pwd.length() < 10 )
    pwd += letters[ (int)( Math.random() * letters.length ) ] ;
    this.Passwd = pwd;
    i successfully compile my java file. and try to test it by writing a jsp file.
    here is my jsp code
    <html>
    <head>
    <title>
    Try retrieving password
    </title>
    </head>
    <body>
    <jsp:useBean class"autogenerate.GeneratePwId" id="bean0" scope="page"/>
    <%=bean0.getPasswd()%>
    </body>
    </html>
    but i encounter this error
    org.apache.jasper.compiler.ParseException: /jsp/GetPasswd.jsp(7,18) Attribute class has no value
    anyone can teach me how to solve this problem?
    thanks a alot!

  • Generate random number and letter in a text field ...

    Hi All,
    I having a bit trouble when trying to generate random number and letter in application express in a text field. Say I have a licence form and when user wants to create a licence, it will provide a random licence number in the licence number field but it has to be unique. the number should be something like HQ2345. I was trying to set the following sql in default value for that text field but it is not working -
    select DBMS_RANDOM.STRING('',2) || trunc(DBMS_RANDOM.VALUE(1000,9999))
    from dual;
    any suggesion !!!!
    thanks

    Put this as default value for your text-item
    DBMS_RANDOM.STRING('',2) || trunc(DBMS_RANDOM.VALUE(1000,9999))
    with type PL/SQL Expression. It have tested it and it works fine.
    DickDral

  • Generating random numbers, while excluding some numbers

    I want to generate random numbers between 1 and 13 (including 1 and 13), while excluding numbers 6 and 9
    Please tell me theres an easy fix to this issue --

    lemme know if it compiles
    import java.util.*;
    public class RandomNumber {
    public static void main( String[] args) {
    int numWins = 0;
    for( int i = 1; i < 101; i++) {
    boolean x = true, y = true;
    int number = 0;
    while(!x && !y && number != 6 && number != 9)
    number = 1 + (int) (Math.random() % 13);
    x = number >= 1;
    y = number <= 13;
    int number2 = 0;
    while(!x && !y && number2 != 6 && number2 != 9)
    number2 = 1 + (int) (Math.random() % 13);
    x = number2 >= 1;
    y = number2 <= 13;
    int number3 = 0;
    while(!x && !y && number3 != 6 && number3 != 9)
    number3 = 1 + (int) (Math.random() % 13);
    x = number3 >= 1;
    y = number3 <= 13;
    int number4 = 0;
    while(!x && !y && number4 != 6 && number4 != 9)
    number4 = 1 + (int) (Math.random() % 13);
    x = number4 >= 1;
    y = number4 <= 13;
    int DrawAgain = 2;
    if (number == DrawAgain) {
    System.out.println( "A Random number between 1 and 10: " + number);
    System.out.println( "A second Random number between 1 and 10: " + number2);
    if (number2 == 8) {
    System.out.println( " Piece made it home successfully");
    numWins++;
    if (number2 == DrawAgain) {
    System.out.println( "A third Random number between 1 and 10: " + number3);
    if (number2 == 7) {
    System.out.println( " Piece made it home successfully");
    numWins++;
    if (number3 == DrawAgain) {
    if (number4 == 7)
    System.out.println( " Piece made it home successfully");
    numWins++;
    else {
    System.out.println( "A Random number between 1 and 10: " + number);
    if (number == 10) {
    System.out.println( " Piece made it home successfully");
    numWins++;
    System.out.println(" Number of times piece made it home successfully " + numWins);
    }

  • Need help with codings on generating random words

    hi guys.. i need help with generating random words from a list of array. please help me with the codings.. let me know the other variables that are needed if required as well.. thanks a million..
    private String wordList[] = { "abstraction", "command", "arithmetic", "backslash" };

    Hi,
    You can use the Random class to generate Random number between 0 to the array length and use the generated random number as index in to the Strign array.
    To generate Random number use the following code
    Random r = new Random();
    num = ((r.nextInt() >>> 1) % wordList.length);
    num will have the randomly generated number.

  • How can I generate random password

    Hello...
    I use oracle 10g for windows,,,I have an employee table , there are a lot of colunms , their names are employee_name , employee_id ,employee_pass .....
    employee_pass colunm is empty
    I want to generate random password for employee_pass colunm
    How can I generate random password for employee_pass colunm
    thanks
    omer faruk akyuzlu
    in Turkey

    SQL>  exec dbms_random.seed(to_char(sysdate, 'sssss'))
    PL/SQL procedure successfully completed.
    SQL> select dbms_random.string('X', 8) from dual
      2  /
    DBMS_RANDOM.STRING('X',8)
    4YT1H150
    SQL> select dbms_random.string('X', 8) from dual
      2  /
    DBMS_RANDOM.STRING('X',8)
    WIA3QCIP
    SQL> Please be aware that storing the actual passwords in a the EMPLOYEES table is a very bad idea. Oracle has a pretty good password implementation. It's not perfect but it's a darn site better than hand-rolling our own.
    Cheers, APC

  • How do you generate random data info using json and spry?

    I have a mobile applicaton that uses spry datasets that dynamically populate a jquery mobile listview by using a json file. Everything is operating as it should.
    However, I would like to understand how to pull random objects from the json file to have them displayed on a different page.
    My json file is standard and not complicated. It has several levels. Each is represented as below:
                                  { "Level1":
                                                                {"imageurl":"images/_myimage.png",
                                                                "someData":"S,A,P,R",
                                                                "levelLongDesc":"further description",
                                                                "name": "John Doe",
                                                                "page": "referencepage",
                                                                "description":"The description of the image"
    {"imageurl":"images/_myimage.png",
      "someData":"S,A,P,R",
      "levelLongDesc":"further description",
      "name": "John Doe",
      "page": "referencepage",
      "description":"The description of the image"
    Json file Level1 has about 70 objects
    What I would like to do is randomly load one of the Level1 object arrays into the page when the user selects a Level 1 radio button that is on the screen. I know how to create the page, radio buttons and basics, but just don't know how to pull in the random data.
    I've found one code sample on this site that speaks to spry and xml, but I haven't been able to apply it in any way that works for me with the json file:
    http://forums.adobe.com/message/662551
    I've also googled. There isn't much on spry datasets with json and generating random info. There was a little bit on sorting, but that didn't help either.
    Does anyone have a good example/tutorial of how to use the random function with spry/json?
    TIA
    -Rachel

    I've done similar things before.  A few thoughts for you:
    1. I'm assuming you're doing a buffered period or frequency measurement on the incoming encoder pulses, right?  First key point is that you'll have data that is spaced equally in position, but not equally in time.  If you are looking for a time-based FFT such that increasing speed will shift your spectrum, you're going to need to go through an interpolation process to resample your data as though equally-spaced in in time. 
    2. Your 149 pulse per rev encoder may be a significant source of error unless its 149 pulses are placed with extreme accuracy.  Any error in pulse placement violates your underlying assumption of data that is equally-spaced in position.  It'll be very helpful to send your data through a software lowpass filter to attenuate those artifacts. 
    3. I am not sure what you mean by "decompose the buffered data (array) into a single datastream."  You'll get an array of periods / frequencies from the call to DAQmx Read.  If you want to use it in a LabVIEW waveform datatype, you'll first need to do the resampling to create equally-spaced-in-time data.  The LabVIEW waveform datatype (and all the analysis functions like FFT that use it) depend on receiving data with a fixed constant time interval between samples.
    -Kevin P.

  • Finding the smallest letter in a single alphanumeric string

    How do I find the smallest letter in a single alphanumeric input?
    I already wrote and successfully tested the code that takes an alphanumeric string as input, separates the number from the alphabet, and creates a new alphabetic string. However, I'm unsuccesful in writting the code to find the smallest letter within the alphabetic string. I am almost certain that the easy answer is Arrays.sort, but I unsuccesfully tried writing the code to place the alphabetic string into an array. I researched compareTo, but I do not have another object to compare?! Any suggetsions?

    Ahh flaimbait - I'm sure I'll get criticized for this... but - while we are talking about time-to-market, etc...:
    The most important issue in development is to make sure that you understand the project requirements. The requirements in this situation were:
    Find the smallest character in a string.
    Given that, then any developer that goes through the trouble of looking up the sort APIs, etc... is not helping themselves - all they really needed to do was to write one line of code (as xxxx graciously posted):
    for (int x=0; x<foo.length(); x++) if (foo.charAt(i)<low) low=foo.charAt(x);I absolutely guarantee that any Java programmer could write the above faster than they could figure out how to split a string appart by characters, look up the arraysort API, etc...
    The arraysort functions are EXTREMELY efficient, and I would never suggest that someone re-implement them. The point here is that just because you've got a wrecking ball available, you can still use a hammer to drive a nail.

  • Generate random User Alias - Entity adapter

    Hi,
    I am a newbie. Can anyone please help me in telling steps for creating an Entity Adapter which generate a random User Alias.
    TIA.
    Got few threads that tell about pre-populate adapter, none for entity adapter.

    Hi,
    Follow the below steps to create new entity adapter in OIM
    To add the new created event handler to OIM server, perform the following steps:
    1. Write a java code to perform the needed operation ("Generate random user alias" in your case).
    2. Copy the file to OIM_HOME\xellerate\EventHandlers
    3. Open Design Console and navigate to: Development Tools -> Business Rule Definition -> Event Handler Manager
    4. Create a new Event Handler and specify:
    Event Handler Name: +<give the class name of your code>+
    Package: +<give the package name of your code>+
    Pre-Insert: Checked (for this scenario)
    5. Save the event handler
    6. Navigate to Development Tools -> Business Rule Definition -> Data Object Manager
    7. Search for "Users" and add the event handler to the Pre-Insert list.
    8. Save.
    Regards,
    NS

Maybe you are looking for