<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.mx.dla.dda.reporte.configuracion.daos.ConfiguracionReportesDAO">

	<insert id="insertarConfiguracionReporte">
		INSERT INTO DDA_T_REPORTE_CONFIG (CLAVE_REPORTE, ID_ESTUDIO, COLUMNA) 
		VALUES (#{claveReporte, javaType=String, jdbcType=VARCHAR}, #{idEstudio ,javaType=long, jdbcType=NUMERIC}, #{columna, javaType=String, jdbcType=VARCHAR})
	</insert>
	
	<delete id="eliminaConfiguracionReporte" >
		DELETE FROM DDA_T_REPORTE_CONFIG WHERE CLAVE_REPORTE=#{claveReporte} AND ID_ESTUDIO =#{idEstudio} 
	</delete>
	
	<select id="consultaConfiguracion" resultType="String">
		SELECT 
			DISTINCT LISTAGG(COLUMNA, ',') WITHIN GROUP (ORDER BY COLUMNA) over (partition by ID_ESTUDIO) COLUMNAS
		FROM 
			DDA_T_REPORTE_CONFIG 
		WHERE 
			CLAVE_REPORTE=#{claveReporte} 
		AND ID_ESTUDIO =#{idEstudio} 
	</select>
	
</mapper>
