create or replace PROCEDURE GETEMP5
(
m_patientUserId IN VARCHAR2,
EMP_CURSOR OUT SYS_REFCURSOR
) IS
BEGIN
OPEN EMP_CURSOR FOR
select * from patient where patientUserId LIKE '%'||m_patientUserId||'%';
END GETEMP5;
|| 가 concat과 같은 역할을 한다고 생각하면 된다. 주의할 점은 프로시저의 인자를 선언할 때. 반드시 "문자_변수명"으로 선언해줘야 된다는 거다. 아니면 프로시저에서 인자를 정상적으로 전달해줘도 인식을 못하더라. 3시간 소모했으니까 꼭 기억하자..
VARIABLE RC REFCURSOR;
EXEC GETEMP5('patient 100', :RC);
PRINT RC;
요런 식으로 sql developer에서 확인할 수 있다.
@NoArgsConstructor
@AllArgsConstructor
@Data
public class Patient {
private Integer pid;
private String patientUserId;
private String firstname;
private String lastname;
//private GenderType gender;
private Integer gender;
private Integer age;
private Double height;
private Double weight;
private String lastSession; //sessionId
private String comment;
}
@Mapper
public interface PatientMapper {
public List<Patient> findByContainPatientUserId(Map<String,Object> map); //프로시저 호출
}
<resultMap id="patientMap" type="com.patient.Patient">
</resultMap>
<select id="findByContainPatientUserId" statementType="CALLABLE">
{
CALL GETEMP5(
#{patientUserId, mode=IN, jdbcType=VARCHAR},
#{key, jdbcType=CURSOR, mode=OUT, javaType=java.sql.ResultSet, resultMap=patientMap}
)
}
</select>
인자를 Map으로 전달하면 key 값을 "key"로 해서 리턴한다.
HashMap<String,Object> map = new HashMap<String,Object>();
map.put("patientUserId", patientUserId);
oraclePatientMapper.findByContainPatientUserId(map);
log.info(map.toString());
List<Patient> bilabPatients = (List<Patient>)map.get("key");
log.info("확인... " + bilabPatients);