I am using MyBatis with Java 8. I am trying to inject mybatis parameters into SDO_NN constructor in oracle like;
SELECT
c.COLUMNNAME_ID as columnId,
TRIM(c.COLUMNNAME_NAME) as columnName,
c.COLUMNNAME_OWNER_ID as columnOwnerId ,
c.LATITUDE as latitude,
c.LONGITUDE as longitude,
TRIM(c.ADDRESS) as address,
TRIM(c.CITY) as city,
TRIM(c.DISTRICT) as district,
TRIM(c.PHONE_NUMBER) as phoneNumber,
TRUNC(SDO_NN_DISTANCE(1),3) distance
FROM TABLE_NAME c
WHERE c.COLUMNNAME_STATUS = 'ACT'
AND c.COLUMNAME_OWNER_ID = 'XXX'
AND SDO_NN(c.XY, sdo_geometry(2001, 8307, sdo_point_type(#{queryInput.longitude},#{queryInput.latitude},NULL), NULL, NULL),
'SDO_NUM_RES=5000 distance=#{queryInput.radius} unit=m', 1) = 'TRUE'
But it gives me the exception below.
org.springframework.jdbc.InvalidResultSetAccessException:
### Error querying database. Cause: java.sql.SQLException: Invalid column index
### The error may exist in com/xxxx/xxxxx/xxxx/mapper/CustomMapperOracle.xml
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: SELECT c.COLUMNNAME_ID as columnId, TRIM(c.COLUMNNAME_NAME) as columnName, c.COLUMNNAME_OWNER_ID as columnOwnerId, c.LATITUDE as latitude, c.LONGITUDE as longitude, c.MCC_NUM as mccNum, c.BRAND_NUM as brandNum, TRIM(c.ADDRESS) as address, TRIM(c.CITY) as city, TRIM(c.DISTRICT) as district, TRIM(c.PHONE_NUMBER) as phoneNumber, TRUNC(SDO_NN_DISTANCE(1),3) distance FROM TABLE_NAME c WHERE c.COLUMNNAME_STATUS = 'A' AND c.COLUMNAME_OWNER_ID = 'XXX' AND SDO_NN(c.XY, sdo_geometry(2001, 8307, sdo_point_type(?,?,NULL), NULL, NULL), 'SDO_NUM_RES=? distance=? unit=m', 1) = 'TRUE'
When I changed code to this one;
SELECT
c.COLUMNNAME_ID as columnId,
TRIM(c.COLUMNNAME_NAME) as columnName,
c.COLUMNNAME_OWNER_ID as columnOwnerId ,
c.LATITUDE as latitude,
c.LONGITUDE as longitude,
TRIM(c.ADDRESS) as address,
TRIM(c.CITY) as city,
TRIM(c.DISTRICT) as district,
TRIM(c.PHONE_NUMBER) as phoneNumber,
TRUNC(SDO_NN_DISTANCE(1),3) distance
FROM TABLE_NAME c
WHERE c.COLUMNNAME_STATUS = 'ACT'
AND c.COLUMNAME_OWNER_ID = 'XXX'
AND SDO_NN(c.XY, sdo_geometry(2001, 8307, sdo_point_type(#{queryInput.longitude},#{queryInput.latitude},NULL), NULL, NULL),
'SDO_NUM_RES=5000 distance=10000 unit=m', 1) = 'TRUE'
It works, I am trying to parameterized the distance.
The only change between first query and second query is
from
distance=#{queryInput.radius}
to
10000
Any help would be appreciated.
Thanks.