Puede hacer esto creando un disparador para insertar en la tabla 1. Luego, seleccione todos los ID de dirección de la tabla 2 que aún no estén configurados en la tabla 1, ordénelos al azar y elija el primero. Un ejemplo práctico de tal disparador:
CREATE TRIGGER TRIGGER1
BEFORE INSERT ON TABLE1
FOR EACH ROW /* Trigger for each new row inserted into table1 */
BEGIN
SELECT addressId INTO :new.ADDRESSID /* Set AddressId for new row in table1 */ FROM
(
SELECT table2.addressId FROM table2
LEFT JOIN table1 ON table1.CompanyNumber = table2.company AND table1.AddressID = table2.addressId
WHERE table1.AddressID IS NULL /* Not already in table1 */ AND table2.Company = :new.COMPANYNUMBER /* Select all addressIds matching the company number */
ORDER BY dbms_random.value /* order them randomly */
) hits
WHERE ROWNUM = 1; /*Only pick the first randomly ordered one*/
EXCEPTION
WHEN no_data_found THEN /* CompanyNumber not in table2 or no unique AddressId left */
:new.ADDRESSID := NULL;
END;