If you looking oracle spatial solution refer this link.
SELECT SDO_GEOM.SDO_DISTANCE(c_b.shape, m.diminfo, c_d.shape, m.diminfo)
FROM cola_markets c_b, cola_markets c_d, user_sdo_geom_metadata m
WHERE m.table_name = 'COLA_MARKETS' AND m.column_name = 'SHAPE'
AND c_b.name = 'cola_b' AND c_d.name = 'cola_d';
If you looking for spatial formula refer this or google it for 'distance formula'
you can have a look at this page where you can find some examples on how you can do this without the need for spatial