trunkc trunkc - 5 months ago 9
SQL Question

How to insert same random value into two columns within one SQL Statement (Oracle)?

My example doesn't work:

INSERT INTO test_table
(column_1, column_2)
VALUES (DBMS_CRYPTO.RANDOMBYTES(16), column_1);


I'm not interested in PL/SQL solutions.

Answer

Use a subquery:

INSERT INTO test_table(column_1, column_2)
  SELECT val, val
  FROM (SELECT DBMS_CRYPTO.RANDOMBYTES(16) as val FROM dual) x;