0

我正在尝试使用更大的 SQL 语句设置 MyBatis 接口,该语句多次使用相同的参数。我的代码是:

@Select({
"select cnfp_nr_years, cnfp_nr_credits, cnfp_credits_activities, cnfp_credits_studies, cnfp_credits_professional_evolution, cnfp_credits_programs_first_second, cnfp_credits_programs_third_fourth ",
"from ",
"(select cnfp_parameter_value as cnfp_nr_years ",
"from cnfp_parameters ", 
"where cnfp_parameter_name='PARAM_NR_YEARS' ",
"and CNFP_PARAMETER_START_DATE <= #{cnfpProcessingDate,jdbcType=DATE} ",
"and (cnfp_parameter_end_date is null or cnfp_parameter_end_date >= #{cnfpProcessingDate,jdbcType=DATE})) as param1, ",
"(select cnfp_parameter_value as cnfp_nr_credits ",
"from cnfp_parameters ",
"where cnfp_parameter_name='PARAM_NR_CREDITS' ",
"and CNFP_PARAMETER_START_DATE <= #{cnfpProcessingDate,jdbcType=DATE} ",
"and (cnfp_parameter_end_date is null or cnfp_parameter_end_date >= #{cnfpProcessingDate,jdbcType=DATE})) as param2, ",
"(select coalesce(sum(cnfp_teacher_activity_cpt_equiv),0) as cnfp_credits_activities ",
"from cnfp_teacher_activities ",
"where cnfp_person_id = #{cnfpPersonId,jdbcType=BIGINT} ",
"and cnfp_teacher_activity_date_equiv <= #{cnfpProcessingDate,jdbcType=DATE}' ",
"and cnfp_teacher_activity_date_expiry >= #{cnfpProcessingDate,jdbcType=DATE}) as activities, ",
"(select coalesce(sum(cnfp_teacher_study_cpt_equiv), 0) as cnfp_credits_studies ",
"from cnfp_teacher_studies ",
"where cnfp_person_id = #{cnfpPersonId,jdbcType=BIGINT} ",
"and cnfp_institution_id is not null ",
"and cnfp_teacher_study_date_equiv <= #{cnfpProcessingDate,jdbcType=DATE} ",
"and cnfp_teacher_study_date_expiry >= #{cnfpProcessingDate,jdbcType=DATE}) as studies, ",
"(select coalesce(sum(cnfp_teacher_study_cpt_equiv), 0) as cnfp_credits_professional_evolution ",
"from cnfp_teacher_studies ",
"where cnfp_person_id = #{cnfpPersonId,jdbcType=BIGINT} ",
"and cnfp_professional_level_id is not null ",
"and cnfp_teacher_study_date_equiv <= #{cnfpProcessingDate,jdbcType=DATE} ",
"and cnfp_teacher_study_date_expiry >= #{cnfpProcessingDate,jdbcType=DATE}) as professional_evolution, ",
"(select coalesce(sum(case when cnfp_program_categories_code in (1,2) then cnfp_program_module_cpt_equiv else 0 end), 0) as cnfp_credits_programs_first_second, ",
"coalesce(sum(case when cnfp_program_categories_code in (3,4) then cnfp_program_module_cpt_equiv else 0 end), 0) as cnfp_credits_programs_third_fourth ",
"from cnfp_teacher_learning_activities ",
"left join cnfp_teacher_learning_activities_x_program_modules on cnfp_teacher_learning_activities.cnfp_teacher_learning_activity_id = cnfp_teacher_learning_activities_x_program_modules.cnfp_teacher_learning_activity_id ",
"left join cnfp_program_modules on cnfp_teacher_learning_activities_x_program_modules.cnfp_program_module_id = cnfp_program_modules.cnfp_program_module_id ",
"left join cnfp_programs on cnfp_program_modules.cnfp_program_id = cnfp_programs.cnfp_program_id ",
"left join cnfp_program_categories on cnfp_programs.cnfp_program_categories_id = cnfp_program_categories.cnfp_program_categories_id ",
"where cnfp_person_id = #{cnfpPersonId,jdbcType=BIGINT} ",
"and CNFP_TEACHER_LEARNING_ACTIVITY_STATUS = 1 ",
"and CNFP_TEACHER_LEARNING_ACTIVITY_GRAD_DATE <= #{cnfpProcessingDate,jdbcType=DATE} ",
"and CNFP_TEACHER_LEARNING_ACTIVITY_EXPIRY_DATE >= #{cnfpProcessingDate,jdbcType=DATE}) as learning_activities"
})
@Results({
    @Result(column="cnfp_nr_years", property="cnfpParamVerifYears", jdbcType=JdbcType.BIGINT),
    @Result(column="cnfp_nr_credits", property="cnfpParamCreditsAcc", jdbcType=JdbcType.BIGINT),
    @Result(column="cnfp_credits_activities", property="cnfpCreditsActivities", jdbcType=JdbcType.BIGINT),
    @Result(column="cnfp_credits_studies", property="cnfpCreditsStudies", jdbcType=JdbcType.BIGINT),
    @Result(column="cnfp_credits_professional_evolution", property="cnfpCreditsProfessionalEvolution", jdbcType=JdbcType.BIGINT),
    @Result(column="cnfp_credits_programs_first_second", property="cnfpCreditsProgramsFirstSecondCat", jdbcType=JdbcType.BIGINT),
    @Result(column="cnfp_credits_programs_third_fourth", property="cnfpCreditsThirdFourthCat", jdbcType=JdbcType.BIGINT)
})
CptCalculator selectResults(@Param("cnfpPersonId")Long cnfpPersonId, @Param("cnfpProcessingDate")Date cnfpProcessingDate);

但我不断收到异常:

java.sql.SQLException: Parameter index out of range (7 > number of parameters, which is 6).] with root cause

java.sql.SQLException:参数索引超出范围(7 > 参数数量,即 6)。

我不知道为什么。任何帮助,将不胜感激

4

1 回答 1

0

在结果中,您期望 7 个元素,而您只得到 6 个。直接在 DB 客户端中测试您的查询以检查输出。

于 2012-09-07T14:50:06.693 回答