Oracle | Random Strings

STRING

Create Random Strings
dbms_random.string(opt IN CHAR, len IN NUMBER)
RETURN VARCHAR2;

opt seed values:
‘a’,’A’  alpha characters only (mixed case)
‘l’,’L’  lower case alpha characters only
‘p’,’P’  any printable characters
‘u’,’U’  upper case alpha characters only
‘x’,’X’  any alpha-numeric characters (upper)

CREATE TABLE random_strings AS
SELECT rownum RNUM,
dbms_random.string(‘A’, 12) RNDMSTR
FROM all_objects
WHERE rownum <= 200;

col rndmstr format a20

SELECT * FROM random_strings;

— create test data
CREATE TABLE test (
col1 VARCHAR2(20),
col2 VARCHAR2(20));

DECLARE
 x VARCHAR2(20);
 y VARCHAR2(20);
BEGIN
  FOR i IN 1..100
  LOOP
    x := dbms_random.string(‘A’, 20);
    y := dbms_random.string(‘A’, 20);

    INSERT INTO test
    (col1, col2)
    VALUES
    (x,y);
  END LOOP;
  COMMIT;
END;
/

SELECT * FROM test;

The following two tabs change content below.

Carlos Pampulim Caldeira

Professor Auxiliar | Assistant Professor at Universidade de Évora

Latest posts by Carlos Pampulim Caldeira (see all)