C#中的Oracle数据库查询

时间:2018-06-04 07:11:17

标签: c# sql oracle plsql oracle11g

我被建议查询崩溃我的CustomerSatisfaction程序: 此查询应该获取信息,并确保它仅提取其部门中活动的员工,这意味着存在重复项,并确保它仅获取由allocation_end定义的最新部门中的那些信息。我使用Oracle DB并因为比较运算符而崩溃,例如第一个大于或等于。

原始查询

var sql = "SELECT " + 
                  "SPØRGSMÅL_ID, " +
                  "KARAKTER, " +
                  "COUNT(*) AS COUNT " +
              "FROM " + 
                  "KS_DRIFT.KT_KARAKTER kara " +
              "LEFT JOIN " + 
                  "KS_DRIFT.KT_BESVARELSE besv ON kara.BESVARELSE_ID = besv.EKSTERN_ID AND kara.TYPE = besv.TYPE " +
              "LEFT JOIN " +
                  "KS_DRIFT.V_AGENT_ALLOCATION age ON " + (queryParams.JoinOnFirstAgent ? "FØRSTE_AGENT" : "SIDSTE_AGENT") + " = age.AGENT_INITIALS AND TRUNC(TIDSPUNKT) BETWEEN ALLOCATION_START AND ALLOCATION_END " +
              "WHERE " + 
                  "TRUNC(TIDSPUNKT) BETWEEN " + OracleConversion.ToOracleDate(queryParams.Interval.Lower) + " AND " + OracleConversion.ToOracleDate(queryParams.Interval.Upper) + " AND " +
                  "SPØRGSMÅL_ID = " + queryParams.QuestionId +
                  (!queryParams.IncludeCDNs.IsNullOrEmpty() ? "AND CDN IN (" + queryParams.IncludeCDNs.ToDelimitedString(", ") + ") " : "") +
                  (!queryParams.ExcludeCDNs.IsNullOrEmpty() ? "AND CDN NOT IN (" + queryParams.ExcludeCDNs.ToDelimitedString(", ") + ") " : "") +
                  (!queryParams.AgentIds.IsNullOrEmpty() ? " AND AGENT_ID IN (" + queryParams.AgentIds.ToDelimitedString(", ") + ") " : "") +
                  (!queryParams.TeamIds.IsNullOrEmpty() ? " AND TEAM_ID IN (" + queryParams.TeamIds.ToDelimitedString(", ") + ") " : "") +
              "GROUP BY " +
                  "SPØRGSMÅL_ID, " +
                  "KARAKTER";

导致我的程序崩溃的建议查询:

var sql = "SELECT " +
              "SPØRGSMÅL_ID, " +
              "KARAKTER, " +
              "COUNT(*) AS COUNT " +
          "FROM " + 
              "KS_DRIFT.KT_KARAKTER kara " +
          "LEFT JOIN " + 
              "KS_DRIFT.KT_BESVARELSE besv ON kara.BESVARELSE_ID = besv.EKSTERN_ID AND kara.TYPE = besv.TYPE " +
          "LEFT JOIN " +
              "KS_DRIFT.V_AGENT_ALLOCATION age ON " + (queryParams.JoinOnFirstAgent ? "FØRSTE_AGENT" : "SIDSTE_AGENT") + " = age.AGENT_INITIALS AND TIDSPUNKT >= ALLOCATION_START AND TIDSPUNKT < ALLOCATION_END + 1  " +
              "and sysdate BETWEEN ALLOCATION_START AND ALLOCATION_END " +
          "WHERE " + 
              "TIDSPUNKT >= " + OracleConversion.ToOracleDate(queryParams.Interval.Lower) + " AND TIDSPUNKT < " + OracleConversion.ToOracleDate(queryParams.Interval.Upper) + " + 1 AND " +
              "SPØRGSMÅL_ID = " + queryParams.QuestionId +
              (!queryParams.IncludeCDNs.IsNullOrEmpty() ? "AND CDN IN (" + queryParams.IncludeCDNs.ToDelimitedString(", ") + ") " : "") +
              (!queryParams.ExcludeCDNs.IsNullOrEmpty() ? "AND CDN NOT IN (" + queryParams.ExcludeCDNs.ToDelimitedString(", ") + ") " : "") +
              (!queryParams.AgentIds.IsNullOrEmpty() ? " AND AGENT_ID IN (" + queryParams.AgentIds.ToDelimitedString(", ") + ") " : "") +
              (!queryParams.TeamIds.IsNullOrEmpty() ? " AND TEAM_ID IN (" + queryParams.TeamIds.ToDelimitedString(", ") + ") " : "") +
          "GROUP BY " +
              "SPØRGSMÅL_ID, " +
              "KARAKTER";

错误消息

  

ORA-00932:inkonsistente datatyper:forventede DATE,fik NUMBER ved Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode,OracleConnection conn,IntPtr opsErrCtx,OpoSqlValCtx * pOpoSqlValCtx,Object src,String procedure,Boolean bCheck)ved Oracle .DataAccess.Client.OracleException.HandleError(Int32 errCode,OracleConnection conn,String procedure,IntPtr opsErrCtx,OpoSqlValCtx * pOpoSqlValCtx,Object src,Boolean bCheck)ved Oracle.DataAccess.Client.OracleCommand.ExecuteReader(Boolean requery,Boolean fillRequest,CommandBehavior behavior )ved Oracle.DataAccess.Client.OracleCommand.ExecuteReader()

0 个答案:

没有答案