Sorry, never looked at Oracle Spatial before, but:
Suppose the user enters longitude and latitude as 95.224 and 31.601 respectively and you want to select from your a_spatial table all the rows within a 20 miles range.
Using equatorial and meridional circumference from Earth - Wikipedia, the free encyclopedia :
40,075.017 km = 24901.46109 mi; 40,007.86 km = 24859.73167 mi (using Kilometers to miles (km to mi) Metric conversion calculator)
you can start by calculating the degrees corresponding to 20 miles distance:
- longitude: 360 / 24901.46109 * 20 = 0,2891396602784644 lon_deg
- latitude: 360 / 24859.73167 * 20 = 0,2896250086515918 lat_deg
and look only for:
- longitudes: between 95.224 - lon_deg and 95.224 + lon_deg
- latitudes: between 31.601 - lat_deg and 31.601 + lat_deg
Please recheck the figures (or use those that suit you best)
There is a Spatial forum that should be the best place to ask for help ( https://forums.oracle.com/community/developer/english/oracle_database/spatial/content ), but aren't you trying to emulate the spatial operator SDO_WITHIN_DISTANCE, which should be able to use an appropriate index ?